| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#undef CAREFUL_ALIGNMENT |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#if defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__ || __amd64 |
| 26 |
#define CAREFUL_ALIGNMENT 0 |
| 27 |
#endif |
| 28 |
|
| 29 |
#ifndef CAREFUL_ALIGNMENT |
| 30 |
#define CAREFUL_ALIGNMENT 1 |
| 31 |
#endif |
| 32 |
|
| 33 |
#define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) |
| 34 |
#define UVAL(buf,pos) ((uint32)CVAL(buf,pos)) |
| 35 |
|
| 36 |
#if CAREFUL_ALIGNMENT |
| 37 |
|
| 38 |
static inline uint32 |
| 39 |
IVALu(const uchar *buf, int pos) |
| 40 |
{ |
| 41 |
return UVAL(buf, pos) |
| 42 |
| UVAL(buf, pos + 1) << 8 |
| 43 |
| UVAL(buf, pos + 2) << 16 |
| 44 |
| UVAL(buf, pos + 3) << 24; |
| 45 |
} |
| 46 |
|
| 47 |
static inline void |
| 48 |
SIVALu(uchar *buf, int pos, uint32 val) |
| 49 |
{ |
| 50 |
CVAL(buf, pos) = val; |
| 51 |
CVAL(buf, pos + 1) = val >> 8; |
| 52 |
CVAL(buf, pos + 2) = val >> 16; |
| 53 |
CVAL(buf, pos + 3) = val >> 24; |
| 54 |
} |
| 55 |
|
| 56 |
static inline int64 |
| 57 |
IVAL64(const char *buf, int pos) |
| 58 |
{ |
| 59 |
return IVALu((uchar*)buf, pos) | (int64)IVALu((uchar*)buf, pos + 4) << 32; |
| 60 |
} |
| 61 |
|
| 62 |
static inline void |
| 63 |
SIVAL64(char *buf, int pos, int64 val) |
| 64 |
{ |
| 65 |
SIVALu((uchar*)buf, pos, val); |
| 66 |
SIVALu((uchar*)buf, pos + 4, val >> 32); |
| 67 |
} |
| 68 |
|
| 69 |
#else |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
#ifndef GCC_VERSION |
| 77 |
#define GCC_VERSION (__GNUC__ * 10000 \ |
| 78 |
+ __GNUC_MINOR__ * 100 \ |
| 79 |
+ __GNUC_PATCHLEVEL__) |
| 80 |
#endif |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
#ifdef __clang__ |
| 87 |
__attribute__((no_sanitize("undefined"))) |
| 88 |
#elif GCC_VERSION >= 409 |
| 89 |
__attribute__((no_sanitize_undefined)) |
| 90 |
#endif |
| 91 |
static inline uint32 |
| 92 |
IVALu(const uchar *buf, int pos) |
| 93 |
{ |
| 94 |
union { |
| 95 |
const uchar *b; |
| 96 |
const uint32 *num; |
| 97 |
} u; |
| 98 |
u.b = buf + pos; |
| 99 |
return *u.num; |
| 100 |
} |
| 101 |
|
| 102 |
#ifdef __clang__ |
| 103 |
__attribute__((no_sanitize("undefined"))) |
| 104 |
#elif GCC_VERSION >= 409 |
| 105 |
__attribute__((no_sanitize_undefined)) |
| 106 |
#endif |
| 107 |
static inline void |
| 108 |
SIVALu(uchar *buf, int pos, uint32 val) |
| 109 |
{ |
| 110 |
union { |
| 111 |
uchar *b; |
| 112 |
uint32 *num; |
| 113 |
} u; |
| 114 |
u.b = buf + pos; |
| 115 |
*u.num = val; |
| 116 |
} |
| 117 |
|
| 118 |
#ifdef __clang__ |
| 119 |
__attribute__((no_sanitize("undefined"))) |
| 120 |
#elif GCC_VERSION >= 409 |
| 121 |
__attribute__((no_sanitize_undefined)) |
| 122 |
#endif |
| 123 |
static inline int64 |
| 124 |
IVAL64(const char *buf, int pos) |
| 125 |
{ |
| 126 |
union { |
| 127 |
const char *b; |
| 128 |
const int64 *num; |
| 129 |
} u; |
| 130 |
u.b = buf + pos; |
| 131 |
return *u.num; |
| 132 |
} |
| 133 |
|
| 134 |
#ifdef __clang__ |
| 135 |
__attribute__((no_sanitize("undefined"))) |
| 136 |
#elif GCC_VERSION >= 409 |
| 137 |
__attribute__((no_sanitize_undefined)) |
| 138 |
#endif |
| 139 |
static inline void |
| 140 |
SIVAL64(char *buf, int pos, int64 val) |
| 141 |
{ |
| 142 |
union { |
| 143 |
char *b; |
| 144 |
int64 *num; |
| 145 |
} u; |
| 146 |
u.b = buf + pos; |
| 147 |
*u.num = val; |
| 148 |
} |
| 149 |
|
| 150 |
#endif |
| 151 |
|
| 152 |
static inline uint32 |
| 153 |
IVAL(const char *buf, int pos) |
| 154 |
{ |
| 155 |
return IVALu((uchar*)buf, pos); |
| 156 |
} |
| 157 |
|
| 158 |
static inline void |
| 159 |
SIVAL(char *buf, int pos, uint32 val) |
| 160 |
{ |
| 161 |
SIVALu((uchar*)buf, pos, val); |
| 162 |
} |