]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
ppc: Add altivec detection to fat builds
authorNiels Möller <nisse@lysator.liu.se>
Sat, 7 Nov 2020 09:35:02 +0000 (10:35 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Sat, 7 Nov 2020 09:35:02 +0000 (10:35 +0100)
ChangeLog
configure.ac
fat-ppc.c
powerpc64/fat/chacha-core-internal-2.asm [new file with mode: 0644]

index 5e994dbc25d7bb3064708cd956c0fa07cbe6adba..1603036970128ac07ea7bb6d51a36ef39ab2768f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-11-07  Niels Möller  <nisse@lysator.liu.se>
+
+       * configure.ac: New command line option --enable-power-altivec.
+       Update asm_path logic, and add altivec to FAT_TEST_LIST.
+       * fat-ppc.c (get_ppc_features): Add logic to check for altivec and
+       vsx support, and select aither C or altivec implementation of
+       chacha_core.
+       * powerpc64/fat/chacha-core-internal-2.asm: New file.
+
 2020-09-25  Niels Möller  <nisse@lysator.liu.se>
 
        * powerpc64/p7/chacha-core-internal.asm: New file.
index ab12496f257f1a29867a73ea71ec4114ee9c349f..2a47f9403a0d3dd28bea5160ea4baf4d212b06c0 100644 (file)
@@ -93,6 +93,10 @@ AC_ARG_ENABLE(power-crypto-ext,
   AC_HELP_STRING([--enable-power-crypto-ext], [Enable POWER crypto extensions. (default=no)]),,
   [enable_power_crypto_ext=no])
 
+AC_ARG_ENABLE(power-altivec,
+  AC_HELP_STRING([--enable-power-altivec], [Enable POWER altivec and vsx extensions. (default=no)]),,
+  [enable_altivec=no])
+
 AC_ARG_ENABLE(mini-gmp,
   AC_HELP_STRING([--enable-mini-gmp], [Enable mini-gmp, used instead of libgmp.]),,
   [enable_mini_gmp=no])
@@ -458,13 +462,18 @@ if test "x$enable_assembler" = xyes ; then
     *powerpc64*)
       if test "$ABI" = 64 ; then
        GMP_ASM_POWERPC_R_REGISTERS
-       asm_path="powerpc64/p7 powerpc64"
+       asm_path="powerpc64"
        if test "x$enable_fat" = xyes ; then
          asm_path="powerpc64/fat $asm_path"
          OPT_NETTLE_SOURCES="fat-ppc.c $OPT_NETTLE_SOURCES"
-         FAT_TEST_LIST="none crypto_ext"
-       elif test "x$enable_power_crypto_ext" = xyes ; then
-          asm_path="powerpc64/p8 $asm_path"
+         FAT_TEST_LIST="none crypto_ext altivec"
+       else
+         if test "$enable_power_crypto_ext" = yes ; then
+            asm_path="powerpc64/p8 $asm_path"
+         fi
+         if test "$enable_power_altivec" = yes ; then
+           asm_path="powerpc64/p7 $asm_path"
+         fi
        fi
       fi
       ;;
index 2bc504810b80e4f502394a0360f803a3a2b019c2..2bfd649f7a3b115681fba891cc46bb66cdc414c4 100644 (file)
--- a/fat-ppc.c
+++ b/fat-ppc.c
@@ -66,6 +66,7 @@
 struct ppc_features
 {
   int have_crypto_ext;
+  int have_altivec;
 };
 
 #define MATCH(s, slen, literal, llen) \
