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 ( $xlate="${dir}x86_64-xlate.pl" and -f
$xlate ) or
11 ( $xlate="${dir}perlasm/x86_64-xlate.pl" and -f
$xlate) or
12 die "can't locate x86_64-xlate.pl";
14 open OUT
,"| \"$^X\" $xlate $flavour $output";
17 ($arg1,$arg2,$arg3,$arg4)=$win64?
("%rcx","%rdx","%r8", "%r9") : # Win64 order
18 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
21 .extern OPENSSL_cpuid_setup
22 .hidden OPENSSL_cpuid_setup
24 call OPENSSL_cpuid_setup
26 .hidden OPENSSL_ia32cap_P
27 .comm OPENSSL_ia32cap_P
,16,4
31 .globl OPENSSL_atomic_add
32 .type OPENSSL_atomic_add
,\
@abi-omnipotent
36 .Lspin
: leaq
($arg2,%rax),%r8
41 .byte
0x48,0x98 # cltq/cdqe
43 .size OPENSSL_atomic_add
,.-OPENSSL_atomic_add
46 .type OPENSSL_rdtsc
,\
@abi-omnipotent
53 .size OPENSSL_rdtsc
,.-OPENSSL_rdtsc
55 .globl OPENSSL_ia32_cpuid
56 .type OPENSSL_ia32_cpuid
,\
@function,1
59 mov
%rbx,%r8 # save %rbx
62 mov
%eax,8(%rdi) # clear 3rd word
64 mov
%eax,%r11d # max value for standard query level
67 cmp \
$0x756e6547,%ebx # "Genu"
70 cmp \
$0x49656e69,%edx # "ineI"
73 cmp \
$0x6c65746e,%ecx # "ntel"
75 or %eax,%r9d # 0 indicates Intel CPU
78 cmp \
$0x68747541,%ebx # "Auth"
81 cmp \
$0x69746E65,%edx # "enti"
84 cmp \
$0x444D4163,%ecx # "cAMD"
86 or %eax,%r10d # 0 indicates AMD CPU
98 and \
$0x00000801,%r9d # isolate AMD XOP bit, 1<<11
100 cmp \
$0x80000008,%r10d
103 mov \
$0x80000008,%eax
105 movzb
%cl,%r10 # number of cores - 1
106 inc
%r10 # number of cores
110 bt \
$28,%edx # test hyper-threading bit
112 shr \
$16,%ebx # number of logical processors
115 and \
$0xefffffff,%edx # ~(1<<28)
124 mov \
$0,%ecx # query L1D
128 and \
$0xfff,%r10d # number of cores -1 per L1D
141 and \
$0xbfefffff,%edx # force reserved bits to 0
144 or \
$0x40000000,%edx # set reserved bit#30 on Intel CPUs
146 cmp \
$15,%ah # examine Family ID
148 or \
$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
150 bt \
$28,%edx # test hyper-threading bit
152 and \
$0xefffffff,%edx # ~(1<<28)
156 or \
$0x10000000,%edx # 1<<28
158 cmp \
$1,%bl # see if cache is shared
160 and \
$0xefffffff,%edx # ~(1<<28)
162 and \
$0x00000800,%r9d # isolate AMD XOP flag
163 and \
$0xfffff7ff,%ecx
164 or %ecx,%r9d # merge AMD XOP flag
166 mov
%edx,%r10d # %r9d:%r10d is copy of %ecx:%edx
167 bt \
$27,%r9d # check OSXSAVE bit
170 .byte
0x0f,0x01,0xd0 # xgetbv
171 and \
$6,%eax # isolate XMM and YMM state support
175 mov \
$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
176 and %eax,%r9d # clear AVX, FMA and AMD XOP bits
177 andl \
$0xffffffdf,8(%rdi) # cleax AVX2, ~(1<<5)
181 mov
%r8,%rbx # restore %rbx
184 .size OPENSSL_ia32_cpuid
,.-OPENSSL_ia32_cpuid
186 .globl OPENSSL_cleanse
187 .type OPENSSL_cleanse
,\
@abi-omnipotent
219 .size OPENSSL_cleanse
,.-OPENSSL_cleanse
222 print<<___
if (!$win64);
223 .globl OPENSSL_wipe_cpu
224 .type OPENSSL_wipe_cpu
,\
@abi-omnipotent
253 .size OPENSSL_wipe_cpu
,.-OPENSSL_wipe_cpu
255 print<<___
if ($win64);
256 .globl OPENSSL_wipe_cpu
257 .type OPENSSL_wipe_cpu
,\
@abi-omnipotent
274 .size OPENSSL_wipe_cpu
,.-OPENSSL_wipe_cpu
282 my $redzone=win64?
8:-8;
285 .globl OPENSSL_instrument_bus
286 .type OPENSSL_instrument_bus
,\
@abi-omnipotent
288 OPENSSL_instrument_bus
:
289 mov
$arg1,$out # tribute to Win64
293 rdtsc
# collect 1st tick
294 mov
%eax,$lasttick # lasttick = tick
295 mov \
$0,$lastdiff # lastdiff = 0
315 .size OPENSSL_instrument_bus
,.-OPENSSL_instrument_bus
317 .globl OPENSSL_instrument_bus2
318 .type OPENSSL_instrument_bus2
,\
@abi-omnipotent
320 OPENSSL_instrument_bus2
:
321 mov
$arg1,$out # tribute to Win64
324 mov
$cnt,$redzone(%rsp)
326 rdtsc
# collect 1st tick
327 mov
%eax,$lasttick # lasttick = tick
328 mov \
$0,$lastdiff # lastdiff = 0
334 rdtsc
# collect 1st diff
336 sub $lasttick,%eax # diff
337 mov
%edx,$lasttick # lasttick = tick
338 mov
%eax,$lastdiff # lastdiff = diff
342 add
%eax,($out) # accumulate diff
349 sub $lasttick,%eax # diff
350 mov
%edx,$lasttick # lasttick = tick
352 mov
%eax,$lastdiff # lastdiff = diff
355 sub %rdx,$cnt # conditional --$cnt
356 lea
($out,%rdx,4),$out # conditional ++$out
360 mov
$redzone(%rsp),%rax
363 .size OPENSSL_instrument_bus2
,.-OPENSSL_instrument_bus2
368 .globl OPENSSL_ia32_rdrand
369 .type OPENSSL_ia32_rdrand
,\
@abi-omnipotent
381 .size OPENSSL_ia32_rdrand
,.-OPENSSL_ia32_rdrand
383 .globl OPENSSL_ia32_rdseed
384 .type OPENSSL_ia32_rdseed
,\
@abi-omnipotent
396 .size OPENSSL_ia32_rdseed
,.-OPENSSL_ia32_rdseed
399 close STDOUT
; # flush