blob: 7f235c7105c19713c0a22e2e2ea40ea5579895f0 [file] [log] [blame]
Harvey Harrison5d30a682009-01-06 14:56:28 -08001#ifndef _ASM_X86_SWAB_H
2#define _ASM_X86_SWAB_H
3
Jaswinder Singh Rajput7cff3602009-01-30 22:57:38 +05304#include <linux/types.h>
Harvey Harrison5d30a682009-01-06 14:56:28 -08005#include <linux/compiler.h>
6
7static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
8{
H. Peter Anvine5bb8ad2012-11-28 11:50:26 -08009 asm("bswapl %0" : "=r" (val) : "0" (val));
Harvey Harrison5d30a682009-01-06 14:56:28 -080010 return val;
11}
12#define __arch_swab32 __arch_swab32
13
14static 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 Harrison5d30a682009-01-06 14:56:28 -080025 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 Harrison5d30a682009-01-06 14:56:28 -080028 return v.u;
29#else /* __i386__ */
H. Peter Anvine5bb8ad2012-11-28 11:50:26 -080030 asm("bswapq %0" : "=r" (val) : "0" (val));
Harvey Harrison5d30a682009-01-06 14:56:28 -080031 return val;
32#endif
33}
34#define __arch_swab64 __arch_swab64
35
36#endif /* _ASM_X86_SWAB_H */