Skip to content

Commit

Permalink
Fix: Detect armv8_crc32 programatically for Apple A9
Browse files Browse the repository at this point in the history
The Apple A9 supports Neon but does not support Arm's crc32 instruction.
This detection does not work on other platforms, however this feature is only used on Apple platforms anyway.
  • Loading branch information
rcelyte authored and spnda committed Sep 24, 2024
1 parent d64b21e commit 3e42d9f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/fastgltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ static_assert(std::string_view { SIMDJSON_TARGET_VERSION } == SIMDJSON_VERSION,
#elif defined(FASTGLTF_ENABLE_ARMV8_CRC)
// MSVC does not provide the arm crc32 intrinsics.
#include <arm_acle.h>
#ifdef __APPLE__
#include <sys/sysctl.h>
#endif
#endif

namespace fg = fastgltf;
Expand Down Expand Up @@ -224,6 +227,11 @@ namespace fastgltf {
#elif defined(FASTGLTF_ENABLE_ARMV8_CRC)
const auto& impls = simdjson::get_available_implementations();
if (const auto* neon = impls["arm64"]; neon != nullptr && neon->supported_by_runtime_system()) {
#ifdef __APPLE__
std::int64_t ret = 0;
std::size_t size = sizeof(ret);
if (sysctlbyname("hw.optional.armv8_crc32", &ret, &size, nullptr, 0) == 0 && ret == 1)
#endif
crcStringFunction = armv8_crc32c;
}
#endif
Expand Down

0 comments on commit 3e42d9f

Please sign in to comment.