cryptopp: fix cpu.cpp.patch

This commit is contained in:
Leonid Pliushch 2021-01-07 14:17:59 +02:00
parent 7f9739993f
commit 477209e02c
No known key found for this signature in database
GPG Key ID: 45F2964132545795

View File

@ -1,283 +1,168 @@
diff -uNr cryptopp/cpu.cpp cryptopp.mod/cpu.cpp diff -uNr cryptopp/cpu.cpp cryptopp.mod/cpu.cpp
--- cryptopp/cpu.cpp 2019-04-28 23:36:50.000000000 +0000 --- cryptopp/cpu.cpp 2021-01-01 19:03:59.000000000 +0200
+++ cryptopp.mod/cpu.cpp 2019-05-10 14:47:58.091890446 +0000 +++ cryptopp.mod/cpu.cpp 2021-01-07 14:16:48.145624898 +0200
@@ -47,7 +47,7 @@ @@ -54,7 +54,7 @@
// "$ANDROID_NDK_ROOT/sources/android/cpufeatures". // "$ANDROID_NDK_ROOT/sources/android/cpufeatures".
// setenv-android.sh will copy the header and source file // setenv-android.sh will copy the header and source file
// into PWD and the makefile will build it in place. // into PWD and the makefile will build it in place.
-#if defined(__ANDROID__) -#if defined(__ANDROID__)
+#if 0 +#if defined(__ANDROID__) && !defined(__TERMUX__)
# include "cpu-features.h" # include "cpu-features.h"
#endif #endif
@@ -548,264 +548,64 @@ @@ -762,6 +762,7 @@
inline bool CPU_QueryARMv7() inline bool CPU_QueryARMv7()
{ {
-#if defined(__aarch32__) || defined(__aarch64__) +#ifndef __TERMUX__
- // ARMv7 or above #if defined(__ANDROID__) && defined(__arm__)
+#if defined(__arm__) || defined(__aarch32__) || defined(__aarch64__) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) &&
((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_ARMv7) != 0))
@@ -774,11 +775,13 @@
// Apple hardware is ARMv7 or above.
return true; return true;
-#elif defined(__ANDROID__) && defined(__arm__) #endif
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) &&
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_ARMv7) != 0))
- return true;
-#elif defined(__linux__) && defined(__arm__)
- if ((getauxval(AT_HWCAP) & HWCAP_ARMv7) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__arm__)
- // Apple hardware is ARMv7 or above.
- return true;
-#endif
+#else
return false;
+#endif +#endif
return false;
} }
inline bool CPU_QueryNEON() inline bool CPU_QueryNEON()
{ {
-#if defined(__ANDROID__) && defined(__aarch64__) +#ifndef __TERMUX__
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_ASIMD) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_ASIMD) != 0))
-#elif defined(__ANDROID__) && defined(__arm__) @@ -800,11 +803,13 @@
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && // Core feature set for Aarch32 and Aarch64.
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0))
- return true;
-#elif defined(__linux__) && defined(__aarch64__)
- if ((getauxval(AT_HWCAP) & HWCAP_ASIMD) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_ASIMD) != 0)
- return true;
-#elif defined(__linux__) && defined(__arm__)
- if ((getauxval(AT_HWCAP) & HWCAP_ARM_NEON) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__)
- // Core feature set for Aarch32 and Aarch64.
+#if defined(__arm__) || defined(__aarch32__) || defined(__aarch64__)
return true; return true;
-#endif #endif
+#else
return false;
+#endif +#endif
return false;
} }
inline bool CPU_QueryCRC32() inline bool CPU_QueryCRC32()
{ {
-#if defined(__ANDROID__) && defined(__aarch64__) +#ifndef __TERMUX__
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_CRC32) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_CRC32) != 0))
-#elif defined(__ANDROID__) && defined(__aarch32__) @@ -823,11 +828,13 @@
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && // No compiler support. CRC intrinsics result in a failed compiled.
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_CRC32) != 0)) return false;
- return true; #endif
-#elif defined(__linux__) && defined(__aarch64__) +#endif
- if ((getauxval(AT_HWCAP) & HWCAP_CRC32) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_CRC32) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__)
- // No compiler support. CRC intrinsics result in a failed compiled.
- return false;
-#endif
return false; return false;
} }
inline bool CPU_QueryPMULL() inline bool CPU_QueryPMULL()
{ {
-#if defined(__ANDROID__) && defined(__aarch64__) +#ifndef __TERMUX__
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_PMULL) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_PMULL) != 0))
-#elif defined(__ANDROID__) && defined(__aarch32__) @@ -846,11 +853,13 @@
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && // No compiler support. PMULL intrinsics result in a failed compiled.
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_PMULL) != 0)) return false;
- return true; #endif
-#elif defined(__linux__) && defined(__aarch64__) +#endif
- if ((getauxval(AT_HWCAP) & HWCAP_PMULL) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_PMULL) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__)
- // No compiler support. PMULL intrinsics result in a failed compiled.
- return false;
-#endif
return false; return false;
} }
inline bool CPU_QueryAES() inline bool CPU_QueryAES()
{ {
-#if defined(__ANDROID__) && defined(__aarch64__) +#ifndef __TERMUX__
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_AES) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_AES) != 0))
-#elif defined(__ANDROID__) && defined(__aarch32__) @@ -868,11 +877,13 @@
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && #elif defined(__APPLE__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_AES) != 0)) return IsAppleMachineARMv8();
- return true; #endif
-#elif defined(__linux__) && defined(__aarch64__) +#endif
- if ((getauxval(AT_HWCAP) & HWCAP_AES) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_AES) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__)
- unsigned int device, version;
- GetAppleMachineInfo(device, version);
- return IsAppleMachineARMv8(device, version);
-#endif
return false; return false;
} }
inline bool CPU_QuerySHA1() inline bool CPU_QuerySHA1()
{ {
-#if defined(__ANDROID__) && defined(__aarch64__) +#ifndef __TERMUX__
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SHA1) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SHA1) != 0))
-#elif defined(__ANDROID__) && defined(__aarch32__) @@ -890,11 +901,13 @@
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && #elif defined(__APPLE__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_SHA1) != 0)) return IsAppleMachineARMv8();
- return true; #endif
-#elif defined(__linux__) && defined(__aarch64__) +#endif
- if ((getauxval(AT_HWCAP) & HWCAP_SHA1) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_SHA1) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__)
- unsigned int device, version;
- GetAppleMachineInfo(device, version);
- return IsAppleMachineARMv8(device, version);
-#endif
return false; return false;
} }
inline bool CPU_QuerySHA2() inline bool CPU_QuerySHA256()
{ {
-#if defined(__ANDROID__) && defined(__aarch64__) +#ifndef __TERMUX__
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SHA2) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SHA2) != 0))
-#elif defined(__ANDROID__) && defined(__aarch32__) @@ -912,11 +925,13 @@
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && #elif defined(__APPLE__) && defined(__aarch64__)
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_SHA2) != 0)) return IsAppleMachineARMv8();
- return true; #endif
-#elif defined(__linux__) && defined(__aarch64__) +#endif
- if ((getauxval(AT_HWCAP) & HWCAP_SHA2) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_SHA2) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__)
- unsigned int device, version;
- GetAppleMachineInfo(device, version);
- return IsAppleMachineARMv8(device, version);
-#endif
return false; return false;
} }
inline bool CPU_QuerySHA512() inline bool CPU_QuerySHA512()
{ {
-// Some ARMv8.4 features are disabled at the moment +#ifndef __TERMUX__
-#if defined(__ANDROID__) && defined(__aarch64__) && 0 // Some ARMv8.4 features are disabled at the moment
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__) && 0
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SHA512) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; @@ -935,11 +950,13 @@
-#elif defined(__ANDROID__) && defined(__aarch32__) && 0 #elif defined(__APPLE__) && defined(__aarch64__) && 0
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && return false;
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_SHA512) != 0)) #endif
- return true; +#endif
-#elif defined(__linux__) && defined(__aarch64__)
- if ((getauxval(AT_HWCAP) & HWCAP_SHA512) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_SHA512) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__) && 0
- unsigned int device, version;
- GetAppleMachineInfo(device, version);
- return IsAppleMachineARMv84(device, version);
-#endif
return false; return false;
} }
inline bool CPU_QuerySHA3() inline bool CPU_QuerySHA3()
{ {
-// Some ARMv8.4 features are disabled at the moment +#ifndef __TERMUX__
-#if defined(__ANDROID__) && defined(__aarch64__) && 0 // Some ARMv8.4 features are disabled at the moment
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__) && 0
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SHA3) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; @@ -958,11 +975,13 @@
-#elif defined(__ANDROID__) && defined(__aarch32__) && 0 #elif defined(__APPLE__) && defined(__aarch64__) && 0
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && return false;
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_SHA3) != 0)) #endif
- return true; +#endif
-#elif defined(__linux__) && defined(__aarch64__)
- if ((getauxval(AT_HWCAP) & HWCAP_SHA3) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_SHA3) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__) && 0
- unsigned int device, version;
- GetAppleMachineInfo(device, version);
- return IsAppleMachineARMv84(device, version);
-#endif
return false; return false;
} }
inline bool CPU_QuerySM3() inline bool CPU_QuerySM3()
{ {
-// Some ARMv8.4 features are disabled at the moment +#ifndef __TERMUX__
-#if defined(__ANDROID__) && defined(__aarch64__) && 0 // Some ARMv8.4 features are disabled at the moment
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__) && 0
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SM3) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; @@ -981,11 +1000,13 @@
-#elif defined(__ANDROID__) && defined(__aarch32__) && 0 #elif defined(__APPLE__) && defined(__aarch64__) && 0
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && return false;
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_SM3) != 0)) #endif
- return true; +#endif
-#elif defined(__linux__) && defined(__aarch64__)
- if ((getauxval(AT_HWCAP) & HWCAP_SM3) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_SM3) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__) && 0
- unsigned int device, version;
- GetAppleMachineInfo(device, version);
- return IsAppleMachineARMv84(device, version);
-#endif
return false; return false;
} }
inline bool CPU_QuerySM4() inline bool CPU_QuerySM4()
{ {
-// Some ARMv8.4 features are disabled at the moment +#ifndef __TERMUX__
-#if defined(__ANDROID__) && defined(__aarch64__) && 0 // Some ARMv8.4 features are disabled at the moment
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) && #if defined(__ANDROID__) && defined(__aarch64__) && 0
- ((android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_SM4) != 0)) if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM64) != 0) &&
- return true; @@ -1004,6 +1025,7 @@
-#elif defined(__ANDROID__) && defined(__aarch32__) && 0 #elif defined(__APPLE__) && defined(__aarch64__) && 0
- if (((android_getCpuFamily() & ANDROID_CPU_FAMILY_ARM) != 0) && return false;
- ((android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_SM4) != 0)) #endif
- return true; +#endif
-#elif defined(__linux__) && defined(__aarch64__)
- if ((getauxval(AT_HWCAP) & HWCAP_SM4) != 0)
- return true;
-#elif defined(__linux__) && defined(__aarch32__)
- if ((getauxval(AT_HWCAP2) & HWCAP2_SM4) != 0)
- return true;
-#elif defined(__APPLE__) && defined(__aarch64__) && 0
- unsigned int device, version;
- GetAppleMachineInfo(device, version);
- return IsAppleMachineARMv84(device, version);
-#endif
return false; return false;
} }