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-sh / byteorder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-11  |  1.1 KB  |  57 lines

  1. #ifndef __ASM_SH_BYTEORDER_H
  2. #define __ASM_SH_BYTEORDER_H
  3.  
  4. /*
  5.  * Copyright (C) 1999  Niibe Yutaka
  6.  */
  7.  
  8. #include <asm/types.h>
  9. #include <linux/compiler.h>
  10.  
  11. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  12. {
  13.     __asm__("swap.b    %0, %0\n\t"
  14.         "swap.w %0, %0\n\t"
  15.         "swap.b %0, %0"
  16.         : "=r" (x)
  17.         : "0" (x));
  18.     return x;
  19. }
  20.  
  21. static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
  22. {
  23.     __asm__("swap.b %0, %0"
  24.         : "=r" (x)
  25.         :  "0" (x));
  26.     return x;
  27. }
  28.  
  29. static inline __u64 ___arch__swab64(__u64 val) 
  30.     union { 
  31.         struct { __u32 a,b; } s;
  32.         __u64 u;
  33.     } v, w;
  34.     v.u = val;
  35.     w.s.b = ___arch__swab32(v.s.a); 
  36.     w.s.a = ___arch__swab32(v.s.b); 
  37.     return w.u;    
  38.  
  39. #define __arch__swab64(x) ___arch__swab64(x)
  40. #define __arch__swab32(x) ___arch__swab32(x)
  41. #define __arch__swab16(x) ___arch__swab16(x)
  42.  
  43. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  44. #  define __BYTEORDER_HAS_U64__
  45. #  define __SWAB_64_THRU_32__
  46. #endif
  47.  
  48. #ifdef __LITTLE_ENDIAN__
  49. #include <linux/byteorder/little_endian.h>
  50. #else
  51. #include <linux/byteorder/big_endian.h>
  52. #endif
  53.  
  54. #endif /* __ASM_SH_BYTEORDER_H */
  55.