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