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 OUT,"| \"$^X\" $xlate $flavour $output";
17 ($arg1,$arg2,$arg3,$arg4)=$win64?("%rcx","%rdx","%r8", "%r9") : # Win64 order
18 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
21 .extern OPENSSL_cpuid_setup
22 .hidden OPENSSL_cpuid_setup
24 call OPENSSL_cpuid_setup
26 .hidden OPENSSL_ia32cap_P
27 .comm OPENSSL_ia32cap_P,16,4
31 .globl OPENSSL_atomic_add
32 .type OPENSSL_atomic_add,\@abi-omnipotent
36 .Lspin: leaq ($arg2,%rax),%r8
41 .byte 0x48,0x98 # cltq/cdqe
43 .size OPENSSL_atomic_add,.-OPENSSL_atomic_add
46 .type OPENSSL_rdtsc,\@abi-omnipotent
53 .size OPENSSL_rdtsc,.-OPENSSL_rdtsc
55 .globl OPENSSL_ia32_cpuid
56 .type OPENSSL_ia32_cpuid,\@function,1
59 mov %rbx,%r8 # save %rbx
62 mov %eax,8(%rdi) # clear extended feature flags
64 mov %eax,%r11d # max value for standard query level
67 cmp \$0x756e6547,%ebx # "Genu"
70 cmp \$0x49656e69,%edx # "ineI"
73 cmp \$0x6c65746e,%ecx # "ntel"
75 or %eax,%r9d # 0 indicates Intel CPU
78 cmp \$0x68747541,%ebx # "Auth"
81 cmp \$0x69746E65,%edx # "enti"
84 cmp \$0x444D4163,%ecx # "cAMD"
86 or %eax,%r10d # 0 indicates AMD CPU
98 and \$0x00000801,%r9d # isolate AMD XOP bit, 1<<11
100 cmp \$0x80000008,%r10d
103 mov \$0x80000008,%eax
105 movzb %cl,%r10 # number of cores - 1
106 inc %r10 # number of cores
110 bt \$28,%edx # test hyper-threading bit
112 shr \$16,%ebx # number of logical processors
115 and \$0xefffffff,%edx # ~(1<<28)
124 mov \$0,%ecx # query L1D
128 and \$0xfff,%r10d # number of cores -1 per L1D
133 and \$0xbfefffff,%edx # force reserved bits to 0
136 or \$0x40000000,%edx # set reserved bit#30 on Intel CPUs
138 cmp \$15,%ah # examine Family ID
140 or \$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
142 bt \$28,%edx # test hyper-threading bit
144 and \$0xefffffff,%edx # ~(1<<28)
148 or \$0x10000000,%edx # 1<<28
150 cmp \$1,%bl # see if cache is shared
152 and \$0xefffffff,%edx # ~(1<<28)
154 and \$0x00000800,%r9d # isolate AMD XOP flag
155 and \$0xfffff7ff,%ecx
156 or %ecx,%r9d # merge AMD XOP flag
158 mov %edx,%r10d # %r9d:%r10d is copy of %ecx:%edx
161 jb .Lno_extended_info
165 mov %ebx,8(%rdi) # save extended feature flags
168 bt \$27,%r9d # check OSXSAVE bit
171 .byte 0x0f,0x01,0xd0 # xgetbv
172 and \$6,%eax # isolate XMM and YMM state support
176 mov \$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
177 and %eax,%r9d # clear AVX, FMA and AMD XOP bits
178 andl \$0xffffffdf,8(%rdi) # cleax AVX2, ~(1<<5)
182 mov %r8,%rbx # restore %rbx
185 .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
187 .globl OPENSSL_cleanse
188 .type OPENSSL_cleanse,\@abi-omnipotent
220 .size OPENSSL_cleanse,.-OPENSSL_cleanse
223 print<<___ if (!$win64);
224 .globl OPENSSL_wipe_cpu
225 .type OPENSSL_wipe_cpu,\@abi-omnipotent
254 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
256 print<<___ if ($win64);
257 .globl OPENSSL_wipe_cpu
258 .type OPENSSL_wipe_cpu,\@abi-omnipotent
275 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
279 .globl OPENSSL_ia32_rdrand
280 .type OPENSSL_ia32_rdrand,\@abi-omnipotent
292 .size OPENSSL_ia32_rdrand,.-OPENSSL_ia32_rdrand
294 .globl OPENSSL_ia32_rdseed
295 .type OPENSSL_ia32_rdseed,\@abi-omnipotent
307 .size OPENSSL_ia32_rdseed,.-OPENSSL_ia32_rdseed
310 close STDOUT; # flush