blob: f110ad417df3e0121333cbb06564a492ef8be2c2 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_BYTEORDER_H
2#define _ASM_X86_BYTEORDER_H
Thomas Gleixneracbbbe92007-10-23 22:37:23 +02003
4#include <asm/types.h>
5#include <linux/compiler.h>
6
Harvey Harrisonad38dab2008-10-27 13:30:56 -07007#define __LITTLE_ENDIAN
Thomas Gleixneracbbbe92007-10-23 22:37:23 +02008
Harvey Harrisonad38dab2008-10-27 13:30:56 -07009static inline __attribute_const__ __u32 __arch_swab32(__u32 val)
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020010{
Harvey Harrisonad38dab2008-10-27 13:30:56 -070011#ifdef __i386__
12# ifdef CONFIG_X86_BSWAP
13 asm("bswap %0" : "=r" (val) : "0" (val));
14# else
Joe Perches34605092008-03-23 01:01:47 -070015 asm("xchgb %b0,%h0\n\t" /* swap lower bytes */
16 "rorl $16,%0\n\t" /* swap words */
17 "xchgb %b0,%h0" /* swap higher bytes */
Harvey Harrisonad38dab2008-10-27 13:30:56 -070018 : "=q" (val)
19 : "0" (val));
20# endif
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020021
Harvey Harrisonad38dab2008-10-27 13:30:56 -070022#else /* __i386__ */
23 asm("bswapl %0"
24 : "=r" (val)
25 : "0" (val));
26#endif
27 return val;
28}
29#define __arch_swab32 __arch_swab32
30
31static inline __attribute_const__ __u64 __arch_swab64(__u64 val)
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020032{
Harvey Harrisonad38dab2008-10-27 13:30:56 -070033#ifdef __i386__
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020034 union {
Joe Perches34605092008-03-23 01:01:47 -070035 struct {
36 __u32 a;
37 __u32 b;
38 } s;
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020039 __u64 u;
40 } v;
41 v.u = val;
Harvey Harrisonad38dab2008-10-27 13:30:56 -070042# ifdef CONFIG_X86_BSWAP
Joe Perches34605092008-03-23 01:01:47 -070043 asm("bswapl %0 ; bswapl %1 ; xchgl %0,%1"
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020044 : "=r" (v.s.a), "=r" (v.s.b)
45 : "0" (v.s.a), "1" (v.s.b));
Harvey Harrisonad38dab2008-10-27 13:30:56 -070046# else
47 v.s.a = __arch_swab32(v.s.a);
48 v.s.b = __arch_swab32(v.s.b);
Joe Perches34605092008-03-23 01:01:47 -070049 asm("xchgl %0,%1"
50 : "=r" (v.s.a), "=r" (v.s.b)
51 : "0" (v.s.a), "1" (v.s.b));
Harvey Harrisonad38dab2008-10-27 13:30:56 -070052# endif
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020053 return v.u;
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020054#else /* __i386__ */
Joe Perches34605092008-03-23 01:01:47 -070055 asm("bswapq %0"
Harvey Harrisonad38dab2008-10-27 13:30:56 -070056 : "=r" (val)
57 : "0" (val));
58 return val;
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020059#endif
Harvey Harrisonad38dab2008-10-27 13:30:56 -070060}
61#define __arch_swab64 __arch_swab64
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020062
Harvey Harrisonad38dab2008-10-27 13:30:56 -070063#include <linux/byteorder.h>
Thomas Gleixneracbbbe92007-10-23 22:37:23 +020064
H. Peter Anvin1965aae2008-10-22 22:26:29 -070065#endif /* _ASM_X86_BYTEORDER_H */