swab.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #if !defined(__mips16) && \
  14. ((defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) || \
  15. defined(_MIPS_ARCH_LOONGSON3A))
  16. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  17. {
  18. __asm__(
  19. " .set push \n"
  20. " .set arch=mips32r2 \n"
  21. " wsbh %0, %1 \n"
  22. " .set pop \n"
  23. : "=r" (x)
  24. : "r" (x));
  25. return x;
  26. }
  27. #define __arch_swab16 __arch_swab16
  28. static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
  29. {
  30. __asm__(
  31. " .set push \n"
  32. " .set arch=mips32r2 \n"
  33. " wsbh %0, %1 \n"
  34. " rotr %0, %0, 16 \n"
  35. " .set pop \n"
  36. : "=r" (x)
  37. : "r" (x));
  38. return x;
  39. }
  40. #define __arch_swab32 __arch_swab32
  41. /*
  42. * Having already checked for MIPS R2, enable the optimized version for
  43. * 64-bit kernel on r2 CPUs.
  44. */
  45. #ifdef __mips64
  46. static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
  47. {
  48. __asm__(
  49. " .set push \n"
  50. " .set arch=mips64r2 \n"
  51. " dsbh %0, %1 \n"
  52. " dshd %0, %0 \n"
  53. " .set pop \n"
  54. : "=r" (x)
  55. : "r" (x));
  56. return x;
  57. }
  58. #define __arch_swab64 __arch_swab64
  59. #endif /* __mips64 */
  60. #endif /* (not __mips16) and (MIPS R2 or newer or Loongson 3A) */
  61. #endif /* _ASM_SWAB_H */