swab.h 1.5 KB

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