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 STDOUT
,"| \"$^X\" $xlate $flavour $output";
16 ($arg1,$arg2,$arg3,$arg4)=$win64?
("%rcx","%rdx","%r8", "%r9") : # Win64 order
17 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
20 .extern OPENSSL_cpuid_setup
21 .hidden OPENSSL_cpuid_setup
23 call OPENSSL_cpuid_setup
25 .hidden OPENSSL_ia32cap_P
26 .comm OPENSSL_ia32cap_P
,8,4
30 .globl OPENSSL_atomic_add
31 .type OPENSSL_atomic_add
,\
@abi-omnipotent
35 .Lspin
: leaq
($arg2,%rax),%r8
40 .byte
0x48,0x98 # cltq/cdqe
42 .size OPENSSL_atomic_add
,.-OPENSSL_atomic_add
45 .type OPENSSL_rdtsc
,\
@abi-omnipotent
52 .size OPENSSL_rdtsc
,.-OPENSSL_rdtsc
54 .globl OPENSSL_ia32_cpuid
55 .type OPENSSL_ia32_cpuid
,\
@abi-omnipotent
58 mov
%rbx,%r8 # save %rbx
62 mov
%eax,%r11d # max value for standard query level
65 cmp \
$0x756e6547,%ebx # "Genu"
68 cmp \
$0x49656e69,%edx # "ineI"
71 cmp \
$0x6c65746e,%ecx # "ntel"
73 or %eax,%r9d # 0 indicates Intel CPU
76 cmp \
$0x68747541,%ebx # "Auth"
79 cmp \
$0x69746E65,%edx # "enti"
82 cmp \
$0x444D4163,%ecx # "cAMD"
84 or %eax,%r10d # 0 indicates AMD CPU
96 and \
$0x00000801,%r9d # isolate AMD XOP bit, 1<<11
98 cmp \
$0x80000008,%r10d
101 mov \
$0x80000008,%eax
103 movzb
%cl,%r10 # number of cores - 1
104 inc
%r10 # number of cores
108 bt \
$28,%edx # test hyper-threading bit
110 shr \
$16,%ebx # number of logical processors
113 and \
$0xefffffff,%edx # ~(1<<28)
122 mov \
$0,%ecx # query L1D
126 and \
$0xfff,%r10d # number of cores -1 per L1D
131 and \
$0xbfefffff,%edx # force reserved bits to 0
134 or \
$0x40000000,%edx # set reserved bit#30 on Intel CPUs
136 cmp \
$15,%ah # examine Family ID
138 or \
$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
140 bt \
$28,%edx # test hyper-threading bit
142 and \
$0xefffffff,%edx # ~(1<<28)
146 or \
$0x10000000,%edx # 1<<28
148 cmp \
$1,%bl # see if cache is shared
150 and \
$0xefffffff,%edx # ~(1<<28)
152 and \
$0x00000800,%r9d # isolate AMD XOP flag
153 and \
$0xfffff7ff,%ecx
154 or %ecx,%r9d # merge AMD XOP flag
156 mov
%edx,%r10d # %r9d:%r10d is copy of %ecx:%edx
157 bt \
$27,%r9d # check OSXSAVE bit
160 .byte
0x0f,0x01,0xd0 # xgetbv
161 and \
$6,%eax # isolate XMM and YMM state support
165 mov \
$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
166 and %eax,%r9d # clear AVX, FMA and AMD XOP bits
170 mov
%r8,%rbx # restore %rbx
173 .size OPENSSL_ia32_cpuid
,.-OPENSSL_ia32_cpuid
175 .globl OPENSSL_cleanse
176 .type OPENSSL_cleanse
,\
@abi-omnipotent
208 .size OPENSSL_cleanse
,.-OPENSSL_cleanse
211 print<<___
if (!$win64);
212 .globl OPENSSL_wipe_cpu
213 .type OPENSSL_wipe_cpu
,\
@abi-omnipotent
242 .size OPENSSL_wipe_cpu
,.-OPENSSL_wipe_cpu
244 print<<___
if ($win64);
245 .globl OPENSSL_wipe_cpu
246 .type OPENSSL_wipe_cpu
,\
@abi-omnipotent
263 .size OPENSSL_wipe_cpu
,.-OPENSSL_wipe_cpu
271 my $redzone=win64?
8:-8;
274 .globl OPENSSL_instrument_bus
275 .type OPENSSL_instrument_bus
,\
@abi-omnipotent
277 OPENSSL_instrument_bus
:
278 mov
$arg1,$out # tribute to Win64
282 rdtsc
# collect 1st tick
283 mov
%eax,$lasttick # lasttick = tick
284 mov \
$0,$lastdiff # lastdiff = 0
304 .size OPENSSL_instrument_bus
,.-OPENSSL_instrument_bus
306 .globl OPENSSL_instrument_bus2
307 .type OPENSSL_instrument_bus2
,\
@abi-omnipotent
309 OPENSSL_instrument_bus2
:
310 mov
$arg1,$out # tribute to Win64
313 mov
$cnt,$redzone(%rsp)
315 rdtsc
# collect 1st tick
316 mov
%eax,$lasttick # lasttick = tick
317 mov \
$0,$lastdiff # lastdiff = 0
323 rdtsc
# collect 1st diff
325 sub $lasttick,%eax # diff
326 mov
%edx,$lasttick # lasttick = tick
327 mov
%eax,$lastdiff # lastdiff = diff
331 add
%eax,($out) # accumulate diff
338 sub $lasttick,%eax # diff
339 mov
%edx,$lasttick # lasttick = tick
341 mov
%eax,$lastdiff # lastdiff = diff
344 sub %rdx,$cnt # conditional --$cnt
345 lea
($out,%rdx,4),$out # conditional ++$out
349 mov
$redzone(%rsp),%rax
352 .size OPENSSL_instrument_bus2
,.-OPENSSL_instrument_bus2
357 .globl OPENSSL_ia32_rdrand
358 .type OPENSSL_ia32_rdrand
,\
@abi-omnipotent
370 .size OPENSSL_ia32_rdrand
,.-OPENSSL_ia32_rdrand
373 close STDOUT
; # flush