aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/lib
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 /arch/x86/lib
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
Diffstat (limited to 'arch/x86/lib')
-rw-r--r--arch/x86/lib/hash.c22
1 files changed, 13 insertions, 9 deletions
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;