swab.h 1.4 KB

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