Lower ARM architecture requirement for CRC32 instructions.

The changes ensure compatibility with compilers targeting ARMv7.
32-bit processors of architecture 8 and higher, or 64-bit processors running in 32-bit mode can have the CRC32 instructions.
With this change we will query the processor instead of the compiler architecture.
This commit is contained in:
2023-09-23 00:53:23 +01:00
parent c392dfa682
commit d4a607345e
4 changed files with 11 additions and 5 deletions

View File

@@ -48,7 +48,7 @@ AARU_EXPORT int AARU_CALL crc32_update(crc32_ctx* ctx, const uint8_t* data, uint
#endif #endif
#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM) #if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
#if __ARM_ARCH >= 8 #if __ARM_ARCH >= 7
if(have_arm_crc32()) if(have_arm_crc32())
{ {
ctx->crc = armv8_crc32_little(ctx->crc, data, len); ctx->crc = armv8_crc32_little(ctx->crc, data, len);

View File

@@ -30,9 +30,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#if(defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)) && __ARM_ARCH >= 8 #if(defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)) && __ARM_ARCH >= 7
#if defined(__MINGW32__) && !defined(__ARM_FEATURE_CRC32) #if !defined(__ARM_FEATURE_CRC32)
#define __ARM_FEATURE_CRC32 1 #define __ARM_FEATURE_CRC32 1
#endif #endif

6
simd.c
View File

@@ -198,6 +198,12 @@ int have_arm_crc32(void)
#elif defined(__APPLE__) #elif defined(__APPLE__)
return have_crc32_apple(); return have_crc32_apple();
#else #else
// Not defined in ARMv7 compilers, even if the CPU has the capability
#ifndef HWCAP2_CRC32
#define HWCAP2_CRC32 (1 << 4)
#endif
return getauxval(AT_HWCAP2) & HWCAP2_CRC32; return getauxval(AT_HWCAP2) & HWCAP2_CRC32;
#endif #endif
} }

4
simd.h
View File

@@ -92,7 +92,7 @@ AARU_EXPORT int have_arm_crypto(void);
#define TARGET_WITH_SIMD #define TARGET_WITH_SIMD
#else #else
#if __ARM_ARCH >= 8 #if (__ARM_ARCH >= 7 || defined (__ARM_ARCH_8A))
#ifdef __clang__ #ifdef __clang__
#define TARGET_ARMV8_WITH_CRC __attribute__((target("armv8-a,crc"))) #define TARGET_ARMV8_WITH_CRC __attribute__((target("armv8-a,crc")))
@@ -100,7 +100,7 @@ AARU_EXPORT int have_arm_crypto(void);
#define TARGET_ARMV8_WITH_CRC __attribute__((target("arch=armv8-a+crc"))) #define TARGET_ARMV8_WITH_CRC __attribute__((target("arch=armv8-a+crc")))
#endif #endif
#endif // __ARM_ARCH >= 8 #endif // __ARM_ARCH_7A__
#ifdef __clang__ #ifdef __clang__
#define TARGET_WITH_CRYPTO __attribute__((target("armv8-a,crypto"))) #define TARGET_WITH_CRYPTO __attribute__((target("armv8-a,crypto")))