home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / Include / asm / byteorder.h < prev    next >
C/C++ Source or Header  |  2002-04-26  |  1KB  |  50 lines

  1. /* $Id: byteorder.h,v 1.2 2002/04/26 23:09:18 smilcke Exp $ */
  2.  
  3. #ifndef _I386_BYTEORDER_H
  4. #define _I386_BYTEORDER_H
  5.  
  6. #include <asm/types.h>
  7.  
  8. #ifdef __GNUC__
  9.  
  10. /* For avoiding bswap on i386 */
  11. #ifdef __KERNEL__
  12. #include <linux/config.h>
  13. #endif
  14.  
  15. static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
  16. {
  17. #ifdef CONFIG_X86_BSWAP
  18.     __asm__("bswap %0" : "=r" (x) : "0" (x));
  19. #else
  20.     __asm__("xchgb %b0,%h0\n\t"    /* swap lower bytes    */
  21.         "rorl $16,%0\n\t"    /* swap words        */
  22.         "xchgb %b0,%h0"        /* swap higher bytes    */
  23.         :"=q" (x)
  24.         : "0" (x));
  25. #endif
  26.     return x;
  27. }
  28.  
  29. static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
  30. {
  31.     __asm__("xchgb %b0,%h0"        /* swap bytes        */ \
  32.         : "=q" (x) \
  33.         :  "0" (x)); \
  34.         return x;
  35. }
  36.  
  37. #define __arch__swab32(x) ___arch__swab32(x)
  38. #define __arch__swab16(x) ___arch__swab16(x)
  39.  
  40. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  41. #  define __BYTEORDER_HAS_U64__
  42. #  define __SWAB_64_THRU_32__
  43. #endif
  44.  
  45. #endif /* __GNUC__ */
  46.  
  47. #include <linux/byteorder/little_endian.h>
  48.  
  49. #endif /* _I386_BYTEORDER_H */
  50.