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 STDOUT,"| $^X $xlate $flavour $output";
16 ($arg1,$arg2,$arg3,$arg4)=$win64?("%rcx","%rdx","%r8", "%r9") : # Win64 order
17 ("%rdi","%rsi","%rdx","%rcx"); # Unix order
20 .extern OPENSSL_cpuid_setup
21 .hidden OPENSSL_cpuid_setup
23 call OPENSSL_cpuid_setup
25 .hidden OPENSSL_ia32cap_P
26 .comm OPENSSL_ia32cap_P,8
30 .globl OPENSSL_atomic_add
31 .type OPENSSL_atomic_add,\@abi-omnipotent
35 .Lspin: leaq ($arg2,%rax),%r8
40 .byte 0x48,0x98 # cltq/cdqe
42 .size OPENSSL_atomic_add,.-OPENSSL_atomic_add
45 .type OPENSSL_rdtsc,\@abi-omnipotent
52 .size OPENSSL_rdtsc,.-OPENSSL_rdtsc
54 .globl OPENSSL_ia32_cpuid
55 .type OPENSSL_ia32_cpuid,\@abi-omnipotent
58 mov %rbx,%r8 # save %rbx
62 mov %eax,%r11d # max value for standard query level
65 cmp \$0x756e6547,%ebx # "Genu"
68 cmp \$0x49656e69,%edx # "ineI"
71 cmp \$0x6c65746e,%ecx # "ntel"
73 or %eax,%r9d # 0 indicates Intel CPU
76 cmp \$0x68747541,%ebx # "Auth"
79 cmp \$0x69746E65,%edx # "enti"
82 cmp \$0x444D4163,%ecx # "cAMD"
84 or %eax,%r10d # 0 indicates AMD CPU
96 and \$0x00000801,%r9d # isolate AMD XOP bit, 1<<11
98 cmp \$0x80000008,%r10d
101 mov \$0x80000008,%eax
103 movzb %cl,%r10 # number of cores - 1
104 inc %r10 # number of cores
108 bt \$28,%edx # test hyper-threading bit
110 shr \$16,%ebx # number of logical processors
113 and \$0xefffffff,%edx # ~(1<<28)
122 mov \$0,%ecx # query L1D
126 and \$0xfff,%r10d # number of cores -1 per L1D
131 and \$0xbfefffff,%edx # force reserved bits to 0
134 or \$0x40000000,%edx # set reserved bit#30 on Intel CPUs
136 cmp \$15,%ah # examine Family ID
138 or \$0x00100000,%edx # set reserved bit#20 to engage RC4_CHAR
140 bt \$28,%edx # test hyper-threading bit
142 and \$0xefffffff,%edx # ~(1<<28)
146 or \$0x10000000,%edx # 1<<28
148 cmp \$1,%bl # see if cache is shared
150 and \$0xefffffff,%edx # ~(1<<28)
152 and \$0x00000800,%r9d # isolate AMD XOP flag
153 and \$0xfffff7ff,%ecx
154 or %ecx,%r9d # merge AMD XOP flag
156 mov %edx,%r10d # %r9d:%r10d is copy of %ecx:%edx
157 bt \$27,%r9d # check OSXSAVE bit
160 .byte 0x0f,0x01,0xd0 # xgetbv
161 and \$6,%eax # isolate XMM and YMM state support
165 mov \$0xefffe7ff,%eax # ~(1<<28|1<<12|1<<11)
166 and %eax,%r9d # clear AVX, FMA and AMD XOP bits
170 mov %r8,%rbx # restore %rbx
173 .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
175 .globl OPENSSL_cleanse
176 .type OPENSSL_cleanse,\@abi-omnipotent
208 .size OPENSSL_cleanse,.-OPENSSL_cleanse
211 print<<___ if (!$win64);
212 .globl OPENSSL_wipe_cpu
213 .type OPENSSL_wipe_cpu,\@abi-omnipotent
242 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
244 print<<___ if ($win64);
245 .globl OPENSSL_wipe_cpu
246 .type OPENSSL_wipe_cpu,\@abi-omnipotent
263 .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
267 .globl OPENSSL_ia32_rdrand
268 .type OPENSSL_ia32_rdrand,\@abi-omnipotent
280 .size OPENSSL_ia32_rdrand,.-OPENSSL_ia32_rdrand
283 close STDOUT; # flush