From 20bba29df0141d703962f0cd7bac1d7dddf5e792 Mon Sep 17 00:00:00 2001 From: Manuel Frischknecht Date: Thu, 25 Apr 2024 16:14:39 +0200 Subject: [PATCH] Fix CPU architecture guards for x86 and x64 on MSVC MSVC uses `_M_IX86` and `_M_AMD64` for CPU architecture guards instead of `__i386__` and `__x86_64__` [^1]. Because of that, libaegis didn't upgrade from the software implementation to those powered by AESNI or AVX when compiled with Microsoft's Visual Studio build tools. [^1]: As per the table here: https://sourceforge.net/p/predef/wiki/Architectures/ http://web.archive.org/web/20240211072249/https://sourceforge.net/p/predef/wiki/Architectures/ https://archive.is/jRq9r --- src/aegis128l/aegis128l.c | 2 +- src/aegis128l/aegis128l_aesni.c | 2 +- src/aegis128x2/aegis128x2.c | 2 +- src/aegis128x2/aegis128x2_aesni.c | 2 +- src/aegis128x2/aegis128x2_avx2.c | 2 +- src/aegis128x4/aegis128x4.c | 2 +- src/aegis128x4/aegis128x4_aesni.c | 2 +- src/aegis128x4/aegis128x4_avx2.c | 2 +- src/aegis128x4/aegis128x4_avx512.c | 2 +- src/aegis256/aegis256.c | 2 +- src/aegis256/aegis256_aesni.c | 2 +- src/aegis256x2/aegis256x2.c | 2 +- src/aegis256x2/aegis256x2_aesni.c | 2 +- src/aegis256x2/aegis256x2_avx2.c | 2 +- src/aegis256x4/aegis256x4.c | 2 +- src/aegis256x4/aegis256x4_aesni.c | 2 +- src/aegis256x4/aegis256x4_avx2.c | 2 +- src/aegis256x4/aegis256x4_avx512.c | 2 +- src/common/common.h | 5 +++-- 19 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/aegis128l/aegis128l.c b/src/aegis128l/aegis128l.c index 79b82a4..f6273f3 100644 --- a/src/aegis128l/aegis128l.c +++ b/src/aegis128l/aegis128l.c @@ -185,7 +185,7 @@ aegis128l_pick_best_implementation(void) } #endif -#if defined(__x86_64__) || defined(__i386__) +#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) { implementation = &aegis128l_aesni_implementation; return 0; diff --git a/src/aegis128l/aegis128l_aesni.c b/src/aegis128l/aegis128l_aesni.c index 96da6d4..6ba60b7 100644 --- a/src/aegis128l/aegis128l_aesni.c +++ b/src/aegis128l/aegis128l_aesni.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis128x2/aegis128x2.c b/src/aegis128x2/aegis128x2.c index 85f74ca..dda159d 100644 --- a/src/aegis128x2/aegis128x2.c +++ b/src/aegis128x2/aegis128x2.c @@ -186,7 +186,7 @@ aegis128x2_pick_best_implementation(void) } #endif -#if defined(__x86_64__) || defined(__i386__) +#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) { implementation = &aegis128x2_avx2_implementation; return 0; diff --git a/src/aegis128x2/aegis128x2_aesni.c b/src/aegis128x2/aegis128x2_aesni.c index 177a24b..dc4340f 100644 --- a/src/aegis128x2/aegis128x2_aesni.c +++ b/src/aegis128x2/aegis128x2_aesni.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis128x2/aegis128x2_avx2.c b/src/aegis128x2/aegis128x2_avx2.c index 2a2442b..44af2f6 100644 --- a/src/aegis128x2/aegis128x2_avx2.c +++ b/src/aegis128x2/aegis128x2_avx2.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis128x4/aegis128x4.c b/src/aegis128x4/aegis128x4.c index cdcfef5..c68c356 100644 --- a/src/aegis128x4/aegis128x4.c +++ b/src/aegis128x4/aegis128x4.c @@ -187,7 +187,7 @@ aegis128x4_pick_best_implementation(void) } #endif -#if defined(__x86_64__) || defined(__i386__) +#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) # ifdef HAVE_VAESINTRIN_H if (aegis_runtime_has_vaes() && aegis_runtime_has_avx512f()) { implementation = &aegis128x4_avx512_implementation; diff --git a/src/aegis128x4/aegis128x4_aesni.c b/src/aegis128x4/aegis128x4_aesni.c index 2ad2816..6917f4b 100644 --- a/src/aegis128x4/aegis128x4_aesni.c +++ b/src/aegis128x4/aegis128x4_aesni.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis128x4/aegis128x4_avx2.c b/src/aegis128x4/aegis128x4_avx2.c index b865d08..f704a4b 100644 --- a/src/aegis128x4/aegis128x4_avx2.c +++ b/src/aegis128x4/aegis128x4_avx2.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis128x4/aegis128x4_avx512.c b/src/aegis128x4/aegis128x4_avx512.c index f0fd251..5b325a7 100644 --- a/src/aegis128x4/aegis128x4_avx512.c +++ b/src/aegis128x4/aegis128x4_avx512.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis256/aegis256.c b/src/aegis256/aegis256.c index 5a251b6..3699d60 100644 --- a/src/aegis256/aegis256.c +++ b/src/aegis256/aegis256.c @@ -185,7 +185,7 @@ aegis256_pick_best_implementation(void) } #endif -#if defined(__x86_64__) || defined(__i386__) +#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) if (aegis_runtime_has_aesni() && aegis_runtime_has_avx()) { implementation = &aegis256_aesni_implementation; return 0; diff --git a/src/aegis256/aegis256_aesni.c b/src/aegis256/aegis256_aesni.c index b1a0087..1f02c22 100644 --- a/src/aegis256/aegis256_aesni.c +++ b/src/aegis256/aegis256_aesni.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis256x2/aegis256x2.c b/src/aegis256x2/aegis256x2.c index b126601..787b7e9 100644 --- a/src/aegis256x2/aegis256x2.c +++ b/src/aegis256x2/aegis256x2.c @@ -186,7 +186,7 @@ aegis256x2_pick_best_implementation(void) } #endif -#if defined(__x86_64__) || defined(__i386__) +#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) if (aegis_runtime_has_vaes() && aegis_runtime_has_avx2()) { implementation = &aegis256x2_avx2_implementation; return 0; diff --git a/src/aegis256x2/aegis256x2_aesni.c b/src/aegis256x2/aegis256x2_aesni.c index af1f785..cd96d15 100644 --- a/src/aegis256x2/aegis256x2_aesni.c +++ b/src/aegis256x2/aegis256x2_aesni.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis256x2/aegis256x2_avx2.c b/src/aegis256x2/aegis256x2_avx2.c index cc4ee70..ed8aa13 100644 --- a/src/aegis256x2/aegis256x2_avx2.c +++ b/src/aegis256x2/aegis256x2_avx2.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis256x4/aegis256x4.c b/src/aegis256x4/aegis256x4.c index e07e339..f11f9c4 100644 --- a/src/aegis256x4/aegis256x4.c +++ b/src/aegis256x4/aegis256x4.c @@ -187,7 +187,7 @@ aegis256x4_pick_best_implementation(void) } #endif -#if defined(__x86_64__) || defined(__i386__) +#if defined(__x86_64__) || defined(_M_AMD64) || defined(__i386__) || defined(_M_IX86) # ifdef HAVE_VAESINTRIN_H if (aegis_runtime_has_vaes() && aegis_runtime_has_avx512f()) { implementation = &aegis256x4_avx512_implementation; diff --git a/src/aegis256x4/aegis256x4_aesni.c b/src/aegis256x4/aegis256x4_aesni.c index 0f165d9..4cdd774 100644 --- a/src/aegis256x4/aegis256x4_aesni.c +++ b/src/aegis256x4/aegis256x4_aesni.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis256x4/aegis256x4_avx2.c b/src/aegis256x4/aegis256x4_avx2.c index 113723b..404fcda 100644 --- a/src/aegis256x4/aegis256x4_avx2.c +++ b/src/aegis256x4/aegis256x4_avx2.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/aegis256x4/aegis256x4_avx512.c b/src/aegis256x4/aegis256x4_avx512.c index ecdf127..652fee9 100644 --- a/src/aegis256x4/aegis256x4_avx512.c +++ b/src/aegis256x4/aegis256x4_avx512.c @@ -1,4 +1,4 @@ -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) # include # include diff --git a/src/common/common.h b/src/common/common.h index d66321e..a822558 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -14,14 +14,15 @@ #ifdef __ANDROID_API__ # define HAVE_ANDROID_GETCPUFEATURES #endif -#if defined(__i386__) || defined(__x86_64__) +#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_AMD64) + # define HAVE_CPUID # define NATIVE_LITTLE_ENDIAN # if defined(__clang__) || defined(__GNUC__) # define HAVE_AVX_ASM # endif #endif -#ifdef __x86_64__ +#if defined(__x86_64__) || defined(_M_AMD64) # define HAVE_AVXINTRIN_H # define HAVE_AVX2INTRIN_H # define HAVE_AVX512FINTRIN_H