2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef __included_crc32_h__
17 #define __included_crc32_h__
19 #include <vppinfra/clib.h>
22 #define clib_crc32c_uses_intrinsics
23 #include <x86intrin.h>
24 static_always_inline u32
25 clib_crc32c_u8 (u32 last, u8 data)
27 return _mm_crc32_u8 (last, data);
30 static_always_inline u32
31 clib_crc32c_u16 (u32 last, u16 data)
33 return _mm_crc32_u16 (last, data);
36 static_always_inline u32
37 clib_crc32c_u32 (u32 last, u32 data)
39 return _mm_crc32_u32 (last, data);
42 static_always_inline u32
43 clib_crc32c_u64 (u32 last, u64 data)
45 return _mm_crc32_u64 (last, data);
49 #if __ARM_FEATURE_CRC32
50 #define clib_crc32c_uses_intrinsics
52 static_always_inline u32
53 clib_crc32c_u8 (u32 last, u8 data)
55 return __crc32cd (last, data);
58 static_always_inline u32
59 clib_crc32c_u16 (u32 last, u16 data)
61 return __crc32ch (last, data);
64 static_always_inline u32
65 clib_crc32c_u32 (u32 last, u32 data)
67 return __crc32cw (last, data);
70 static_always_inline u32
71 clib_crc32c_u64 (u32 last, u64 data)
73 return __crc32cd (last, data);
77 #ifdef clib_crc32c_uses_intrinsics
78 static_always_inline u32
79 clib_crc32c_with_init (u8 *s, int len, u32 last)
81 for (; len >= 8; len -= 8, s += 8)
82 last = clib_crc32c_u64 (last, *((u64u *) s));
84 for (; len >= 4; len -= 4, s += 4)
85 last = clib_crc32c_u32 (last, *((u32u *) s));
87 for (; len >= 2; len -= 2, s += 2)
88 last = clib_crc32c_u16 (last, *((u16u *) s));
90 for (; len >= 1; len -= 1, s += 1)
91 last = clib_crc32c_u8 (last, *((u8 *) s));
96 static_always_inline u32
97 clib_crc32c (u8 *s, int len)
99 return clib_crc32c_with_init (s, len, 0);
103 #endif /* __included_crc32_h__ */
106 * fd.io coding-style-patch-verification: ON
109 * eval: (c-set-style "gnu")