byteorder.h 1.3 KB

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