4
$masm=1 if ($output =~ /\.asm/);
5
open STDOUT,">$output" || die "can't open $output: $!";
7
print<<___ if(defined($masm));
11
PUBLIC OPENSSL_atomic_add
13
OPENSSL_atomic_add PROC
14
mov eax,DWORD PTR[rcx]
15
\$Lspin: lea r8,DWORD PTR[rdx+rax]
16
lock cmpxchg DWORD PTR[rcx],r8d
21
OPENSSL_atomic_add ENDP
23
PUBLIC OPENSSL_wipe_cpu
38
lea rax,QWORD PTR[rsp+8]
44
EXTRN OPENSSL_cpuid_setup:PROC
45
DQ OPENSSL_cpuid_setup
49
print<<___ if(!defined($masm));
52
.globl OPENSSL_atomic_add
53
.type OPENSSL_atomic_add,\@function
57
.Lspin: leaq (%rsi,%rax),%r8
58
lock; cmpxchgl %r8d,(%rdi)
63
.size OPENSSL_atomic_add,.-OPENSSL_atomic_add
65
.globl OPENSSL_wipe_cpu
66
.type OPENSSL_wipe_cpu,\@function
95
.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
5
if ($flavour =~ /\./) { $output = $flavour; undef $flavour; }
7
$win64=0; $win64=1 if ($flavour =~ /[nm]asm|mingw64/ || $output =~ /\.asm$/);
9
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
10
open STDOUT,"| $^X ${dir}perlasm/x86_64-xlate.pl $flavour $output";
12
if ($win64) { $arg1="%rcx"; $arg2="%rdx"; }
13
else { $arg1="%rdi"; $arg2="%rsi"; }
15
.extern OPENSSL_cpuid_setup
99
18
call OPENSSL_cpuid_setup\@PLT
101
20
call OPENSSL_cpuid_setup
106
open STDOUT,"| $^X perlasm/x86_64-xlate.pl $output";
25
.globl OPENSSL_atomic_add
26
.type OPENSSL_atomic_add,\@abi-omnipotent
30
.Lspin: leaq ($arg2,%rax),%r8
35
.byte 0x48,0x98 # cltq/cdqe
37
.size OPENSSL_atomic_add,.-OPENSSL_atomic_add
110
39
.globl OPENSSL_rdtsc
111
40
.type OPENSSL_rdtsc,\@abi-omnipotent
135
66
cmp \$0x6c65746e,%ecx # "ntel"
68
or %eax,%r9d # 0 indicates Intel CPU
71
cmp \$0x68747541,%ebx # "Auth"
74
cmp \$0x69746E65,%edx # "enti"
77
cmp \$0x444D4163,%ecx # "cAMD"
79
or %eax,%r10d # 0 indicates AMD CPU
90
movzb %cl,%r10 # number of cores - 1
91
inc %r10 # number of cores
95
bt \$28,%edx # test hyper-threading bit
97
shr \$16,%ebx # number of logical processors
100
and \$0xefffffff,%edx # ~(1<<28)
109
mov \$0,%ecx # query L1D
113
and \$0xfff,%r10d # number of cores -1 per L1D
149
126
bt \$28,%edx # test hyper-threading bit
128
and \$0xefffffff,%edx # ~(1<<28)
132
or \$0x10000000,%edx # 1<<28
152
134
cmp \$1,%bl # see if cache is shared
161
143
.size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
145
.globl OPENSSL_cleanse
146
.type OPENSSL_cleanse,\@abi-omnipotent
178
.size OPENSSL_cleanse,.-OPENSSL_cleanse
181
print<<___ if (!$win64);
182
.globl OPENSSL_wipe_cpu
183
.type OPENSSL_wipe_cpu,\@abi-omnipotent
212
.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
214
print<<___ if ($win64);
215
.globl OPENSSL_wipe_cpu
216
.type OPENSSL_wipe_cpu,\@abi-omnipotent
233
.size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
163
236
close STDOUT; # flush