home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.28-15 / arch / sh / include / asm / byteorder.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-12-24  |  1.1 KB  |  69 lines

  1. #ifndef __ASM_SH_BYTEORDER_H
  2. #define __ASM_SH_BYTEORDER_H
  3.  
  4. /*
  5.  * Copyright (C) 1999  Niibe Yutaka
  6.  * Copyright (C) 2000, 2001  Paolo Alberelli
  7.  */
  8. #include <linux/compiler.h>
  9. #include <linux/types.h>
  10.  
  11. #ifdef __LITTLE_ENDIAN__
  12. # define __LITTLE_ENDIAN
  13. #else
  14. # define __BIG_ENDIAN
  15. #endif
  16.  
  17. #define __SWAB_64_THRU_32__
  18.  
  19. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  20. {
  21.     __asm__(
  22. #ifdef __SH5__
  23.         "byterev    %0, %0\n\t"
  24.         "shari        %0, 32, %0"
  25. #else
  26.         "swap.b        %0, %0\n\t"
  27.         "swap.w        %0, %0\n\t"
  28.         "swap.b        %0, %0"
  29. #endif
  30.         : "=r" (x)
  31.         : "0" (x));
  32.  
  33.     return x;
  34. }
  35. #define __arch_swab32 __arch_swab32
  36.  
  37. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  38. {
  39.     __asm__(
  40. #ifdef __SH5__
  41.         "byterev    %0, %0\n\t"
  42.         "shari        %0, 32, %0"
  43. #else
  44.         "swap.b        %0, %0"
  45. #endif
  46.         : "=r" (x)
  47.         :  "0" (x));
  48.  
  49.     return x;
  50. }
  51. #define __arch_swab16 __arch_swab16
  52.  
  53. static inline __u64 __arch_swab64(__u64 val)
  54. {
  55.     union {
  56.         struct { __u32 a,b; } s;
  57.         __u64 u;
  58.     } v, w;
  59.     v.u = val;
  60.     w.s.b = __arch_swab32(v.s.a);
  61.     w.s.a = __arch_swab32(v.s.b);
  62.     return w.u;
  63. }
  64. #define __arch_swab64 __arch_swab64
  65.  
  66. #include <linux/byteorder.h>
  67.  
  68. #endif /* __ASM_SH_BYTEORDER_H */
  69.