swab.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1996, 99, 2003 by Ralf Baechle
  7. */
  8. #ifndef _ASM_SWAB_H
  9. #define _ASM_SWAB_H
  10. #include <linux/compiler.h>
  11. #include <linux/types.h>
  12. #define __SWAB_64_THRU_32__
  13. #ifdef CONFIG_CPU_MIPSR2
  14. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  15. {
  16. __asm__(
  17. " wsbh %0, %1 \n"
  18. : "=r" (x)
  19. : "r" (x));
  20. return x;
  21. }
  22. #define __arch_swab16 __arch_swab16
  23. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  24. {
  25. __asm__(
  26. " wsbh %0, %1 \n"
  27. " rotr %0, %0, 16 \n"
  28. : "=r" (x)
  29. : "r" (x));
  30. return x;
  31. }
  32. #define __arch_swab32 __arch_swab32
  33. /*
  34. * Having already checked for CONFIG_CPU_MIPSR2, enable the
  35. * optimized version for 64-bit kernel on r2 CPUs.
  36. */
  37. #ifdef CONFIG_64BIT
  38. static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
  39. {
  40. __asm__(
  41. " dsbh %0, %1\n"
  42. " dshd %0, %0"
  43. : "=r" (x)
  44. : "r" (x));
  45. return x;
  46. }
  47. #define __arch_swab64 __arch_swab64
  48. #endif /* CONFIG_64BIT */
  49. #endif /* CONFIG_CPU_MIPSR2 */
  50. #endif /* _ASM_SWAB_H */