aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-03-31 15:27:32 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-03-31 15:27:32 -0400
commitd9fcca40eba3266c1c8b6d9d7ab163861ad23b66 (patch)
tree7d69afe258fa57a844b293b4c84c8369ae15b15a
parent7cc3afdf43ffb703db831292f3816d909fd44767 (diff)
parent7a5917e9787dd73284f04e35c3cfdb39a67bf0d5 (diff)
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
-rw-r--r--arch/x86/Makefile1
-rw-r--r--arch/x86/lib/hash.c22
2 files changed, 14 insertions, 9 deletions
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index a414b1471ffc..3b9348a0c1a4 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -152,6 +152,7 @@ cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTI
152 152
153# does binutils support specific instructions? 153# does binutils support specific instructions?
154asinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1) 154asinstr := $(call as-instr,fxsaveq (%rax),-DCONFIG_AS_FXSAVEQ=1)
155asinstr += $(call as-instr,crc32l %eax$(comma)%eax,-DCONFIG_AS_CRC32=1)
155avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1) 156avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
156avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1) 157avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
157 158
diff --git a/arch/x86/lib/hash.c b/arch/x86/lib/hash.c
index 3056702e81fb..ff4fa51a5b1f 100644
--- a/arch/x86/lib/hash.c
+++ b/arch/x86/lib/hash.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/hash.h> 34#include <linux/hash.h>
35#include <linux/init.h>
35 36
36#include <asm/processor.h> 37#include <asm/processor.h>
37#include <asm/cpufeature.h> 38#include <asm/cpufeature.h>
@@ -39,7 +40,11 @@
39 40
40static inline u32 crc32_u32(u32 crc, u32 val) 41static inline u32 crc32_u32(u32 crc, u32 val)
41{ 42{
43#ifdef CONFIG_AS_CRC32
42 asm ("crc32l %1,%0\n" : "+r" (crc) : "rm" (val)); 44 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
43 return crc; 48 return crc;
44} 49}
45 50
@@ -49,19 +54,18 @@ static u32 intel_crc4_2_hash(const void *data, u32 len, u32 seed)
49 u32 i, tmp = 0; 54 u32 i, tmp = 0;
50 55
51 for (i = 0; i < len / 4; i++) 56 for (i = 0; i < len / 4; i++)
52 seed = crc32_u32(*p32++, seed); 57 seed = crc32_u32(seed, *p32++);
53 58
54 switch (3 - (len & 0x03)) { 59 switch (len & 3) {
55 case 0: 60 case 3:
56 tmp |= *((const u8 *) p32 + 2) << 16; 61 tmp |= *((const u8 *) p32 + 2) << 16;
57 /* fallthrough */ 62 /* fallthrough */
58 case 1: 63 case 2:
59 tmp |= *((const u8 *) p32 + 1) << 8; 64 tmp |= *((const u8 *) p32 + 1) << 8;
60 /* fallthrough */ 65 /* fallthrough */
61 case 2: 66 case 1:
62 tmp |= *((const u8 *) p32); 67 tmp |= *((const u8 *) p32);
63 seed = crc32_u32(tmp, seed); 68 seed = crc32_u32(seed, tmp);
64 default:
65 break; 69 break;
66 } 70 }
67 71
@@ -74,12 +78,12 @@ static u32 intel_crc4_2_hash2(const u32 *data, u32 len, u32 seed)
74 u32 i; 78 u32 i;
75 79
76 for (i = 0; i < len; i++) 80 for (i = 0; i < len; i++)
77 seed = crc32_u32(*p32++, seed); 81 seed = crc32_u32(seed, *p32++);
78 82
79 return seed; 83 return seed;
80} 84}
81 85
82void setup_arch_fast_hash(struct fast_hash_ops *ops) 86void __init setup_arch_fast_hash(struct fast_hash_ops *ops)
83{ 87{
84 if (cpu_has_xmm4_2) { 88 if (cpu_has_xmm4_2) {
85 ops->hash = intel_crc4_2_hash; 89 ops->hash = intel_crc4_2_hash;