byteorder.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 1996, 99, 2003 by Ralf Baechle
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #ifndef _ASM_BYTEORDER_H
  7. #define _ASM_BYTEORDER_H
  8. #include <asm/types.h>
  9. #ifdef __GNUC__
  10. #ifdef CONFIG_CPU_MIPSR2
  11. static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
  12. {
  13. __asm__(
  14. " wsbh %0, %1 \n"
  15. : "=r" (x)
  16. : "r" (x));
  17. return x;
  18. }
  19. #define __arch__swab16(x) ___arch__swab16(x)
  20. static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
  21. {
  22. __asm__(
  23. " wsbh %0, %1 \n"
  24. " rotr %0, %0, 16 \n"
  25. : "=r" (x)
  26. : "r" (x));
  27. return x;
  28. }
  29. #define __arch__swab32(x) ___arch__swab32(x)
  30. #ifdef CONFIG_CPU_MIPS64_R2
  31. static __inline__ __attribute_const__ __u64 ___arch__swab64(__u64 x)
  32. {
  33. __asm__(
  34. " dsbh %0, %1 \n"
  35. " dshd %0, %0 \n"
  36. " drotr %0, %0, 32 \n"
  37. : "=r" (x)
  38. : "r" (x));
  39. return x;
  40. }
  41. #define __arch__swab64(x) ___arch__swab64(x)
  42. #endif /* CONFIG_CPU_MIPS64_R2 */
  43. #endif /* CONFIG_CPU_MIPSR2 */
  44. #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
  45. # define __BYTEORDER_HAS_U64__
  46. # define __SWAB_64_THRU_32__
  47. #endif
  48. #endif /* __GNUC__ */
  49. #if defined(__MIPSEB__)
  50. # include <linux/byteorder/big_endian.h>
  51. #elif defined(__MIPSEL__)
  52. # include <linux/byteorder/little_endian.h>
  53. #else
  54. # error "MIPS, but neither __MIPSEB__, nor __MIPSEL__???"
  55. #endif
  56. #endif /* _ASM_BYTEORDER_H */