xref: /openbmc/linux/arch/x86/include/uapi/asm/swab.h (revision eb3fcf00)
1 #ifndef _ASM_X86_SWAB_H
2 #define _ASM_X86_SWAB_H
3 
4 #include <linux/types.h>
5 #include <linux/compiler.h>
6 
7 static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
8 {
9 	asm("bswapl %0" : "=r" (val) : "0" (val));
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;
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));
28 	return v.u;
29 #else /* __i386__ */
30 	asm("bswapq %0" : "=r" (val) : "0" (val));
31 	return val;
32 #endif
33 }
34 #define __arch_swab64 __arch_swab64
35 
36 #endif /* _ASM_X86_SWAB_H */
37