crc32c_arm64.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) 2018, Arm Limited and affiliates. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #ifndef UTIL_CRC32C_ARM64_H
  6. #define UTIL_CRC32C_ARM64_H
  7. #include <cinttypes>
  8. #include <cstddef>
  9. #if defined(__aarch64__) || defined(__AARCH64__)
  10. #ifdef __ARM_FEATURE_CRC32
  11. #define HAVE_ARM64_CRC
  12. #include <arm_acle.h>
  13. #define crc32c_u8(crc, v) __crc32cb(crc, v)
  14. #define crc32c_u16(crc, v) __crc32ch(crc, v)
  15. #define crc32c_u32(crc, v) __crc32cw(crc, v)
  16. #define crc32c_u64(crc, v) __crc32cd(crc, v)
  17. // clang-format off
  18. #define PREF4X64L1(buffer, PREF_OFFSET, ITR) \
  19. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  20. [c] "I"((PREF_OFFSET) + ((ITR) + 0) * 64)); \
  21. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  22. [c] "I"((PREF_OFFSET) + ((ITR) + 1) * 64)); \
  23. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  24. [c] "I"((PREF_OFFSET) + ((ITR) + 2) * 64)); \
  25. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  26. [c] "I"((PREF_OFFSET) + ((ITR) + 3) * 64));
  27. // clang-format on
  28. #define PREF1KL1(buffer, PREF_OFFSET) \
  29. PREF4X64L1(buffer, (PREF_OFFSET), 0) \
  30. PREF4X64L1(buffer, (PREF_OFFSET), 4) \
  31. PREF4X64L1(buffer, (PREF_OFFSET), 8) \
  32. PREF4X64L1(buffer, (PREF_OFFSET), 12)
  33. uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data, size_t len);
  34. uint32_t crc32c_runtime_check(void);
  35. bool crc32c_pmull_runtime_check(void);
  36. #ifdef __ARM_FEATURE_CRYPTO
  37. #define HAVE_ARM64_CRYPTO
  38. #include <arm_neon.h>
  39. #endif // __ARM_FEATURE_CRYPTO
  40. #endif // __ARM_FEATURE_CRC32
  41. #endif // defined(__aarch64__) || defined(__AARCH64__)
  42. #endif