Skip to content

Commit d9fcca4

Browse files
committed
Merge branch 'x86-hash-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 hashing changes from Ingo Molnar: "Small fixes and cleanups to the librarized arch_fast_hash() methods, used by the net/openvswitch code" * 'x86-hash-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86, hash: Simplify switch, add __init annotation x86, hash: Swap arguments passed to crc32_u32() x86, hash: Fix build failure with older binutils
2 parents 7cc3afd + 7a5917e commit d9fcca4

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

arch/x86/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTI
152152

153153
# does binutils support specific instructions?
154154
asinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1)
155+
asinstr += $(call as-instr,crc32l %eax$(comma)%eax,-DCONFIG_AS_CRC32=1)
155156
avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
156157
avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
157158

arch/x86/lib/hash.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@
3232
*/
3333

3434
#include <linux/hash.h>
35+
#include <linux/init.h>
3536

3637
#include <asm/processor.h>
3738
#include <asm/cpufeature.h>
3839
#include <asm/hash.h>
3940

4041
static inline u32 crc32_u32(u32 crc, u32 val)
4142
{
43+
#ifdef CONFIG_AS_CRC32
4244
asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val));
45+
#else
46+
asm (".byte 0xf2, 0x0f, 0x38, 0xf1, 0xc1" : "+a" (crc) : "c" (val));
47+
#endif
4348
return crc;
4449
}
4550

@@ -49,19 +54,18 @@ static u32 intel_crc4_2_hash(const void *data, u32 len, u32 seed)
4954
u32 i, tmp = 0;
5055

5156
for (i = 0; i < len / 4; i++)
52-
seed = crc32_u32(*p32++, seed);
57+
seed = crc32_u32(seed, *p32++);
5358

54-
switch (3 - (len & 0x03)) {
55-
case 0:
59+
switch (len & 3) {
60+
case 3:
5661
tmp |= *((const u8 *) p32 + 2) << 16;
5762
/* fallthrough */
58-
case 1:
63+
case 2:
5964
tmp |= *((const u8 *) p32 + 1) << 8;
6065
/* fallthrough */
61-
case 2:
66+
case 1:
6267
tmp |= *((const u8 *) p32);
63-
seed = crc32_u32(tmp, seed);
64-
default:
68+
seed = crc32_u32(seed, tmp);
6569
break;
6670
}
6771

@@ -74,12 +78,12 @@ static u32 intel_crc4_2_hash2(const u32 *data, u32 len, u32 seed)
7478
u32 i;
7579

7680
for (i = 0; i < len; i++)
77-
seed = crc32_u32(*p32++, seed);
81+
seed = crc32_u32(seed, *p32++);
7882

7983
return seed;
8084
}
8185

82-
void setup_arch_fast_hash(struct fast_hash_ops *ops)
86+
void __init setup_arch_fast_hash(struct fast_hash_ops *ops)
8387
{
8488
if (cpu_has_xmm4_2) {
8589
ops->hash = intel_crc4_2_hash;

0 commit comments

Comments
 (0)