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 ($arg1,$arg2,$arg3,$arg4)=$win64?("%rcx","%rdx","%r8", "%r9") : # Win64 order
13 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
16 .extern OPENSSL_cpuid_setup
18 call OPENSSL_cpuid_setup
22 .globl OPENSSL_atomic_add
23 .type OPENSSL_atomic_add,\@abi-omnipotent
27 .Lspin: leaq ($arg2,%rax),%r8
32 .byte 0x48,0x98 # cltq/cdqe
34 .size OPENSSL_atomic_add,.-OPENSSL_atomic_add
37 .type OPENSSL_rdtsc,\@abi-omnipotent
44 .size OPENSSL_rdtsc,.-OPENSSL_rdtsc
46 .globl OPENSSL_ia32_cpuid
47 .type OPENSSL_ia32_cpuid,\@abi-omnipotent
54 mov %eax,%r11d # max value for standard query level
57 cmp \$0x756e6547,%ebx # "Genu"
60 cmp \$0x49656e69,%edx # "ineI"
63 cmp \$0x6c65746e,%ecx # "ntel"
65 or %eax,%r9d # 0 indicates Intel CPU
68 cmp \$0x68747541,%ebx # "Auth"
71 cmp \$0x69746E65,%edx # "enti"
74 cmp \$0x444D4163,%ecx # "cAMD"
76 or %eax,%r10d # 0 indicates AMD CPU
87 movzb %cl,%r10 # number of cores - 1
88 inc %r10 # number of cores
92 bt \$28,%edx # test hyper-threading bit
94 shr \$16,%ebx # number of logical processors
97 and \$0xefffffff,%edx # ~(1<<28)
106 mov \$0,%ecx # query L1D
110 and \$0xfff,%r10d # number of cores -1 per L1D
117 or \$0x00100000,%edx # use reserved 20th bit to engage RC4_CHAR
119 cmp \$15,%ah # examine Family ID
121 or \$0x40000000,%edx # use reserved bit to skip unrolled loop
123 bt \$28,%edx # test hyper-threading bit
125 and \$0xefffffff,%edx # ~(1<<28)
129 or \$0x10000000,%edx # 1<<28
131 cmp \$1,%bl # see if cache is shared
133 and \$0xefffffff,%edx # ~(1<<28)
140 .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
142 .globl OPENSSL_cleanse
143 .type OPENSSL_cleanse,\@abi-omnipotent
175 .size OPENSSL_cleanse,.-OPENSSL_cleanse
178 print<<___ if (!$win64);
179 .globl OPENSSL_wipe_cpu
180 .type OPENSSL_wipe_cpu,\@abi-omnipotent
209 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
211 print<<___ if ($win64);
212 .globl OPENSSL_wipe_cpu
213 .type OPENSSL_wipe_cpu,\@abi-omnipotent
230 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
238 my $redzone=win64?8:-8;
241 .globl OPENSSL_instrument_bus
242 .type OPENSSL_instrument_bus,\@abi-omnipotent
244 OPENSSL_instrument_bus:
245 mov $arg1,$out # tribute to Win64
249 rdtsc # collect 1st tick
250 mov %eax,$lasttick # lasttick = tick
251 mov \$0,$lastdiff # lastdiff = 0
271 .size OPENSSL_instrument_bus,.-OPENSSL_instrument_bus
273 .globl OPENSSL_instrument_bus2
274 .type OPENSSL_instrument_bus2,\@abi-omnipotent
276 OPENSSL_instrument_bus2:
277 mov $arg1,$out # tribute to Win64
280 mov $cnt,$redzone(%rsp)
282 rdtsc # collect 1st tick
283 mov %eax,$lasttick # lasttick = tick
284 mov \$0,$lastdiff # lastdiff = 0
290 rdtsc # collect 1st diff
292 sub $lasttick,%eax # diff
293 mov %edx,$lasttick # lasttick = tick
294 mov %eax,$lastdiff # lastdiff = diff
298 add %eax,($out) # accumulate diff
305 sub $lasttick,%eax # diff
306 mov %edx,$lasttick # lasttick = tick
308 mov %eax,$lastdiff # lastdiff = diff
311 sub %rdx,$cnt # conditional --$cnt
312 lea ($out,%rdx,4),$out # conditional ++$out
316 mov $redzone(%rsp),%rax
319 .size OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2
323 close STDOUT; # flush