* cipher/Makefile.am (riscv_vector_cflags, riscv_vector_crypto_cflags): Use
"-mstrict-align" if SUPPORT_CC_RISCV_MSTRICT_ALIGN is set.
* configure.ac (SUPPORT_CC_RISCV_MSTRICT_ALIGN): Add check for "-mstrict-align"
compiler flag support.
--

Signed-off-by: Jussi Kivilinna <jussi.kivili...@iki.fi>
---
 cipher/Makefile.am | 12 ++++++++++--
 configure.ac       | 25 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/cipher/Makefile.am b/cipher/Makefile.am
index 3375ea38..ea91b7b8 100644
--- a/cipher/Makefile.am
+++ b/cipher/Makefile.am
@@ -355,12 +355,16 @@ serpent-avx512-x86.o: $(srcdir)/serpent-avx512-x86.c 
Makefile
 serpent-avx512-x86.lo: $(srcdir)/serpent-avx512-x86.c Makefile
        `echo $(LTCOMPILE) $(avx512f_cflags) -c $< | $(instrumentation_munging) 
`
 
-if ENABLE_RISCV_VECTOR_INTRINSICS_EXTRA_CFLAGS
 # Note: -mstrict-align needed for GCC-14 bug (disable unaligned vector loads)
+if ENABLE_RISCV_VECTOR_INTRINSICS_EXTRA_CFLAGS
 riscv_vector_cflags = -O2 -march=rv64imafdcv -mstrict-align
 else
+if SUPPORT_CC_RISCV_MSTRICT_ALIGN
+riscv_vector_cflags = -O2 -mstrict-align
+else
 riscv_vector_cflags =
 endif
+endif
 
 chacha20-riscv-v.o: $(srcdir)/chacha20-riscv-v.c Makefile
        `echo $(COMPILE) $(riscv_vector_cflags) -c $< | 
$(instrumentation_munging) `
@@ -374,12 +378,16 @@ rijndael-vp-riscv.o: $(srcdir)/rijndael-vp-riscv.c 
Makefile
 rijndael-vp-riscv.lo: $(srcdir)/rijndael-vp-riscv.c Makefile
        `echo $(LTCOMPILE) $(riscv_vector_cflags) -c $< | 
$(instrumentation_munging) `
 
-if ENABLE_RISCV_VECTOR_CRYPTO_INTRINSICS_EXTRA_CFLAGS
 # Note: -mstrict-align needed for GCC-14 bug (disable unaligned vector loads)
+if ENABLE_RISCV_VECTOR_CRYPTO_INTRINSICS_EXTRA_CFLAGS
 riscv_vector_crypto_cflags = -O2 -march=rv64imafdcv_zvbc_zvkg_zvkn_zvks 
-mstrict-align
 else
+if SUPPORT_CC_RISCV_MSTRICT_ALIGN
+riscv_vector_crypto_cflags = -O2 -mstrict-align
+else
 riscv_vector_crypto_cflags =
 endif
+endif
 
 sha256-riscv-zvknha-zvkb.o: $(srcdir)/sha256-riscv-zvknha-zvkb.c Makefile
        `echo $(COMPILE) $(riscv_vector_crypto_cflags) -c $< | 
$(instrumentation_munging) `
diff --git a/configure.ac b/configure.ac
index 63bdfbe7..d45ea851 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2666,6 +2666,31 @@ if test "$gcry_cv_gcc_inline_asm_riscv_v" = "yes" ; then
 fi
 
 
+#
+# Check whether compiler supports RISC-V -mstrict-align flag
+#
+_gcc_cflags_save=$CFLAGS
+# Note: -mstrict-align needed for GCC-14 bug (disable unaligned vector loads)
+CFLAGS="$CFLAGS -mstrict-align"
+
+AC_CACHE_CHECK([whether compiler supports RISC-V -mstrict-align flag],
+      [gcry_cv_cc_riscv_mstrict_align],
+      [if test "$mpi_cpu_arch" != "riscv64" ||
+         test "$try_asm_modules" != "yes" ; then
+       gcry_cv_cc_riscv_mstrict_align="n/a"
+      else
+       gcry_cv_cc_riscv_mstrict_align=no
+       AC_COMPILE_IFELSE(
+         [AC_LANG_SOURCE([[void testfn(void) { }]])],
+         [gcry_cv_cc_riscv_mstrict_align=yes])
+      fi])
+AM_CONDITIONAL(SUPPORT_CC_RISCV_MSTRICT_ALIGN,
+              test "$gcry_cv_cc_riscv_mstrict_align" = "yes")
+
+# Restore flags.
+CFLAGS=$_gcc_cflags_save;
+
+
 #
 # Check whether compiler supports RISC-V vector intrinsics
 #
-- 
2.48.1


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
https://lists.gnupg.org/mailman/listinfo/gcrypt-devel

Reply via email to