DPDK 22.11.6
rte_crc_arm64.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015 Cavium, Inc
3 */
4
5#ifndef _RTE_CRC_ARM64_H_
6#define _RTE_CRC_ARM64_H_
7
8static inline uint32_t
9crc32c_arm64_u8(uint8_t data, uint32_t init_val)
10{
11 __asm__ volatile(
12 "crc32cb %w[crc], %w[crc], %w[value]"
13 : [crc] "+r" (init_val)
14 : [value] "r" (data));
15 return init_val;
16}
17
18static inline uint32_t
19crc32c_arm64_u16(uint16_t data, uint32_t init_val)
20{
21 __asm__ volatile(
22 "crc32ch %w[crc], %w[crc], %w[value]"
23 : [crc] "+r" (init_val)
24 : [value] "r" (data));
25 return init_val;
26}
27
28static inline uint32_t
29crc32c_arm64_u32(uint32_t data, uint32_t init_val)
30{
31 __asm__ volatile(
32 "crc32cw %w[crc], %w[crc], %w[value]"
33 : [crc] "+r" (init_val)
34 : [value] "r" (data));
35 return init_val;
36}
37
38static inline uint32_t
39crc32c_arm64_u64(uint64_t data, uint32_t init_val)
40{
41 __asm__ volatile(
42 "crc32cx %w[crc], %w[crc], %x[value]"
43 : [crc] "+r" (init_val)
44 : [value] "r" (data));
45 return init_val;
46}
47
48/*
49 * Use single crc32 instruction to perform a hash on a byte value.
50 * Fall back to software crc32 implementation in case ARM CRC is
51 * not supported.
52 */
53static inline uint32_t
54rte_hash_crc_1byte(uint8_t data, uint32_t init_val)
55{
56 if (likely(crc32_alg & CRC32_ARM64))
57 return crc32c_arm64_u8(data, init_val);
58
59 return crc32c_1byte(data, init_val);
60}
61
62/*
63 * Use single crc32 instruction to perform a hash on a 2 bytes value.
64 * Fall back to software crc32 implementation in case ARM CRC is
65 * not supported.
66 */
67static inline uint32_t
68rte_hash_crc_2byte(uint16_t data, uint32_t init_val)
69{
70 if (likely(crc32_alg & CRC32_ARM64))
71 return crc32c_arm64_u16(data, init_val);
72
73 return crc32c_2bytes(data, init_val);
74}
75
76/*
77 * Use single crc32 instruction to perform a hash on a 4 byte value.
78 * Fall back to software crc32 implementation in case ARM CRC is
79 * not supported.
80 */
81static inline uint32_t
82rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
83{
84 if (likely(crc32_alg & CRC32_ARM64))
85 return crc32c_arm64_u32(data, init_val);
86
87 return crc32c_1word(data, init_val);
88}
89
90/*
91 * Use single crc32 instruction to perform a hash on a 8 byte value.
92 * Fall back to software crc32 implementation in case ARM CRC is
93 * not supported.
94 */
95static inline uint32_t
96rte_hash_crc_8byte(uint64_t data, uint32_t init_val)
97{
98 if (likely(crc32_alg & CRC32_ARM64))
99 return crc32c_arm64_u64(data, init_val);
100
101 return crc32c_2words(data, init_val);
102}
103
104#endif /* _RTE_CRC_ARM64_H_ */
#define likely(x)
static uint32_t rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
static uint32_t rte_hash_crc_1byte(uint8_t data, uint32_t init_val)
static uint32_t rte_hash_crc_2byte(uint16_t data, uint32_t init_val)
static uint32_t rte_hash_crc_8byte(uint64_t data, uint32_t init_val)