9 #ifndef _gu_byteswap_h_
10 #define _gu_byteswap_h_
14 #include "gu_macros.h"
24 #define GU_ROTL32(x,y) _rotl(x,y)
25 #define GU_ROTL64(x,y) _rotl64(x,y)
29 static GU_FORCE_INLINE uint32_t GU_ROTL32 (uint32_t x, int8_t r)
31 return (x << r) | (x >> (32 - r));
34 static GU_FORCE_INLINE uint64_t GU_ROTL64 (uint64_t x, int8_t r)
36 return (x << r) | (x >> (64 - r));
45 #if defined(HAVE_BYTESWAP_H)
46 # include <byteswap.h>
47 #elif defined(__APPLE__)
48 # include <libkern/OSByteOrder.h>
51 #if defined(__APPLE__)
53 # define gu_bswap16 _OSSwapInt16
54 # define gu_bswap32 _OSSwapInt32
55 # define gu_bswap64 _OSSwapInt64
56 #elif defined(__FreeBSD__)
58 # define gu_bswap16 __bswap16_var
59 # define gu_bswap32 __bswap32_var
60 # define gu_bswap64 __bswap64_var
61 #elif defined(__sun__)
62 # define gu_bswap16 BSWAP_16
63 # define gu_bswap32 BSWAP_32
64 # define gu_bswap64 BSWAP_64
65 #elif defined(bswap16)
66 # define gu_bswap16 bswap16
67 # define gu_bswap32 bswap32
68 # define gu_bswap64 bswap64
69 #elif defined(bswap_16)
70 # define gu_bswap16 bswap_16
71 # define gu_bswap32 bswap_32
72 # define gu_bswap64 bswap_64
74 # error "No byteswap macros are defined"
83 static GU_FORCE_INLINE uint16_t gu_bswap16(uint16_t
const x)
86 {
return static_cast<uint16_t
>((x >> 8) | (x << 8)); }
89 #if defined(GU_LITTLE_ENDIAN)
91 #define gu_le16(x) (x)
92 #define gu_le32(x) (x)
93 #define gu_le64(x) (x)
96 #define gu_be16(x) gu_bswap16(x)
97 #define gu_be32(x) gu_bswap32(x)
98 #define gu_be64(x) gu_bswap64(x)
103 #define gu_le16(x) gu_bswap16(x)
104 #define gu_le32(x) gu_bswap32(x)
105 #define gu_le64(x) gu_bswap64(x)
108 #define gu_be16(x) (x)
109 #define gu_be32(x) (x)
110 #define gu_be64(x) (x)
117 #define htogs(x) gu_le16(x)
118 #define gtohs(x) htogs(x)
119 #define htogl(x) gu_le32(x)
120 #define gtohl(x) htogl(x)
123 #define htog16(x) gu_le16(x)
124 #define gtoh16(x) htog16(x)
125 #define htog32(x) gu_le32(x)
126 #define gtoh32(x) htog32(x)
127 #define htog64(x) gu_le64(x)
128 #define gtoh64(x) htog64(x)