From 1a12fc8399638223feca8f853e2ac2cc22eeb471 Mon Sep 17 00:00:00 2001 From: miod <> Date: Fri, 4 Nov 2016 17:30:30 +0000 Subject: 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@ --- src/lib/libcrypto/bn/asm/bn-586.pl | 12 ++++++------ src/lib/libcrypto/bn/asm/x86-gf2m.pl | 6 +++--- src/lib/libcrypto/bn/asm/x86-mont.pl | 2 +- src/lib/libcrypto/bn/asm/x86_64-gf2m.pl | 5 +++-- 4 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src/lib/libcrypto/bn/asm') 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 { local($name)=@_; - &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); + &function_begin_B($name,""); $r="eax"; $a="edx"; @@ -33,7 +33,7 @@ sub bn_mul_add_words if ($sse2) { &picmeup("eax","OPENSSL_ia32cap_P"); - &bt(&DWP(0,"eax"),26); + &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); &jnc(&label("maw_non_sse2")); &mov($r,&wparam(0)); @@ -211,7 +211,7 @@ sub bn_mul_words { local($name)=@_; - &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); + &function_begin_B($name,""); $r="eax"; $a="edx"; @@ -219,7 +219,7 @@ sub bn_mul_words if ($sse2) { &picmeup("eax","OPENSSL_ia32cap_P"); - &bt(&DWP(0,"eax"),26); + &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); &jnc(&label("mw_non_sse2")); &mov($r,&wparam(0)); @@ -322,7 +322,7 @@ sub bn_sqr_words { local($name)=@_; - &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); + &function_begin_B($name,""); $r="eax"; $a="edx"; @@ -330,7 +330,7 @@ sub bn_sqr_words if ($sse2) { &picmeup("eax","OPENSSL_ia32cap_P"); - &bt(&DWP(0,"eax"),26); + &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); &jnc(&label("sqr_non_sse2")); &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) { &picmeup("edx","OPENSSL_ia32cap_P"); &mov ("eax",&DWP(0,"edx")); &mov ("edx",&DWP(4,"edx")); - &test ("eax",1<<23); # check MMX bit + &test ("eax","\$IA32CAP_MASK0_MMX"); # check MMX bit &jz (&label("ialu")); if ($sse2) { - &test ("eax",1<<24); # check FXSR bit + &test ("eax","\$IA32CAP_MASK0_FXSR"); # check FXSR bit &jz (&label("mmx")); - &test ("edx",1<<1); # check PCLMULQDQ bit + &test ("edx","\$IA32CAP_MASK1_PCLMUL"); # check PCLMULQDQ bit &jz (&label("mmx")); &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"; $mask="mm7"; &picmeup("eax","OPENSSL_ia32cap_P"); - &bt (&DWP(0,"eax"),26); + &bt (&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2"); &jnc (&label("non_sse2")); &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 @@ ___ $code.=<<___; .extern OPENSSL_ia32cap_P +.hidden OPENSSL_ia32cap_P .globl bn_GF2m_mul_2x2 .type bn_GF2m_mul_2x2,\@abi-omnipotent .align 16 bn_GF2m_mul_2x2: - mov OPENSSL_ia32cap_P(%rip),%rax - bt \$33,%rax + mov OPENSSL_ia32cap_P+4(%rip),%eax + bt \$IA32CAP_BIT1_PCLMUL,%eax jnc .Lvanilla_mul_2x2 movd $a1,%xmm0 -- cgit v1.2.3-55-g6feb