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
127 and \$0xbfefffff,%edx # force reserved bits to 0
130 or \$0x40000000,%edx # set reserved bit#30 on Intel CPUs
132 cmp \$15,%ah # examine Family ID
134 or \$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
136 bt \$28,%edx # test hyper-threading bit
138 and \$0xefffffff,%edx # ~(1<<28)
142 or \$0x10000000,%edx # 1<<28
144 cmp \$1,%bl # see if cache is shared
146 and \$0xefffffff,%edx # ~(1<<28)
148 and \$0x00000800,%r9d # isolate AMD XOP flag
149 and \$0xfffff7ff,%ecx
150 or %ecx,%r9d # merge AMD XOP flag
152 mov %edx,%r10d # %r9d:%r10d is copy of %ecx:%edx
153 bt \$27,%r9d # check OSXSAVE bit
156 .byte 0x0f,0x01,0xd0 # xgetbv
157 and \$6,%eax # isolate XMM and YMM state support
161 mov \$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
162 and %eax,%r9d # clear AVX, FMA and AMD XOP bits
166 mov %r8,%rbx # restore %rbx
169 .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
171 .globl OPENSSL_cleanse
172 .type OPENSSL_cleanse,\@abi-omnipotent
204 .size OPENSSL_cleanse,.-OPENSSL_cleanse
207 print<<___ if (!$win64);
208 .globl OPENSSL_wipe_cpu
209 .type OPENSSL_wipe_cpu,\@abi-omnipotent
238 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
240 print<<___ if ($win64);
241 .globl OPENSSL_wipe_cpu
242 .type OPENSSL_wipe_cpu,\@abi-omnipotent
259 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
267 my $redzone=win64?8:-8;
270 .globl OPENSSL_instrument_bus
271 .type OPENSSL_instrument_bus,\@abi-omnipotent
273 OPENSSL_instrument_bus:
274 mov $arg1,$out # tribute to Win64
278 rdtsc # collect 1st tick
279 mov %eax,$lasttick # lasttick = tick
280 mov \$0,$lastdiff # lastdiff = 0
300 .size OPENSSL_instrument_bus,.-OPENSSL_instrument_bus
302 .globl OPENSSL_instrument_bus2
303 .type OPENSSL_instrument_bus2,\@abi-omnipotent
305 OPENSSL_instrument_bus2:
306 mov $arg1,$out # tribute to Win64
309 mov $cnt,$redzone(%rsp)
311 rdtsc # collect 1st tick
312 mov %eax,$lasttick # lasttick = tick
313 mov \$0,$lastdiff # lastdiff = 0
319 rdtsc # collect 1st diff
321 sub $lasttick,%eax # diff
322 mov %edx,$lasttick # lasttick = tick
323 mov %eax,$lastdiff # lastdiff = diff
327 add %eax,($out) # accumulate diff
334 sub $lasttick,%eax # diff
335 mov %edx,$lasttick # lasttick = tick
337 mov %eax,$lastdiff # lastdiff = diff
340 sub %rdx,$cnt # conditional --$cnt
341 lea ($out,%rdx,4),$out # conditional ++$out
345 mov $redzone(%rsp),%rax
348 .size OPENSSL_instrument_bus2,.-OPENSSL_instrument_bus2
352 close STDOUT; # flush