Apple devices do not support CRC32 instructions. Don't believe Clang's lies.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2322033002
CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot
Review-Url: https://codereview.chromium.org/2322033002
diff --git a/include/core/SkPreConfig.h b/include/core/SkPreConfig.h
index f241bab..b165ae1 100644
--- a/include/core/SkPreConfig.h
+++ b/include/core/SkPreConfig.h
@@ -193,6 +193,12 @@
#define SK_ARM_HAS_NEON
#endif
+// Really this __APPLE__ check shouldn't be necessary, but it seems that Apple's Clang defines
+// __ARM_FEATURE_CRC32 for -arch arm64, even though their chips don't support those instructions!
+#if defined(__ARM_FEATURE_CRC32) && !defined(__APPLE__)
+ #define SK_ARM_HAS_CRC32
+#endif
+
//////////////////////////////////////////////////////////////////////
#if !defined(SKIA_IMPLEMENTATION)
diff --git a/src/core/SkCpu.h b/src/core/SkCpu.h
index 4fba1d4..4dbe065 100644
--- a/src/core/SkCpu.h
+++ b/src/core/SkCpu.h
@@ -80,7 +80,7 @@
features |= NEON|NEON_FMA|VFP_FP16;
#endif
- #if defined(__ARM_FEATURE_CRC32)
+ #if defined(SK_ARM_HAS_CRC32)
features |= CRC32;
#endif
diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp
index 879eefc..9ecad15 100644
--- a/src/core/SkOpts.cpp
+++ b/src/core/SkOpts.cpp
@@ -11,7 +11,7 @@
#include "SkOpts.h"
#if defined(SK_ARM_HAS_NEON)
- #if defined(__ARM_FEATURE_CRC32)
+ #if defined(SK_ARM_HAS_CRC32)
#define SK_OPTS_NS neon_and_crc32
#else
#define SK_OPTS_NS neon
diff --git a/src/opts/SkChecksum_opts.h b/src/opts/SkChecksum_opts.h
index 4bcd9b1..3e1acf0 100644
--- a/src/opts/SkChecksum_opts.h
+++ b/src/opts/SkChecksum_opts.h
@@ -13,7 +13,7 @@
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42
#include <immintrin.h>
-#elif defined(SK_CPU_ARM64) && defined(__ARM_FEATURE_CRC32)
+#elif defined(SK_CPU_ARM64) && defined(SK_ARM_HAS_CRC32)
#include <arm_acle.h>
#endif
@@ -127,7 +127,7 @@
return hash;
}
-#elif defined(SK_CPU_ARM64) && defined(__ARM_FEATURE_CRC32)
+#elif defined(SK_CPU_ARM64) && defined(SK_ARM_HAS_CRC32)
static uint32_t hash_fn(const void* vdata, size_t bytes, uint32_t hash) {
auto data = (const uint8_t*)vdata;
if (bytes >= 24) {