summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/acl/bihash_40_8.h9
-rw-r--r--src/plugins/lb/lbhash.h2
-rw-r--r--src/vnet/bfd/bfd_main.c2
-rw-r--r--src/vppinfra.am1
-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
7 files changed, 67 insertions, 19 deletions
diff --git a/src/plugins/acl/bihash_40_8.h b/src/plugins/acl/bihash_40_8.h
index ba3dfbea..1dfb6a1e 100644
--- a/src/plugins/acl/bihash_40_8.h
+++ b/src/plugins/acl/bihash_40_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,13 +45,7 @@ static inline u64
clib_bihash_hash_40_8 (const clib_bihash_kv_40_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]);
- value = _mm_crc32_u64 (value, v->key[3]);
- value = _mm_crc32_u64 (value, v->key[4]);
- return value;
+ return clib_crc32c ((u8 *) v->key, 40);
#else
u64 tmp = v->key[0] ^ v->key[1] ^ v->key[2] ^ v->key[3] ^ v->key[4];
return clib_xxhash (tmp);
diff --git a/src/plugins/lb/lbhash.h b/src/plugins/lb/lbhash.h
index ca3cc143..c514fb57 100644
--- a/src/plugins/lb/lbhash.h
+++ b/src/plugins/lb/lbhash.h
@@ -101,7 +101,7 @@ void lb_hash_free(lb_hash_t *h)
vec_free(mem);
}
-#if __SSE4_2__
+#if __SSE4_2__ && !defined (__i386__)
static_always_inline
u32 lb_hash_hash(u64 k0, u64 k1, u64 k2, u64 k3, u64 k4)
{
diff --git a/src/vnet/bfd/bfd_main.c b/src/vnet/bfd/bfd_main.c
index 66b31ce5..b58a5132 100644
--- a/src/vnet/bfd/bfd_main.c
+++ b/src/vnet/bfd/bfd_main.c
@@ -39,7 +39,7 @@ static u64
bfd_calc_echo_checksum (u32 discriminator, u64 expire_time, u32 secret)
{
u64 checksum = 0;
-#if __SSE4_2__
+#if __SSE4_2__ && !defined (__i386__)
checksum = _mm_crc32_u64 (0, discriminator);
checksum = _mm_crc32_u64 (checksum, expire_time);
checksum = _mm_crc32_u64 (checksum, secret);
diff --git a/src/vppinfra.am b/src/vppinfra.am
index fed1981e..3939d3ce 100644
--- a/src/vppinfra.am
+++ b/src/vppinfra.am
@@ -168,6 +168,7 @@ nobase_include_HEADERS = \
vppinfra/cache.h \
vppinfra/clib.h \
vppinfra/cpu.h \
+ vppinfra/crc32.h \
vppinfra/dlist.h \
vppinfra/elf.h \
vppinfra/elf_clib.h \
diff --git a/src/vppinfra/bihash_24_8.h b/src/vppinfra/bihash_24_8.h
index 353f06bf..655dab80 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 d70da596..b5c17461 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 00000000..abb2953f
--- /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:
+ */