byteorder.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  4. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  5. */
  6. #ifndef _M68K_BYTEORDER_H
  7. #define _M68K_BYTEORDER_H
  8. #include <asm/types.h>
  9. #ifdef __GNUC__
  10. static inline __u32 __sw32(__u32 x)
  11. {
  12. __u32 v = x;
  13. return v << 24 |
  14. (v & (__u32)0x0000ff00UL) << 8 |
  15. (v & (__u32)0x00ff0000UL) >> 8 |
  16. v >> 24;
  17. }
  18. static inline __u16 __sw16(__u16 x)
  19. {
  20. __u16 v = x;
  21. return (v & (__u16)0x00ffU) << 8 |
  22. (v & (__u16)0xff00U) >> 8;
  23. }
  24. static __inline__ unsigned ld_le16(const volatile unsigned short *addr)
  25. {
  26. return __sw16(*addr);
  27. }
  28. static __inline__ void st_le16(volatile unsigned short *addr,
  29. const unsigned val)
  30. {
  31. *addr = __sw16(val);
  32. }
  33. static __inline__ unsigned ld_le32(const volatile unsigned *addr)
  34. {
  35. return __sw32(*addr);
  36. }
  37. static __inline__ void st_le32(volatile unsigned *addr, const unsigned val)
  38. {
  39. *addr = __sw32(val);
  40. }
  41. #if 0
  42. /* alas, egcs sounds like it has a bug in this code that doesn't use the
  43. inline asm correctly, and can cause file corruption. Until I hear that
  44. it's fixed, I can live without the extra speed. I hope. */
  45. #if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90)
  46. #if 0
  47. # define __arch_swab16(x) ld_le16(&x)
  48. # define __arch_swab32(x) ld_le32(&x)
  49. #else
  50. static __inline__ __attribute__ ((const))
  51. __u16 ___arch__swab16(__u16 value)
  52. {
  53. return __sw16(value);
  54. }
  55. static __inline__ __attribute__ ((const))
  56. __u32 ___arch__swab32(__u32 value)
  57. {
  58. return __sw32(value);
  59. }
  60. #define __arch__swab32(x) ___arch__swab32(x)
  61. #define __arch__swab16(x) ___arch__swab16(x)
  62. #endif /* 0 */
  63. #endif
  64. /* The same, but returns converted value from the location pointer by addr. */
  65. #define __arch__swab16p(addr) ld_le16(addr)
  66. #define __arch__swab32p(addr) ld_le32(addr)
  67. /* The same, but do the conversion in situ, ie. put the value back to addr. */
  68. #define __arch__swab16s(addr) st_le16(addr,*addr)
  69. #define __arch__swab32s(addr) st_le32(addr,*addr)
  70. #endif
  71. #endif /* __GNUC__ */
  72. #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  73. #define __BYTEORDER_HAS_U64__
  74. #endif
  75. #include <linux/byteorder/big_endian.h>
  76. #endif /* _M68K_BYTEORDER_H */