From 6678b734ef7e91e0cf91d748910b778891a53e88 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 5 May 2024 11:41:46 -0400 Subject: sha3.c, Makefile, tests/bench/Makefile: allow overriding SHA3_BACKEND via command-line argument --- sha3.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'sha3.c') diff --git a/sha3.c b/sha3.c index 329a810..4073287 100644 --- a/sha3.c +++ b/sha3.c @@ -26,20 +26,28 @@ /** @cond INTERNAL */ // available backends -#define BACKEND_AVX512 8 // AVX-512 backend -#define BACKEND_NEON 4 // A64 Neon backend -#define BACKEND_SCALAR 0 // scalar (default) backend - -// auto-detect backend +#define BACKEND_AUTO 0 // auto-detect (default) +#define BACKEND_SCALAR 1 // scalar backend +#define BACKEND_AVX512 2 // AVX-512 backend +#define BACKEND_NEON 3 // Neon backend + +// if SHA3_BACKEND is defined and set to 0 (the default), then unset it +// and auto-detect the appropriate backend +#if defined(SHA3_BACKEND) && SHA3_BACKEND == BACKEND_AUTO +#undef SHA3_BACKEND +#endif /* defined(SHA3_BACKEND) && SHA3_BACKEND == 0 */ + +// detect backend #ifndef SHA3_BACKEND #if defined(__AVX512F__) #define SHA3_BACKEND BACKEND_AVX512 #elif defined(__ARM_NEON) #define SHA3_BACKEND BACKEND_NEON #else +// no optimized backend detected, fall back to scalar #define SHA3_BACKEND BACKEND_SCALAR #endif -#endif /* SHA3_BACKEND */ +#endif /* !SHA3_BACKEND */ // 64-bit rotate left #define ROL(v, n) (((v) << (n)) | ((v) >> (64-(n)))) -- cgit v1.2.3