byteorder.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef _ASM_POWERPC_BYTEORDER_H
  2. #define _ASM_POWERPC_BYTEORDER_H
  3. /*
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <asm/types.h>
  10. #include <linux/compiler.h>
  11. #ifdef __GNUC__
  12. #ifdef __KERNEL__
  13. static __inline__ __u16 ld_le16(const volatile __u16 *addr)
  14. {
  15. __u16 val;
  16. __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
  17. return val;
  18. }
  19. static __inline__ void st_le16(volatile __u16 *addr, const __u16 val)
  20. {
  21. __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
  22. }
  23. static __inline__ __u32 ld_le32(const volatile __u32 *addr)
  24. {
  25. __u32 val;
  26. __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
  27. return val;
  28. }
  29. static __inline__ void st_le32(volatile __u32 *addr, const __u32 val)
  30. {
  31. __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
  32. }
  33. static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 value)
  34. {
  35. __u16 result;
  36. __asm__("rlwimi %0,%1,8,16,23"
  37. : "=r" (result)
  38. : "r" (value), "0" (value >> 8));
  39. return result;
  40. }
  41. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 value)
  42. {
  43. __u32 result;
  44. __asm__("rlwimi %0,%1,24,16,23\n\t"
  45. "rlwimi %0,%1,8,8,15\n\t"
  46. "rlwimi %0,%1,24,0,7"
  47. : "=r" (result)
  48. : "r" (value), "0" (value >> 24));
  49. return result;
  50. }
  51. #define __arch__swab16(x) ___arch__swab16(x)
  52. #define __arch__swab32(x) ___arch__swab32(x)
  53. /* The same, but returns converted value from the location pointer by addr. */
  54. #define __arch__swab16p(addr) ld_le16(addr)
  55. #define __arch__swab32p(addr) ld_le32(addr)
  56. /* The same, but do the conversion in situ, ie. put the value back to addr. */
  57. #define __arch__swab16s(addr) st_le16(addr,*addr)
  58. #define __arch__swab32s(addr) st_le32(addr,*addr)
  59. #endif /* __KERNEL__ */
  60. #ifndef __STRICT_ANSI__
  61. #define __BYTEORDER_HAS_U64__
  62. #ifndef __powerpc64__
  63. #define __SWAB_64_THRU_32__
  64. #endif /* __powerpc64__ */
  65. #endif /* __STRICT_ANSI__ */
  66. #endif /* __GNUC__ */
  67. #include <linux/byteorder/big_endian.h>
  68. #endif /* _ASM_POWERPC_BYTEORDER_H */