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
50 mov %rbx,%r8 # save %rbx
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
88 and \$0x00000801,%r9d # isolate AMD XOP bit, 1<<11
90 cmp \$0x80000008,%r10d
95 movzb %cl,%r10 # number of cores - 1
96 inc %r10 # number of cores
100 bt \$28,%edx # test hyper-threading bit
102 shr \$16,%ebx # number of logical processors
105 and \$0xefffffff,%edx # ~(1<<28)
114 mov \$0,%ecx # query L1D
118 and \$0xfff,%r10d # number of cores -1 per L1D
125 or \$0x00100000,%edx # use reserved 20th bit to engage RC4_CHAR
127 cmp \$15,%ah # examine Family ID
129 or \$0x40000000,%edx # use reserved bit to skip unrolled loop
131 bt \$28,%edx # test hyper-threading bit
133 and \$0xefffffff,%edx # ~(1<<28)
137 or \$0x10000000,%edx # 1<<28
139 cmp \$1,%bl # see if cache is shared
141 and \$0xefffffff,%edx # ~(1<<28)
143 and \$0x00000800,%r9d # isolate AMD XOP flag
144 and \$0xfffff7ff,%ecx
145 or %r9d,%ecx # merge AMD XOP flag
149 or %rcx,%rbx # compose capability vector in %rbx
150 bt \$27+32,%rcx # check OSXSAVE bit
153 .byte 0x0f,0x01,0xd0 # xgetbv
154 and \$6,%eax # isolate XMM and YMM state support
158 mov \$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
160 and %rax,%rbx # clear AVX, FMA and AMD XOP bits
163 mov %r8,%rbx # restore %rbx
165 .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
167 .globl OPENSSL_cleanse
168 .type OPENSSL_cleanse,\@abi-omnipotent
200 .size OPENSSL_cleanse,.-OPENSSL_cleanse
203 print<<___ if (!$win64);
204 .globl OPENSSL_wipe_cpu
205 .type OPENSSL_wipe_cpu,\@abi-omnipotent
234 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
236 print<<___ if ($win64);
237 .globl OPENSSL_wipe_cpu
238 .type OPENSSL_wipe_cpu,\@abi-omnipotent
255 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
263 my $redzone=win64?8:-8;
266 .globl OPENSSL_instrument_bus
267 .type OPENSSL_instrument_bus,\@abi-omnipotent
269 OPENSSL_instrument_bus:
270 mov $arg1,$out # tribute to Win64
274 rdtsc # collect 1st tick
275 mov %eax,$lasttick # lasttick = tick
276 mov \$0,$lastdiff # lastdiff = 0
296 .size OPENSSL_instrument_bus,.-OPENSSL_instrument_bus
298 .globl OPENSSL_instrument_bus2
299 .type OPENSSL_instrument_bus2,\@abi-omnipotent
301 OPENSSL_instrument_bus2:
302 mov $arg1,$out # tribute to Win64
305 mov $cnt,$redzone(%rsp)
307 rdtsc # collect 1st tick
308 mov %eax,$lasttick # lasttick = tick
309 mov \$0,$lastdiff # lastdiff = 0
315 rdtsc # collect 1st diff
317 sub $lasttick,%eax # diff
318 mov %edx,$lasttick # lasttick = tick
319 mov %eax,$lastdiff # lastdiff = diff
323 add %eax,($out) # accumulate diff
330 sub $lasttick,%eax # diff
331 mov %edx,$lasttick # lasttick = tick
333 mov %eax,$lastdiff # lastdiff = diff
336 sub %rdx,$cnt # conditional --$cnt
337 lea ($out,%rdx,4),$out # conditional ++$out
341 mov $redzone(%rsp),%rax
344 .size OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2
348 close STDOUT; # flush