crc32c_arm64.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #if defined(__aarch64__) || defined(__AARCH64__)
  9. #ifdef __ARM_FEATURE_CRC32
  10. #define HAVE_ARM64_CRC
  11. #include <arm_acle.h>
  12. #define crc32c_u8(crc, v) __crc32cb(crc, v)
  13. #define crc32c_u16(crc, v) __crc32ch(crc, v)
  14. #define crc32c_u32(crc, v) __crc32cw(crc, v)
  15. #define crc32c_u64(crc, v) __crc32cd(crc, v)
  16. #define PREF4X64L1(buffer, PREF_OFFSET, ITR) \
  17. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  18. [c] "I"((PREF_OFFSET) + ((ITR) + 0) * 64)); \
  19. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  20. [c] "I"((PREF_OFFSET) + ((ITR) + 1) * 64)); \
  21. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  22. [c] "I"((PREF_OFFSET) + ((ITR) + 2) * 64)); \
  23. __asm__("PRFM PLDL1KEEP, [%x[v],%[c]]" ::[v] "r"(buffer), \
  24. [c] "I"((PREF_OFFSET) + ((ITR) + 3) * 64));
  25. #define PREF1KL1(buffer, PREF_OFFSET) \
  26. PREF4X64L1(buffer, (PREF_OFFSET), 0) \
  27. PREF4X64L1(buffer, (PREF_OFFSET), 4) \
  28. PREF4X64L1(buffer, (PREF_OFFSET), 8) \
  29. PREF4X64L1(buffer, (PREF_OFFSET), 12)
  30. extern uint32_t crc32c_arm64(uint32_t crc, unsigned char const *data, unsigned len);
  31. extern uint32_t crc32c_runtime_check(void);
  32. #ifdef __ARM_FEATURE_CRYPTO
  33. #define HAVE_ARM64_CRYPTO
  34. #include <arm_neon.h>
  35. #endif // __ARM_FEATURE_CRYPTO
  36. #endif // __ARM_FEATURE_CRC32
  37. #endif // defined(__aarch64__) || defined(__AARCH64__)
  38. #endif