@@ -76,6 +77,7 @@ get_ppc_features (struct ppc_features *features)
 {
   const char *s;
   features->have_crypto_ext = 0;
+  features->have_altivec = 0;
 
   s = secure_getenv (ENV_OVERRIDE);
   if (s)
@@ -86,6 +88,8 @@ get_ppc_features (struct ppc_features *features)
 
        if (MATCH (s, length, "crypto_ext", 10))
          features->have_crypto_ext = 1;
+       else if (MATCH(s, length, "altivec", 7))
+         features->have_altivec = 1;
        if (!sep)
          break;
        s = sep + 1;
@@ -95,8 +99,10 @@ get_ppc_features (struct ppc_features *features)
 #if defined(_AIX) && defined(__power_8_andup)
       features->have_crypto_ext = __power_8_andup() != 0 ? 1 : 0;
 #else
+      unsigned long hwcap = 0;
       unsigned long hwcap2 = 0;
 # if defined(__linux__)
+      hwcap = getauxval(AT_HWCAP);
       hwcap2 = getauxval(AT_HWCAP2);
 # elif defined(__FreeBSD__)
 #  if __FreeBSD__ >= 12
@@ -106,8 +112,13 @@ get_ppc_features (struct ppc_features *features)
       sysctlbyname("hw.cpu_features2", &hwcap2, &len, NULL, 0);
 #  endif
 # endif
-      features->have_crypto_ext =
-       (hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO ? 1 : 0;
+      features->have_crypto_ext
+       = ((hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO);
+
+      /* We also need VSX instructions, mainly for load and store. */
+      features->have_altivec
+       = ((hwcap & (PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_VSX))
+          == (PPC_FEATURE_HAS_ALTIVEC | PPC_FEATURE_HAS_VSX));
 #endif
     }
 }
@@ -120,6 +131,10 @@ DECLARE_FAT_FUNC(_nettle_aes_decrypt, aes_crypt_internal_func)
 DECLARE_FAT_FUNC_VAR(aes_decrypt, aes_crypt_internal_func, c)
 DECLARE_FAT_FUNC_VAR(aes_decrypt, aes_crypt_internal_func, ppc64)
 
+DECLARE_FAT_FUNC(_nettle_chacha_core, chacha_core_func)
+DECLARE_FAT_FUNC_VAR(chacha_core, chacha_core_func, c);
+DECLARE_FAT_FUNC_VAR(chacha_core, chacha_core_func, altivec);
+
 static void CONSTRUCTOR
 fat_init (void)
 {
@@ -145,6 +160,16 @@ fat_init (void)
       _nettle_aes_encrypt_vec = _nettle_aes_encrypt_c;
       _nettle_aes_decrypt_vec = _nettle_aes_decrypt_c;
     }
+  if (features.have_altivec)
+    {
+      if (verbose)
+       fprintf (stderr, "libnettle: enabling altivec code.\n");
+      _nettle_chacha_core_vec = _nettle_chacha_core_altivec;
+    }
+  else
+    {
+      _nettle_chacha_core_vec = _nettle_chacha_core_c;
+    }
 }
 
 DEFINE_FAT_FUNC(_nettle_aes_encrypt, void,
@@ -160,3 +185,7 @@ DEFINE_FAT_FUNC(_nettle_aes_decrypt, void,
  size_t length, uint8_t *dst,
  const uint8_t *src),
  (rounds, keys, T, length, dst, src))
+
+DEFINE_FAT_FUNC(_nettle_chacha_core, void,
+               (uint32_t *dst, const uint32_t *src, unsigned rounds),
+               (dst, src, rounds))
diff --git a/powerpc64/fat/chacha-core-internal-2.asm b/powerpc64/fat/chacha-core-internal-2.asm
new file mode 100644 (file)
index 0000000..35c059e
--- /dev/null
@@ -0,0 +1,37 @@
+C powerpc64/fat/chacha-core-internal-2.asm
+
+
+ifelse(`
+   Copyright (C) 2020 Niels Möller
+
+   This file is part of GNU Nettle.
+
+   GNU Nettle is free software: you can redistribute it and/or
+   modify it under the terms of either:
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at your
+       option) any later version.
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at your
+       option) any later version.
+
+   or both in parallel, as here.
+
+   GNU Nettle is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see http://www.gnu.org/licenses/.
+')
+
+dnl PROLOGUE(_nettle_chacha_core) picked up by configure
+
+define(`fat_transform', `$1_altivec')
+include_src(`powerpc64/p7/chacha-core-internal.asm')