DPDK  17.11.10
rte_crc_arm64.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2015 Cavium, Inc. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * * Neither the name of Cavium, Inc nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef _RTE_CRC_ARM64_H_
35 #define _RTE_CRC_ARM64_H_
36 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 #include <stdint.h>
48 #include <rte_cpuflags.h>
49 #include <rte_branch_prediction.h>
50 #include <rte_common.h>
51 
52 static inline uint32_t
53 crc32c_arm64_u8(uint8_t data, uint32_t init_val)
54 {
55  __asm__ volatile(
56  "crc32cb %w[crc], %w[crc], %w[value]"
57  : [crc] "+r" (init_val)
58  : [value] "r" (data));
59  return init_val;
60 }
61 
62 static inline uint32_t
63 crc32c_arm64_u16(uint16_t data, uint32_t init_val)
64 {
65  __asm__ volatile(
66  "crc32ch %w[crc], %w[crc], %w[value]"
67  : [crc] "+r" (init_val)
68  : [value] "r" (data));
69  return init_val;
70 }
71 
72 static inline uint32_t
73 crc32c_arm64_u32(uint32_t data, uint32_t init_val)
74 {
75  __asm__ volatile(
76  "crc32cw %w[crc], %w[crc], %w[value]"
77  : [crc] "+r" (init_val)
78  : [value] "r" (data));
79  return init_val;
80 }
81 
82 static inline uint32_t
83 crc32c_arm64_u64(uint64_t data, uint32_t init_val)
84 {
85  __asm__ volatile(
86  "crc32cx %w[crc], %w[crc], %x[value]"
87  : [crc] "+r" (init_val)
88  : [value] "r" (data));
89  return init_val;
90 }
91 
102 static inline void
104 {
105  switch (alg) {
106  case CRC32_ARM64:
107  if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32))
108  alg = CRC32_SW;
109  /* fall-through */
110  case CRC32_SW:
111  crc32_alg = alg;
112  /* fall-through */
113  default:
114  break;
115  }
116 }
117 
118 /* Setting the best available algorithm */
119 RTE_INIT(rte_hash_crc_init_alg)
120 {
121  rte_hash_crc_set_alg(CRC32_ARM64);
122 }
123 
136 static inline uint32_t
137 rte_hash_crc_1byte(uint8_t data, uint32_t init_val)
138 {
139  if (likely(crc32_alg & CRC32_ARM64))
140  return crc32c_arm64_u8(data, init_val);
141 
142  return crc32c_1byte(data, init_val);
143 }
144 
157 static inline uint32_t
158 rte_hash_crc_2byte(uint16_t data, uint32_t init_val)
159 {
160  if (likely(crc32_alg & CRC32_ARM64))
161  return crc32c_arm64_u16(data, init_val);
162 
163  return crc32c_2bytes(data, init_val);
164 }
165 
178 static inline uint32_t
179 rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
180 {
181  if (likely(crc32_alg & CRC32_ARM64))
182  return crc32c_arm64_u32(data, init_val);
183 
184  return crc32c_1word(data, init_val);
185 }
186 
199 static inline uint32_t
200 rte_hash_crc_8byte(uint64_t data, uint32_t init_val)
201 {
202  if (likely(crc32_alg == CRC32_ARM64))
203  return crc32c_arm64_u64(data, init_val);
204 
205  return crc32c_2words(data, init_val);
206 }
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif /* _RTE_CRC_ARM64_H_ */
#define likely(x)
static uint32_t rte_hash_crc_1byte(uint8_t data, uint32_t init_val)
static void rte_hash_crc_set_alg(uint8_t alg)
#define RTE_INIT(func)
Definition: rte_common.h:121
static uint32_t rte_hash_crc_8byte(uint64_t data, uint32_t init_val)
static uint32_t rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
__extension__ int rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature)
static uint32_t rte_hash_crc_2byte(uint16_t data, uint32_t init_val)