Add crc32c inline function, allows compilation on 32-bit systems

32-bit code still can use crc32c instructions, but it operates
on 32 registers

Change-Id: I9bb6b0b59635d6ea6a753584676ebcf59c8f6584
Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:
Damjan Marion
2017-04-26 13:05:05 +02:00
committed by Dave Barach
parent 4fb27eed7e
commit 0f68c79a9d
7 changed files with 67 additions and 19 deletions

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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 \

View File

@ -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);

View File

@ -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

58
src/vppinfra/crc32.h Normal file
View File

@ -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:
*/