swab.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * This file is subject to the terms and conditions of the GNU General Public
  4. * License. See the file "COPYING" in the main directory of this archive
  5. * for more details.
  6. *
  7. * Copyright (C) 1996, 99, 2003 by Ralf Baechle
  8. */
  9. #ifndef _ASM_SWAB_H
  10. #define _ASM_SWAB_H
  11. #include <linux/compiler.h>
  12. #include <linux/types.h>
  13. #define __SWAB_64_THRU_32__
  14. #if !defined(__mips16) && \
  15. ((defined(__mips_isa_rev) && (__mips_isa_rev >= 2)) || \
  16. defined(_MIPS_ARCH_LOONGSON3A))
  17. static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
  18. {
  19. __asm__(
  20. " .set push \n"
  21. " .set arch=mips32r2 \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_const__ __u32 __arch_swab32(__u32 x)
  30. {
  31. __asm__(
  32. " .set push \n"
  33. " .set arch=mips32r2 \n"
  34. " wsbh %0, %1 \n"
  35. " rotr %0, %0, 16 \n"
  36. " .set pop \n"
  37. : "=r" (x)
  38. : "r" (x));
  39. return x;
  40. }
  41. #define __arch_swab32 __arch_swab32
  42. /*
  43. * Having already checked for MIPS R2, enable the optimized version for
  44. * 64-bit kernel on r2 CPUs.
  45. */
  46. #ifdef __mips64
  47. static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
  48. {
  49. __asm__(
  50. " .set push \n"
  51. " .set arch=mips64r2 \n"
  52. " dsbh %0, %1 \n"
  53. " dshd %0, %0 \n"
  54. " .set pop \n"
  55. : "=r" (x)
  56. : "r" (x));
  57. return x;
  58. }
  59. #define __arch_swab64 __arch_swab64
  60. #endif /* __mips64 */
  61. #endif /* (not __mips16) and (MIPS R2 or newer or Loongson 3A) */
  62. #endif /* _ASM_SWAB_H */