Re: [PowerPC64] Add AIX to cpu detection

2020-07-20 Thread Maamoun TK
The current assembly implementations for ppc support only AES and GCM,
those implementations take advantage of crypto extensions that
introduced in POWER8. It may be good in the future to extend the detection
to VSX and arch 3.00 ...etc if more algorithms are implemented but for now
I think this is fine.

On Mon, Jul 20, 2020 at 7:34 PM Jeffrey Walton  wrote:

> On Mon, Jul 20, 2020 at 12:18 PM Maamoun TK 
> wrote:
> >
> > ---
> >  fat-ppc.c | 29 -
> >  1 file changed, 20 insertions(+), 9 deletions(-)
> >
> > diff --git a/fat-ppc.c b/fat-ppc.c
> > index e09b2097..eca689fe 100644
> > --- a/fat-ppc.c
> > +++ b/fat-ppc.c
> > @@ -39,10 +39,17 @@
> >  #include 
> >  #include 
> >  #include 
> > -#if defined(__FreeBSD__) && __FreeBSD__ < 12
> > -#include 
> > -#else
> > +
> > +#if defined(_AIX)
> > +#include 
> > +#elif defined(__linux__)
> > +#include 
> > +#elif defined(__FreeBSD__)
> > +#if __FreeBSD__ >= 12
> >  #include 
> > +#else
> > +#include 
> > +#endif
> >  #endif
> >
> >  #include "nettle-types.h"
> > @@ -64,19 +71,23 @@ struct ppc_features
> >  static void
> >  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 hwcap2 = 0;
> > -#if defined(__FreeBSD__)
> > -#if __FreeBSD__ < 12
> > +#if defined(__linux__)
> > +  hwcap2 = getauxval(AT_HWCAP2);
> > +#elif defined(__FreeBSD__)
> > +#if __FreeBSD__ >= 12
> > +  elf_aux_info(AT_HWCAP2, , sizeof(hwcap2));
> > +#else
> >size_t len = sizeof(hwcap2);
> >sysctlbyname("hw.cpu_features2", , , NULL, 0);
> > -#else
> > -  elf_aux_info(AT_HWCAP2, , sizeof(hwcap2));
> >  #endif
> > -#else
> > -  hwcap2 = getauxval(AT_HWCAP2);
> >  #endif
> >features->have_crypto_ext =
> > (hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO ? 1 :
> 0;
> > +#endif
> >  }
> >
> >  DECLARE_FAT_FUNC(_nettle_aes_encrypt, aes_crypt_internal_func)
> > --
> > 2.17.1
>
> Hi Maamon,
>
> One small comment...
>
> You may want to stay flexible enough to detect POWER7, VSX and above.
> ChaCha is fast as hell even on POWER7 and without 64-bit vectors. In
> fact, I found ChaCha is profitable down to POWER4 on an old PowerMac.
>
> Jeff
>
___
nettle-bugs mailing list
nettle-bugs@lists.lysator.liu.se
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs


Re: [PowerPC64] Add AIX to cpu detection

2020-07-20 Thread Jeffrey Walton
On Mon, Jul 20, 2020 at 12:18 PM Maamoun TK  wrote:
>
> ---
>  fat-ppc.c | 29 -
>  1 file changed, 20 insertions(+), 9 deletions(-)
>
> diff --git a/fat-ppc.c b/fat-ppc.c
> index e09b2097..eca689fe 100644
> --- a/fat-ppc.c
> +++ b/fat-ppc.c
> @@ -39,10 +39,17 @@
>  #include 
>  #include 
>  #include 
> -#if defined(__FreeBSD__) && __FreeBSD__ < 12
> -#include 
> -#else
> +
> +#if defined(_AIX)
> +#include 
> +#elif defined(__linux__)
> +#include 
> +#elif defined(__FreeBSD__)
> +#if __FreeBSD__ >= 12
>  #include 
> +#else
> +#include 
> +#endif
>  #endif
>
>  #include "nettle-types.h"
> @@ -64,19 +71,23 @@ struct ppc_features
>  static void
>  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 hwcap2 = 0;
> -#if defined(__FreeBSD__)
> -#if __FreeBSD__ < 12
> +#if defined(__linux__)
> +  hwcap2 = getauxval(AT_HWCAP2);
> +#elif defined(__FreeBSD__)
> +#if __FreeBSD__ >= 12
> +  elf_aux_info(AT_HWCAP2, , sizeof(hwcap2));
> +#else
>size_t len = sizeof(hwcap2);
>sysctlbyname("hw.cpu_features2", , , NULL, 0);
> -#else
> -  elf_aux_info(AT_HWCAP2, , sizeof(hwcap2));
>  #endif
> -#else
> -  hwcap2 = getauxval(AT_HWCAP2);
>  #endif
>features->have_crypto_ext =
> (hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO ? 1 : 0;
> +#endif
>  }
>
>  DECLARE_FAT_FUNC(_nettle_aes_encrypt, aes_crypt_internal_func)
> --
> 2.17.1

Hi Maamon,

One small comment...

You may want to stay flexible enough to detect POWER7, VSX and above.
ChaCha is fast as hell even on POWER7 and without 64-bit vectors. In
fact, I found ChaCha is profitable down to POWER4 on an old PowerMac.

Jeff
___
nettle-bugs mailing list
nettle-bugs@lists.lysator.liu.se
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs


[PowerPC64] Add AIX to cpu detection

2020-07-20 Thread Maamoun TK
---
 fat-ppc.c | 29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/fat-ppc.c b/fat-ppc.c
index e09b2097..eca689fe 100644
--- a/fat-ppc.c
+++ b/fat-ppc.c
@@ -39,10 +39,17 @@
 #include 
 #include 
 #include 
-#if defined(__FreeBSD__) && __FreeBSD__ < 12
-#include 
-#else
+
+#if defined(_AIX)
+#include 
+#elif defined(__linux__)
+#include 
+#elif defined(__FreeBSD__)
+#if __FreeBSD__ >= 12
 #include 
+#else
+#include 
+#endif
 #endif

 #include "nettle-types.h"
@@ -64,19 +71,23 @@ struct ppc_features
 static void
 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 hwcap2 = 0;
-#if defined(__FreeBSD__)
-#if __FreeBSD__ < 12
+#if defined(__linux__)
+  hwcap2 = getauxval(AT_HWCAP2);
+#elif defined(__FreeBSD__)
+#if __FreeBSD__ >= 12
+  elf_aux_info(AT_HWCAP2, , sizeof(hwcap2));
+#else
   size_t len = sizeof(hwcap2);
   sysctlbyname("hw.cpu_features2", , , NULL, 0);
-#else
-  elf_aux_info(AT_HWCAP2, , sizeof(hwcap2));
 #endif
-#else
-  hwcap2 = getauxval(AT_HWCAP2);
 #endif
   features->have_crypto_ext =
(hwcap2 & PPC_FEATURE2_VEC_CRYPTO) == PPC_FEATURE2_VEC_CRYPTO ? 1 : 0;
+#endif
 }

 DECLARE_FAT_FUNC(_nettle_aes_encrypt, aes_crypt_internal_func)
--
2.17.1
___
nettle-bugs mailing list
nettle-bugs@lists.lysator.liu.se
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs