Harvey Harrison | 5d30a68 | 2009-01-06 14:56:28 -0800 | [diff] [blame] | 1 | #ifndef _ASM_X86_SWAB_H |
| 2 | #define _ASM_X86_SWAB_H |
| 3 | |
Jaswinder Singh Rajput | 7cff360 | 2009-01-30 22:57:38 +0530 | [diff] [blame] | 4 | #include <linux/types.h> |
Harvey Harrison | 5d30a68 | 2009-01-06 14:56:28 -0800 | [diff] [blame] | 5 | #include <linux/compiler.h> |
| 6 | |
| 7 | static inline __attribute_const__ __u32 __arch_swab32(__u32 val) |
| 8 | { |
H. Peter Anvin | e5bb8ad | 2012-11-28 11:50:26 -0800 | [diff] [blame] | 9 | asm("bswapl %0" : "=r" (val) : "0" (val)); |
Harvey Harrison | 5d30a68 | 2009-01-06 14:56:28 -0800 | [diff] [blame] | 10 | return val; |
| 11 | } |
| 12 | #define __arch_swab32 __arch_swab32 |
| 13 | |
| 14 | static inline __attribute_const__ __u64 __arch_swab64(__u64 val) |
| 15 | { |
| 16 | #ifdef __i386__ |
| 17 | union { |
| 18 | struct { |
| 19 | __u32 a; |
| 20 | __u32 b; |
| 21 | } s; |
| 22 | __u64 u; |
| 23 | } v; |
| 24 | v.u = val; |
Harvey Harrison | 5d30a68 | 2009-01-06 14:56:28 -0800 | [diff] [blame] | 25 | asm("bswapl %0 ; bswapl %1 ; xchgl %0,%1" |
| 26 | : "=r" (v.s.a), "=r" (v.s.b) |
| 27 | : "0" (v.s.a), "1" (v.s.b)); |
Harvey Harrison | 5d30a68 | 2009-01-06 14:56:28 -0800 | [diff] [blame] | 28 | return v.u; |
| 29 | #else /* __i386__ */ |
H. Peter Anvin | e5bb8ad | 2012-11-28 11:50:26 -0800 | [diff] [blame] | 30 | asm("bswapq %0" : "=r" (val) : "0" (val)); |
Harvey Harrison | 5d30a68 | 2009-01-06 14:56:28 -0800 | [diff] [blame] | 31 | return val; |
| 32 | #endif |
| 33 | } |
| 34 | #define __arch_swab64 __arch_swab64 |
| 35 | |
| 36 | #endif /* _ASM_X86_SWAB_H */ |