diff options
author | Harvey Harrison <harvey.harrison@gmail.com> | 2009-01-06 17:56:28 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-06 21:10:27 -0500 |
commit | 5d30a683888c60b8f93bef3ddc139d1a91ca58f4 (patch) | |
tree | 4cd79bc83d2c97bc95a934b0251757d2170b0140 /arch/x86/include/asm/swab.h | |
parent | f4d2b14501bb7f9a3fa75c07ec0940068fadf728 (diff) |
x86: introduce asm/swab.h
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/x86/include/asm/swab.h')
-rw-r--r-- | arch/x86/include/asm/swab.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/arch/x86/include/asm/swab.h b/arch/x86/include/asm/swab.h new file mode 100644 index 000000000000..306d4178ffc9 --- /dev/null +++ b/arch/x86/include/asm/swab.h | |||
@@ -0,0 +1,61 @@ | |||
1 | #ifndef _ASM_X86_SWAB_H | ||
2 | #define _ASM_X86_SWAB_H | ||
3 | |||
4 | #include <asm/types.h> | ||
5 | #include <linux/compiler.h> | ||
6 | |||
7 | static inline __attribute_const__ __u32 __arch_swab32(__u32 val) | ||
8 | { | ||
9 | #ifdef __i386__ | ||
10 | # ifdef CONFIG_X86_BSWAP | ||
11 | asm("bswap %0" : "=r" (val) : "0" (val)); | ||
12 | # else | ||
13 | asm("xchgb %b0,%h0\n\t" /* swap lower bytes */ | ||
14 | "rorl $16,%0\n\t" /* swap words */ | ||
15 | "xchgb %b0,%h0" /* swap higher bytes */ | ||
16 | : "=q" (val) | ||
17 | : "0" (val)); | ||
18 | # endif | ||
19 | |||
20 | #else /* __i386__ */ | ||
21 | asm("bswapl %0" | ||
22 | : "=r" (val) | ||
23 | : "0" (val)); | ||
24 | #endif | ||
25 | return val; | ||
26 | } | ||
27 | #define __arch_swab32 __arch_swab32 | ||
28 | |||
29 | static inline __attribute_const__ __u64 __arch_swab64(__u64 val) | ||
30 | { | ||
31 | #ifdef __i386__ | ||
32 | union { | ||
33 | struct { | ||
34 | __u32 a; | ||
35 | __u32 b; | ||
36 | } s; | ||
37 | __u64 u; | ||
38 | } v; | ||
39 | v.u = val; | ||
40 | # ifdef CONFIG_X86_BSWAP | ||
41 | asm("bswapl %0 ; bswapl %1 ; xchgl %0,%1" | ||
42 | : "=r" (v.s.a), "=r" (v.s.b) | ||
43 | : "0" (v.s.a), "1" (v.s.b)); | ||
44 | # else | ||
45 | v.s.a = __arch_swab32(v.s.a); | ||
46 | v.s.b = __arch_swab32(v.s.b); | ||
47 | asm("xchgl %0,%1" | ||
48 | : "=r" (v.s.a), "=r" (v.s.b) | ||
49 | : "0" (v.s.a), "1" (v.s.b)); | ||
50 | # endif | ||
51 | return v.u; | ||
52 | #else /* __i386__ */ | ||
53 | asm("bswapq %0" | ||
54 | : "=r" (val) | ||
55 | : "0" (val)); | ||
56 | return val; | ||
57 | #endif | ||
58 | } | ||
59 | #define __arch_swab64 __arch_swab64 | ||
60 | |||
61 | #endif /* _ASM_X86_SWAB_H */ | ||