diff options
author | miod <> | 2016-11-04 17:30:30 +0000 |
---|---|---|
committer | miod <> | 2016-11-04 17:30:30 +0000 |
commit | 723502d9588ba0e1cc08af1b12654917da74d440 (patch) | |
tree | 77b413175d422148cfb0ef7b2062340230aa5413 /src/lib/libcrypto/bn | |
parent | 391f8ce21bb7929810460a73e2fde2c80540848d (diff) | |
download | openbsd-723502d9588ba0e1cc08af1b12654917da74d440.tar.gz openbsd-723502d9588ba0e1cc08af1b12654917da74d440.tar.bz2 openbsd-723502d9588ba0e1cc08af1b12654917da74d440.zip |
Replace all uses of magic numbers when operating on OPENSSL_ia32_P[] by
meaningful constants in a private header file, so that reviewers can actually
get a chance to figure out what the code is attempting to do without knowing
all cpuid bits.
While there, turn it from an array of two 32-bit ints into a properly aligned
64-bit int.
Use of OPENSSL_ia32_P is now restricted to the assembler parts. C code will
now always use OPENSSL_cpu_caps() and check for the proper bits in the
whole 64-bit word it returns.
i386 tests and ok jsing@
Diffstat (limited to 'src/lib/libcrypto/bn')
-rw-r--r-- | src/lib/libcrypto/bn/asm/bn-586.pl | 12 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/asm/x86-gf2m.pl | 6 | ||||
-rwxr-xr-x | src/lib/libcrypto/bn/asm/x86-mont.pl | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/asm/x86_64-gf2m.pl | 5 |
4 files changed, 13 insertions, 12 deletions
diff --git a/src/lib/libcrypto/bn/asm/bn-586.pl b/src/lib/libcrypto/bn/asm/bn-586.pl index 332ef3e91d..c4e2baa6c5 100644 --- a/src/lib/libcrypto/bn/asm/bn-586.pl +++ b/src/lib/libcrypto/bn/asm/bn-586.pl | |||
@@ -25,7 +25,7 @@ sub bn_mul_add_words | |||
25 | { | 25 | { |
26 | local($name)=@_; | 26 | local($name)=@_; |
27 | 27 | ||
28 | &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); | 28 | &function_begin_B($name,""); |
29 | 29 | ||
30 | $r="eax"; | 30 | $r="eax"; |
31 | $a="edx"; | 31 | $a="edx"; |
@@ -33,7 +33,7 @@ sub bn_mul_add_words | |||
33 | 33 | ||
34 | if ($sse2) { | 34 | if ($sse2) { |
35 | &picmeup("eax","OPENSSL_ia32cap_P"); | 35 | &picmeup("eax","OPENSSL_ia32cap_P"); |
36 | &bt(&DWP(0,"eax"),26); | 36 | &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); |
37 | &jnc(&label("maw_non_sse2")); | 37 | &jnc(&label("maw_non_sse2")); |
38 | 38 | ||
39 | &mov($r,&wparam(0)); | 39 | &mov($r,&wparam(0)); |
@@ -211,7 +211,7 @@ sub bn_mul_words | |||
211 | { | 211 | { |
212 | local($name)=@_; | 212 | local($name)=@_; |
213 | 213 | ||
214 | &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); | 214 | &function_begin_B($name,""); |
215 | 215 | ||
216 | $r="eax"; | 216 | $r="eax"; |
217 | $a="edx"; | 217 | $a="edx"; |
@@ -219,7 +219,7 @@ sub bn_mul_words | |||
219 | 219 | ||
220 | if ($sse2) { | 220 | if ($sse2) { |
221 | &picmeup("eax","OPENSSL_ia32cap_P"); | 221 | &picmeup("eax","OPENSSL_ia32cap_P"); |
222 | &bt(&DWP(0,"eax"),26); | 222 | &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); |
223 | &jnc(&label("mw_non_sse2")); | 223 | &jnc(&label("mw_non_sse2")); |
224 | 224 | ||
225 | &mov($r,&wparam(0)); | 225 | &mov($r,&wparam(0)); |
@@ -322,7 +322,7 @@ sub bn_sqr_words | |||
322 | { | 322 | { |
323 | local($name)=@_; | 323 | local($name)=@_; |
324 | 324 | ||
325 | &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); | 325 | &function_begin_B($name,""); |
326 | 326 | ||
327 | $r="eax"; | 327 | $r="eax"; |
328 | $a="edx"; | 328 | $a="edx"; |
@@ -330,7 +330,7 @@ sub bn_sqr_words | |||
330 | 330 | ||
331 | if ($sse2) { | 331 | if ($sse2) { |
332 | &picmeup("eax","OPENSSL_ia32cap_P"); | 332 | &picmeup("eax","OPENSSL_ia32cap_P"); |
333 | &bt(&DWP(0,"eax"),26); | 333 | &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); |
334 | &jnc(&label("sqr_non_sse2")); | 334 | &jnc(&label("sqr_non_sse2")); |
335 | 335 | ||
336 | &mov($r,&wparam(0)); | 336 | &mov($r,&wparam(0)); |
diff --git a/src/lib/libcrypto/bn/asm/x86-gf2m.pl b/src/lib/libcrypto/bn/asm/x86-gf2m.pl index 808a1e5969..97d9136260 100644 --- a/src/lib/libcrypto/bn/asm/x86-gf2m.pl +++ b/src/lib/libcrypto/bn/asm/x86-gf2m.pl | |||
@@ -203,12 +203,12 @@ if (!$x86only) { | |||
203 | &picmeup("edx","OPENSSL_ia32cap_P"); | 203 | &picmeup("edx","OPENSSL_ia32cap_P"); |
204 | &mov ("eax",&DWP(0,"edx")); | 204 | &mov ("eax",&DWP(0,"edx")); |
205 | &mov ("edx",&DWP(4,"edx")); | 205 | &mov ("edx",&DWP(4,"edx")); |
206 | &test ("eax",1<<23); # check MMX bit | 206 | &test ("eax","\$IA32CAP_MASK0_MMX"); # check MMX bit |
207 | &jz (&label("ialu")); | 207 | &jz (&label("ialu")); |
208 | if ($sse2) { | 208 | if ($sse2) { |
209 | &test ("eax",1<<24); # check FXSR bit | 209 | &test ("eax","\$IA32CAP_MASK0_FXSR"); # check FXSR bit |
210 | &jz (&label("mmx")); | 210 | &jz (&label("mmx")); |
211 | &test ("edx",1<<1); # check PCLMULQDQ bit | 211 | &test ("edx","\$IA32CAP_MASK1_PCLMUL"); # check PCLMULQDQ bit |
212 | &jz (&label("mmx")); | 212 | &jz (&label("mmx")); |
213 | 213 | ||
214 | &movups ("xmm0",&QWP(8,"esp")); | 214 | &movups ("xmm0",&QWP(8,"esp")); |
diff --git a/src/lib/libcrypto/bn/asm/x86-mont.pl b/src/lib/libcrypto/bn/asm/x86-mont.pl index e8f6b05084..a0bdd5787e 100755 --- a/src/lib/libcrypto/bn/asm/x86-mont.pl +++ b/src/lib/libcrypto/bn/asm/x86-mont.pl | |||
@@ -114,7 +114,7 @@ $temp="mm6"; | |||
114 | $mask="mm7"; | 114 | $mask="mm7"; |
115 | 115 | ||
116 | &picmeup("eax","OPENSSL_ia32cap_P"); | 116 | &picmeup("eax","OPENSSL_ia32cap_P"); |
117 | &bt (&DWP(0,"eax"),26); | 117 | &bt (&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); |
118 | &jnc (&label("non_sse2")); | 118 | &jnc (&label("non_sse2")); |
119 | 119 | ||
120 | &mov ("eax",-1); | 120 | &mov ("eax",-1); |
diff --git a/src/lib/libcrypto/bn/asm/x86_64-gf2m.pl b/src/lib/libcrypto/bn/asm/x86_64-gf2m.pl index 8e45c7479b..3ecb425dad 100644 --- a/src/lib/libcrypto/bn/asm/x86_64-gf2m.pl +++ b/src/lib/libcrypto/bn/asm/x86_64-gf2m.pl | |||
@@ -163,12 +163,13 @@ ___ | |||
163 | 163 | ||
164 | $code.=<<___; | 164 | $code.=<<___; |
165 | .extern OPENSSL_ia32cap_P | 165 | .extern OPENSSL_ia32cap_P |
166 | .hidden OPENSSL_ia32cap_P | ||
166 | .globl bn_GF2m_mul_2x2 | 167 | .globl bn_GF2m_mul_2x2 |
167 | .type bn_GF2m_mul_2x2,\@abi-omnipotent | 168 | .type bn_GF2m_mul_2x2,\@abi-omnipotent |
168 | .align 16 | 169 | .align 16 |
169 | bn_GF2m_mul_2x2: | 170 | bn_GF2m_mul_2x2: |
170 | mov OPENSSL_ia32cap_P(%rip),%rax | 171 | mov OPENSSL_ia32cap_P+4(%rip),%eax |
171 | bt \$33,%rax | 172 | bt \$IA32CAP_BIT1_PCLMUL,%eax |
172 | jnc .Lvanilla_mul_2x2 | 173 | jnc .Lvanilla_mul_2x2 |
173 | 174 | ||
174 | movd $a1,%xmm0 | 175 | movd $a1,%xmm0 |