Skip to content

Commit

Permalink
Merge branch 'x86-hash-for-linus' of git://git.kernel.org/pub/scm/lin…
Browse files Browse the repository at this point in the history
…ux/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
  • Loading branch information
torvalds committed Mar 31, 2014
2 parents 7cc3afd + 7a5917e commit d9fcca4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions arch/x86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTI

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

Expand Down
22 changes: 13 additions & 9 deletions arch/x86/lib/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@
*/

#include <linux/hash.h>
#include <linux/init.h>

#include <asm/processor.h>
#include <asm/cpufeature.h>
#include <asm/hash.h>

static inline u32 crc32_u32(u32 crc, u32 val)
{
#ifdef CONFIG_AS_CRC32
asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val));
#else
asm (".byte 0xf2, 0x0f, 0x38, 0xf1, 0xc1" : "+a" (crc) : "c" (val));
#endif
return crc;
}

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

for (i = 0; i < len / 4; i++)
seed = crc32_u32(*p32++, seed);
seed = crc32_u32(seed, *p32++);

switch (3 - (len & 0x03)) {
case 0:
switch (len & 3) {
case 3:
tmp |= *((const u8 *) p32 + 2) << 16;
/* fallthrough */
case 1:
case 2:
tmp |= *((const u8 *) p32 + 1) << 8;
/* fallthrough */
case 2:
case 1:
tmp |= *((const u8 *) p32);
seed = crc32_u32(tmp, seed);
default:
seed = crc32_u32(seed, tmp);
break;
}

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

for (i = 0; i < len; i++)
seed = crc32_u32(*p32++, seed);
seed = crc32_u32(seed, *p32++);

return seed;
}

void setup_arch_fast_hash(struct fast_hash_ops *ops)
void __init setup_arch_fast_hash(struct fast_hash_ops *ops)
{
if (cpu_has_xmm4_2) {
ops->hash = intel_crc4_2_hash;
Expand Down

0 comments on commit d9fcca4

Please sign in to comment.