home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / src / linux-headers-2.6.17-6 / include / asm-i386 / byteorder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-11  |  1.3 KB  |  59 lines

  1. #ifndef _I386_BYTEORDER_H
  2. #define _I386_BYTEORDER_H
  3.  
  4. #include <asm/types.h>
  5. #include <linux/compiler.h>
  6.  
  7. #ifdef __GNUC__
  8.  
  9. /* For avoiding bswap on i386 */
  10. #ifdef __KERNEL__
  11. #endif
  12.  
  13. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  14. {
  15. #ifdef CONFIG_X86_BSWAP
  16.     __asm__("bswap %0" : "=r" (x) : "0" (x));
  17. #else
  18.     __asm__("xchgb %b0,%h0\n\t"    /* swap lower bytes    */
  19.         "rorl $16,%0\n\t"    /* swap words        */
  20.         "xchgb %b0,%h0"        /* swap higher bytes    */
  21.         :"=q" (x)
  22.         : "0" (x));
  23. #endif
  24.     return x;
  25. }
  26.  
  27. static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 val)
  28.     union { 
  29.         struct { __u32 a,b; } s;
  30.         __u64 u;
  31.     } v;
  32.     v.u = val;
  33. #ifdef CONFIG_X86_BSWAP
  34.     asm("bswapl %0 ; bswapl %1 ; xchgl %0,%1" 
  35.         : "=r" (v.s.a), "=r" (v.s.b) 
  36.         : "0" (v.s.a), "1" (v.s.b)); 
  37. #else
  38.    v.s.a = ___arch__swab32(v.s.a); 
  39.     v.s.b = ___arch__swab32(v.s.b); 
  40.     asm("xchgl %0,%1" : "=r" (v.s.a), "=r" (v.s.b) : "0" (v.s.a), "1" (v.s.b));
  41. #endif
  42.     return v.u;    
  43.  
  44. /* Do not define swab16.  Gcc is smart enough to recognize "C" version and
  45.    convert it into rotation or exhange.  */
  46.  
  47. #define __arch__swab64(x) ___arch__swab64(x)
  48. #define __arch__swab32(x) ___arch__swab32(x)
  49.  
  50. #define __BYTEORDER_HAS_U64__
  51.  
  52. #endif /* __GNUC__ */
  53.  
  54. #include <linux/byteorder/little_endian.h>
  55.  
  56. #endif /* _I386_BYTEORDER_H */
  57.