1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015 Cavium, Inc
5 #ifndef _RTE_CRC_ARM64_H_
6 #define _RTE_CRC_ARM64_H_
19 #include <rte_cpuflags.h>
20 #include <rte_branch_prediction.h>
21 #include <rte_common.h>
23 static inline uint32_t
24 crc32c_arm64_u8(uint8_t data, uint32_t init_val)
27 "crc32cb %w[crc], %w[crc], %w[value]"
28 : [crc] "+r" (init_val)
29 : [value] "r" (data));
33 static inline uint32_t
34 crc32c_arm64_u16(uint16_t data, uint32_t init_val)
37 "crc32ch %w[crc], %w[crc], %w[value]"
38 : [crc] "+r" (init_val)
39 : [value] "r" (data));
43 static inline uint32_t
44 crc32c_arm64_u32(uint32_t data, uint32_t init_val)
47 "crc32cw %w[crc], %w[crc], %w[value]"
48 : [crc] "+r" (init_val)
49 : [value] "r" (data));
53 static inline uint32_t
54 crc32c_arm64_u64(uint64_t data, uint32_t init_val)
57 "crc32cx %w[crc], %w[crc], %x[value]"
58 : [crc] "+r" (init_val)
59 : [value] "r" (data));
64 * Allow or disallow use of arm64 SIMD instrinsics for CRC32 hash
68 * An OR of following flags:
69 * - (CRC32_SW) Don't use arm64 crc intrinsics
70 * - (CRC32_ARM64) Use ARMv8 CRC intrinsic if available
74 rte_hash_crc_set_alg(uint8_t alg)
78 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32))
89 /* Setting the best available algorithm */
90 RTE_INIT(rte_hash_crc_init_alg)
92 rte_hash_crc_set_alg(CRC32_ARM64);
96 * Use single crc32 instruction to perform a hash on a 1 byte value.
97 * Fall back to software crc32 implementation in case arm64 crc intrinsics is
101 * Data to perform hash on.
103 * Value to initialise hash generator.
105 * 32bit calculated hash value.
107 static inline uint32_t
108 rte_hash_crc_1byte(uint8_t data, uint32_t init_val)
110 if (likely(crc32_alg & CRC32_ARM64))
111 return crc32c_arm64_u8(data, init_val);
113 return crc32c_1byte(data, init_val);
117 * Use single crc32 instruction to perform a hash on a 2 bytes value.
118 * Fall back to software crc32 implementation in case arm64 crc intrinsics is
122 * Data to perform hash on.
124 * Value to initialise hash generator.
126 * 32bit calculated hash value.
128 static inline uint32_t
129 rte_hash_crc_2byte(uint16_t data, uint32_t init_val)
131 if (likely(crc32_alg & CRC32_ARM64))
132 return crc32c_arm64_u16(data, init_val);
134 return crc32c_2bytes(data, init_val);
138 * Use single crc32 instruction to perform a hash on a 4 byte value.
139 * Fall back to software crc32 implementation in case arm64 crc intrinsics is
143 * Data to perform hash on.
145 * Value to initialise hash generator.
147 * 32bit calculated hash value.
149 static inline uint32_t
150 rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
152 if (likely(crc32_alg & CRC32_ARM64))
153 return crc32c_arm64_u32(data, init_val);
155 return crc32c_1word(data, init_val);
159 * Use single crc32 instruction to perform a hash on a 8 byte value.
160 * Fall back to software crc32 implementation in case arm64 crc intrinsics is
164 * Data to perform hash on.
166 * Value to initialise hash generator.
168 * 32bit calculated hash value.
170 static inline uint32_t
171 rte_hash_crc_8byte(uint64_t data, uint32_t init_val)
173 if (likely(crc32_alg == CRC32_ARM64))
174 return crc32c_arm64_u64(data, init_val);
176 return crc32c_2words(data, init_val);
183 #endif /* _RTE_CRC_ARM64_H_ */