2008-10-23 09:26:29 +04:00
# ifndef _ASM_X86_BYTEORDER_H
# define _ASM_X86_BYTEORDER_H
2007-10-24 00:37:23 +04:00
# include <asm/types.h>
# include <linux/compiler.h>
2008-10-27 23:30:56 +03:00
# define __LITTLE_ENDIAN
2007-10-24 00:37:23 +04:00
2008-10-27 23:30:56 +03:00
static inline __attribute_const__ __u32 __arch_swab32 ( __u32 val )
2007-10-24 00:37:23 +04:00
{
2008-10-27 23:30:56 +03:00
# ifdef __i386__
# ifdef CONFIG_X86_BSWAP
asm ( " bswap %0 " : " =r " ( val ) : " 0 " ( val ) ) ;
# else
2008-03-23 11:01:47 +03:00
asm ( " xchgb %b0,%h0 \n \t " /* swap lower bytes */
" rorl $16,%0 \n \t " /* swap words */
" xchgb %b0,%h0 " /* swap higher bytes */
2008-10-27 23:30:56 +03:00
: " =q " ( val )
: " 0 " ( val ) ) ;
# endif
# else /* __i386__ */
asm ( " bswapl %0 "
: " =r " ( val )
: " 0 " ( val ) ) ;
2007-10-11 13:20:03 +04:00
# endif
2008-10-27 23:30:56 +03:00
return val ;
2007-10-24 00:37:23 +04:00
}
2008-10-27 23:30:56 +03:00
# define __arch_swab32 __arch_swab32
2007-10-24 00:37:23 +04:00
2008-10-27 23:30:56 +03:00
static inline __attribute_const__ __u64 __arch_swab64 ( __u64 val )
2007-10-24 00:37:23 +04:00
{
2008-10-27 23:30:56 +03:00
# ifdef __i386__
2007-10-24 00:37:23 +04:00
union {
2008-03-23 11:01:47 +03:00
struct {
__u32 a ;
__u32 b ;
} s ;
2007-10-24 00:37:23 +04:00
__u64 u ;
} v ;
v . u = val ;
2008-10-27 23:30:56 +03:00
# ifdef CONFIG_X86_BSWAP
2008-03-23 11:01:47 +03:00
asm ( " bswapl %0 ; bswapl %1 ; xchgl %0,%1 "
2007-10-24 00:37:23 +04:00
: " =r " ( v . s . a ) , " =r " ( v . s . b )
: " 0 " ( v . s . a ) , " 1 " ( v . s . b ) ) ;
2008-10-27 23:30:56 +03:00
# else
v . s . a = __arch_swab32 ( v . s . a ) ;
v . s . b = __arch_swab32 ( v . s . b ) ;
2008-03-23 11:01:47 +03:00
asm ( " xchgl %0,%1 "
: " =r " ( v . s . a ) , " =r " ( v . s . b )
: " 0 " ( v . s . a ) , " 1 " ( v . s . b ) ) ;
2008-10-27 23:30:56 +03:00
# endif
2007-10-24 00:37:23 +04:00
return v . u ;
# else /* __i386__ */
2008-03-23 11:01:47 +03:00
asm ( " bswapq %0 "
2008-10-27 23:30:56 +03:00
: " =r " ( val )
: " 0 " ( val ) ) ;
return val ;
2007-10-24 00:37:23 +04:00
# endif
2008-10-27 23:30:56 +03:00
}
# define __arch_swab64 __arch_swab64
2007-10-24 00:37:23 +04:00
2008-10-27 23:30:56 +03:00
# include <linux/byteorder.h>
2007-10-24 00:37:23 +04:00
2008-10-23 09:26:29 +04:00
# endif /* _ASM_X86_BYTEORDER_H */