4 * Copyright(c) 2015 Cavium networks. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
17 * * Neither the name of Cavium networks 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.
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.
34 #ifndef _RTE_CRC_ARM64_H_
35 #define _RTE_CRC_ARM64_H_
48 #include <rte_cpuflags.h>
49 #include <rte_branch_prediction.h>
50 #include <rte_common.h>
52 static inline uint32_t
53 crc32c_arm64_u32(uint32_t data, uint32_t init_val)
55 asm(".arch armv8-a+crc");
57 "crc32cw %w[crc], %w[crc], %w[value]"
58 : [crc] "+r" (init_val)
59 : [value] "r" (data));
63 static inline uint32_t
64 crc32c_arm64_u64(uint64_t data, uint32_t init_val)
66 asm(".arch armv8-a+crc");
68 "crc32cx %w[crc], %w[crc], %x[value]"
69 : [crc] "+r" (init_val)
70 : [value] "r" (data));
75 * Allow or disallow use of arm64 SIMD instrinsics for CRC32 hash
79 * An OR of following flags:
80 * - (CRC32_SW) Don't use arm64 crc intrinsics
81 * - (CRC32_ARM64) Use ARMv8 CRC intrinsic if available
85 rte_hash_crc_set_alg(uint8_t alg)
89 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32))
98 /* Setting the best available algorithm */
99 static inline void __attribute__((constructor))
100 rte_hash_crc_init_alg(void)
102 rte_hash_crc_set_alg(CRC32_ARM64);
106 * Use single crc32 instruction to perform a hash on a 4 byte value.
107 * Fall back to software crc32 implementation in case arm64 crc intrinsics is
111 * Data to perform hash on.
113 * Value to initialise hash generator.
115 * 32bit calculated hash value.
117 static inline uint32_t
118 rte_hash_crc_4byte(uint32_t data, uint32_t init_val)
120 if (likely(crc32_alg & CRC32_ARM64))
121 return crc32c_arm64_u32(data, init_val);
123 return crc32c_1word(data, init_val);
127 * Use single crc32 instruction to perform a hash on a 8 byte value.
128 * Fall back to software crc32 implementation in case arm64 crc intrinsics is
132 * Data to perform hash on.
134 * Value to initialise hash generator.
136 * 32bit calculated hash value.
138 static inline uint32_t
139 rte_hash_crc_8byte(uint64_t data, uint32_t init_val)
141 if (likely(crc32_alg == CRC32_ARM64))
142 return crc32c_arm64_u64(data, init_val);
144 return crc32c_2words(data, init_val);
151 #endif /* _RTE_CRC_ARM64_H_ */