summaryrefslogtreecommitdiffstats
path: root/crypto/bn
diff options
context:
space:
mode:
authorAndy Polyakov <appro@openssl.org>2014-06-27 00:07:15 +0200
committerAndy Polyakov <appro@openssl.org>2014-06-27 00:36:05 +0200
commit82a9dafe32e1e39b5adff18f9061e43d8df3d3c5 (patch)
treee6cec6c7989d6ab8fc95cbe7a6c4dc4d8abc479b /crypto/bn
parent1536bcfd567d6e369abac1fcaafd56bf7d16d7bb (diff)
bn_exp.c: move check for AD*X to rsaz-avx2.pl.
This ensures high performance is situations when assembler supports AVX2, but not AD*X. (cherry picked from commit f3f620e1e0fa3553116f0b3e8c8d68b070fcdb79) Resolved conflicts: crypto/bn/asm/rsaz-avx2.pl
Diffstat (limited to 'crypto/bn')
-rwxr-xr-xcrypto/bn/asm/rsaz-avx2.pl12
-rw-r--r--crypto/bn/bn_exp.c3
2 files changed, 13 insertions, 2 deletions
diff --git a/crypto/bn/asm/rsaz-avx2.pl b/crypto/bn/asm/rsaz-avx2.pl
index 3eb95569fb..bd4a6a895c 100755
--- a/crypto/bn/asm/rsaz-avx2.pl
+++ b/crypto/bn/asm/rsaz-avx2.pl
@@ -78,16 +78,19 @@ die "can't locate x86_64-xlate.pl";
if (`$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1`
=~ /GNU assembler version ([2-9]\.[0-9]+)/) {
$avx = ($1>=2.19) + ($1>=2.22);
+ $addx = ($1>=2.23);
}
if (!$avx && $win64 && ($flavour =~ /nasm/ || $ENV{ASM} =~ /nasm/) &&
`nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)/) {
$avx = ($1>=2.09) + ($1>=2.10);
+ $addx = ($1>=2.10);
}
if (!$avx && $win64 && ($flavour =~ /masm/ || $ENV{ASM} =~ /ml64/) &&
`ml64 2>&1` =~ /Version ([0-9]+)\./) {
$avx = ($1>=10) + ($1>=11);
+ $addx = ($1>=11);
}
open OUT,"| $^X $xlate $flavour $output";
@@ -1673,6 +1676,15 @@ $code.=<<___;
.align 32
rsaz_avx2_eligible:
mov OPENSSL_ia32cap_P+8(%rip),%eax
+___
+$code.=<<___ if ($addx);
+ mov \$`1<<8|1<<19`,%ecx
+ mov \$0,%edx
+ and %eax,%ecx
+ cmp \$`1<<8|1<<19`,%ecx # check for BMI2+AD*X
+ cmove %edx,%eax
+___
+$code.=<<___;
and \$`1<<5`,%eax
shr \$5,%eax
ret
diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c
index 3fa8cda842..8fb319ad7c 100644
--- a/crypto/bn/bn_exp.c
+++ b/crypto/bn/bn_exp.c
@@ -693,8 +693,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
* RSAZ exponentiation. For further information see
* crypto/bn/rsaz_exp.c and accompanying assembly modules.
*/
- if (((OPENSSL_ia32cap_P[2]&0x80100) != 0x80100) /* check for MULX/AD*X */
- && (16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)
+ if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)
&& rsaz_avx2_eligible())
{
if (NULL == bn_wexpand(rr, 16)) goto err;