[PATCH] Make BMI2 inline assembly check more robust

Jussi Kivilinna jussi.kivilinna at iki.fi
Tue Jan 9 18:23:35 CET 2018


* configure.ac (gcry_cv_gcc_inline_asm_bmi2): New assembly test.
--

Use actual assembly snippets from keccak.c to check that compiler
has proper support for used BMI2 instructions.

GnuPG-bug-id: 3408
Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 configure.ac |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 42cd4c27b..aaf3c82a9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1403,8 +1403,15 @@ AC_CACHE_CHECK([whether GCC inline assembler supports BMI2 instructions],
         else
           gcry_cv_gcc_inline_asm_bmi2=no
           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
-          [[void a(void) {
-              __asm__("rorxl \$23, %%eax, %%edx\\n\\t":::"memory");
+          [[unsigned int a(unsigned int x, unsigned int y) {
+              unsigned int tmp1, tmp2;
+              asm ("rorxl %2, %1, %0"
+                   : "=r" (tmp1)
+                   : "rm0" (x), "J" (32 - ((23) & 31)));
+              asm ("andnl %2, %1, %0"
+                   : "=r" (tmp2)
+                   : "r0" (x), "rm" (y));
+              return tmp1 + tmp2;
             }]])],
           [gcry_cv_gcc_inline_asm_bmi2=yes])
         fi])




More information about the Gcrypt-devel mailing list