FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
crc32.h
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #ifndef __included_crc32_h__
17 #define __included_crc32_h__
18 
19 #include <vppinfra/clib.h>
20 
21 #if __SSE4_2__
22 #define clib_crc32c_uses_intrinsics
23 #include <x86intrin.h>
24 
26 clib_crc32c (u8 * s, int len)
27 {
28  u32 v = 0;
29 
30 #if __x86_64__
31  for (; len >= 8; len -= 8, s += 8)
32  v = _mm_crc32_u64 (v, *((u64 *) s));
33 #else
34  /* workaround weird GCC bug when using _mm_crc32_u32
35  which happens with -O2 optimization */
36  volatile ("":::"memory");
37 #endif
38 
39  for (; len >= 4; len -= 4, s += 4)
40  v = _mm_crc32_u32 (v, *((u32 *) s));
41 
42  for (; len >= 2; len -= 2, s += 2)
43  v = _mm_crc32_u16 (v, *((u16 *) s));
44 
45  for (; len >= 1; len -= 1, s += 1)
46  v = _mm_crc32_u8 (v, *((u16 *) s));
47 
48  return v;
49 }
50 
51 #elif __ARM_FEATURE_CRC32
52 #define clib_crc32c_with_intrinsics
53 #include <arm_acle.h>
54 
56 clib_crc32c (u8 * s, int len)
57 {
58  u32 v = 0;
59 
60  for (; len >= 8; len -= 8, s += 8)
61  v = __crc32cd (v, *((u64 *) s));
62 
63  for (; len >= 4; len -= 4, s += 4)
64  v = __crc32cw (v, *((u32 *) s));
65 
66  for (; len >= 2; len -= 2, s += 2)
67  v = __crc32ch (v, *((u16 *) s));
68 
69  for (; len >= 1; len -= 1, s += 1)
70  v = __crc32cb (v, *((u8 *) s));
71 
72  return v;
73 }
74 
75 #endif
76 #endif /* __included_crc32_h__ */
77 
78 /*
79  * fd.io coding-style-patch-verification: ON
80  *
81  * Local Variables:
82  * eval: (c-set-style "gnu")
83  * End:
84  */
#define static_always_inline
Definition: clib.h:85
unsigned long u64
Definition: types.h:89
#define v
Definition: acl.c:320
unsigned int u32
Definition: types.h:88
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56