summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/bihash_24_8.h7
-rw-r--r--src/vppinfra/bihash_8_8.h7
-rw-r--r--src/vppinfra/crc32.h58
3 files changed, 62 insertions, 10 deletions
diff --git a/src/vppinfra/bihash_24_8.h b/src/vppinfra/bihash_24_8.h
index 353f06bf11f..655dab8015f 100644
--- a/src/vppinfra/bihash_24_8.h
+++ b/src/vppinfra/bihash_24_8.h
@@ -24,6 +24,7 @@
#include <vppinfra/format.h>
#include <vppinfra/pool.h>
#include <vppinfra/xxhash.h>
+#include <vppinfra/crc32.h>
typedef struct
{
@@ -44,11 +45,7 @@ static inline u64
clib_bihash_hash_24_8 (const clib_bihash_kv_24_8_t * v)
{
#if __SSE4_2__
- u32 value = 0;
- value = _mm_crc32_u64 (value, v->key[0]);
- value = _mm_crc32_u64 (value, v->key[1]);
- value = _mm_crc32_u64 (value, v->key[2]);
- return value;
+ return clib_crc32c ((u8 *) v->key, 24);
#else
u64 tmp = v->key[0] ^ v->key[1] ^ v->key[2];
return clib_xxhash (tmp);
diff --git a/src/vppinfra/bihash_8_8.h b/src/vppinfra/bihash_8_8.h
index d70da5966e2..b5c17461245 100644
--- a/src/vppinfra/bihash_8_8.h
+++ b/src/vppinfra/bihash_8_8.h
@@ -24,10 +24,7 @@
#include <vppinfra/format.h>
#include <vppinfra/pool.h>
#include <vppinfra/xxhash.h>
-
-#if __SSE4_2__
-#include <x86intrin.h>
-#endif
+#include <vppinfra/crc32.h>
/** 8 octet key, 8 octet key value pair */
typedef struct
@@ -55,7 +52,7 @@ clib_bihash_hash_8_8 (clib_bihash_kv_8_8_t * v)
{
/* Note: to torture-test linear scan, make this fn return a constant */
#if __SSE4_2__
- return _mm_crc32_u64 (0, v->key);
+ return clib_crc32c ((u8 *) & v->key, 8);
#else
return clib_xxhash (v->key);
#endif
diff --git a/src/vppinfra/crc32.h b/src/vppinfra/crc32.h
new file mode 100644
index 00000000000..abb2953fb4d
--- /dev/null
+++ b/src/vppinfra/crc32.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __included_crc32_h__
+#define __included_crc32_h__
+
+#if __SSE4_2__
+#include <x86intrin.h>
+
+static_always_inline u32
+clib_crc32c (u8 * s, int len)
+{
+ u32 v = 0;
+
+#if __x86_64__
+ for (; len >= 8; len -= 8, s += 8)
+ v = _mm_crc32_u64 (v, *((u64 *) s));
+#else
+ /* workaround weird GCC bug when using _mm_crc32_u32
+ which happens with -O2 optimization */
+ volatile ("":::"memory");
+#endif
+
+ for (; len >= 4; len -= 4, s += 4)
+ v = _mm_crc32_u32 (v, *((u32 *) s));
+
+ for (; len >= 2; len -= 2, s += 2)
+ v = _mm_crc32_u16 (v, *((u16 *) s));
+
+ for (; len >= 1; len -= 1, s += 1)
+ v = _mm_crc32_u8 (v, *((u16 *) s));
+
+ return v;
+}
+
+#endif
+
+#endif /* __included_crc32_h__ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */