swab.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version
  5. * 2 of the License, or (at your option) any later version.
  6. */
  7. #ifndef _ASM_POWERPC_SWAB_H
  8. #define _ASM_POWERPC_SWAB_H
  9. #include <uapi/asm/swab.h>
  10. #ifdef __GNUC__
  11. #ifndef __powerpc64__
  12. #endif /* __powerpc64__ */
  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. #define __arch_swab16p ld_le16
  20. static __inline__ void st_le16(volatile __u16 *addr, const __u16 val)
  21. {
  22. __asm__ __volatile__ ("sthbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
  23. }
  24. static inline void __arch_swab16s(__u16 *addr)
  25. {
  26. st_le16(addr, *addr);
  27. }
  28. #define __arch_swab16s __arch_swab16s
  29. static __inline__ __u32 ld_le32(const volatile __u32 *addr)
  30. {
  31. __u32 val;
  32. __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (val) : "r" (addr), "m" (*addr));
  33. return val;
  34. }
  35. #define __arch_swab32p ld_le32
  36. static __inline__ void st_le32(volatile __u32 *addr, const __u32 val)
  37. {
  38. __asm__ __volatile__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr));
  39. }
  40. static inline void __arch_swab32s(__u32 *addr)
  41. {
  42. st_le32(addr, *addr);
  43. }
  44. #define __arch_swab32s __arch_swab32s
  45. static inline __attribute_const__ __u16 __arch_swab16(__u16 value)
  46. {
  47. __u16 result;
  48. __asm__("rlwimi %0,%1,8,16,23"
  49. : "=r" (result)
  50. : "r" (value), "0" (value >> 8));
  51. return result;
  52. }
  53. #define __arch_swab16 __arch_swab16
  54. static inline __attribute_const__ __u32 __arch_swab32(__u32 value)
  55. {
  56. __u32 result;
  57. __asm__("rlwimi %0,%1,24,16,23\n\t"
  58. "rlwimi %0,%1,8,8,15\n\t"
  59. "rlwimi %0,%1,24,0,7"
  60. : "=r" (result)
  61. : "r" (value), "0" (value >> 24));
  62. return result;
  63. }
  64. #define __arch_swab32 __arch_swab32
  65. #endif /* __GNUC__ */
  66. #endif /* _ASM_POWERPC_SWAB_H */