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
17 .hidden OPENSSL_cpuid_setup
19 call OPENSSL_cpuid_setup
21 .hidden OPENSSL_ia32cap_P
22 .comm OPENSSL_ia32cap_P,8
26 .globl OPENSSL_atomic_add
27 .type OPENSSL_atomic_add,\@abi-omnipotent
31 .Lspin: leaq ($arg2,%rax),%r8
36 .byte 0x48,0x98 # cltq/cdqe
38 .size OPENSSL_atomic_add,.-OPENSSL_atomic_add
41 .type OPENSSL_rdtsc,\@abi-omnipotent
48 .size OPENSSL_rdtsc,.-OPENSSL_rdtsc
50 .globl OPENSSL_ia32_cpuid
51 .type OPENSSL_ia32_cpuid,\@abi-omnipotent
54 mov %rbx,%r8 # save %rbx
58 mov %eax,%r11d # max value for standard query level
61 cmp \$0x756e6547,%ebx # "Genu"
64 cmp \$0x49656e69,%edx # "ineI"
67 cmp \$0x6c65746e,%ecx # "ntel"
69 or %eax,%r9d # 0 indicates Intel CPU
72 cmp \$0x68747541,%ebx # "Auth"
75 cmp \$0x69746E65,%edx # "enti"
78 cmp \$0x444D4163,%ecx # "cAMD"
80 or %eax,%r10d # 0 indicates AMD CPU
92 and \$0x00000801,%r9d # isolate AMD XOP bit, 1<<11
94 cmp \$0x80000008,%r10d
99 movzb %cl,%r10 # number of cores - 1
100 inc %r10 # number of cores
104 bt \$28,%edx # test hyper-threading bit
106 shr \$16,%ebx # number of logical processors
109 and \$0xefffffff,%edx # ~(1<<28)
118 mov \$0,%ecx # query L1D
122 and \$0xfff,%r10d # number of cores -1 per L1D
129 or \$0x00100000,%edx # use reserved 20th bit to engage RC4_CHAR
131 cmp \$15,%ah # examine Family ID
133 or \$0x40000000,%edx # use reserved bit to skip unrolled loop
135 bt \$28,%edx # test hyper-threading bit
137 and \$0xefffffff,%edx # ~(1<<28)
141 or \$0x10000000,%edx # 1<<28
143 cmp \$1,%bl # see if cache is shared
145 and \$0xefffffff,%edx # ~(1<<28)
147 and \$0x00000800,%r9d # isolate AMD XOP flag
148 and \$0xfffff7ff,%ecx
149 or %ecx,%r9d # merge AMD XOP flag
151 mov %edx,%r10d # %r9d:%r10d is copy of %ecx:%edx
152 bt \$27,%r9d # check OSXSAVE bit
155 .byte 0x0f,0x01,0xd0 # xgetbv
156 and \$6,%eax # isolate XMM and YMM state support
160 mov \$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
161 and %eax,%r9d # clear AVX, FMA and AMD XOP bits
165 mov %r8,%rbx # restore %rbx
168 .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
170 .globl OPENSSL_cleanse
171 .type OPENSSL_cleanse,\@abi-omnipotent
203 .size OPENSSL_cleanse,.-OPENSSL_cleanse
206 print<<___ if (!$win64);
207 .globl OPENSSL_wipe_cpu
208 .type OPENSSL_wipe_cpu,\@abi-omnipotent
237 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
239 print<<___ if ($win64);
240 .globl OPENSSL_wipe_cpu
241 .type OPENSSL_wipe_cpu,\@abi-omnipotent
258 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
266 my $redzone=win64?8:-8;
269 .globl OPENSSL_instrument_bus
270 .type OPENSSL_instrument_bus,\@abi-omnipotent
272 OPENSSL_instrument_bus:
273 mov $arg1,$out # tribute to Win64
277 rdtsc # collect 1st tick
278 mov %eax,$lasttick # lasttick = tick
279 mov \$0,$lastdiff # lastdiff = 0
299 .size OPENSSL_instrument_bus,.-OPENSSL_instrument_bus
301 .globl OPENSSL_instrument_bus2
302 .type OPENSSL_instrument_bus2,\@abi-omnipotent
304 OPENSSL_instrument_bus2:
305 mov $arg1,$out # tribute to Win64
308 mov $cnt,$redzone(%rsp)
310 rdtsc # collect 1st tick
311 mov %eax,$lasttick # lasttick = tick
312 mov \$0,$lastdiff # lastdiff = 0
318 rdtsc # collect 1st diff
320 sub $lasttick,%eax # diff
321 mov %edx,$lasttick # lasttick = tick
322 mov %eax,$lastdiff # lastdiff = diff
326 add %eax,($out) # accumulate diff
333 sub $lasttick,%eax # diff
334 mov %edx,$lasttick # lasttick = tick
336 mov %eax,$lastdiff # lastdiff = diff
339 sub %rdx,$cnt # conditional --$cnt
340 lea ($out,%rdx,4),$out # conditional ++$out
344 mov $redzone(%rsp),%rax
347 .size OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2
351 close STDOUT; # flush