Commit eb26db16d77fc4f2b4c6e09b0376c3e547600fe3
1 parent
4c8732d7
endianness functions for unaligned memory accesses
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@908 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
62 additions
and
0 deletions
vl.h
| ... | ... | @@ -141,6 +141,68 @@ static inline uint16_t cpu_to_le16(uint16_t v) |
| 141 | 141 | } |
| 142 | 142 | #endif |
| 143 | 143 | |
| 144 | +static inline void cpu_to_le16w(uint16_t *p, uint16_t v) | |
| 145 | +{ | |
| 146 | + *p = cpu_to_le16(v); | |
| 147 | +} | |
| 148 | + | |
| 149 | +static inline void cpu_to_le32w(uint32_t *p, uint32_t v) | |
| 150 | +{ | |
| 151 | + *p = cpu_to_le32(v); | |
| 152 | +} | |
| 153 | + | |
| 154 | +static inline uint16_t le16_to_cpup(const uint16_t *p) | |
| 155 | +{ | |
| 156 | + return le16_to_cpu(*p); | |
| 157 | +} | |
| 158 | + | |
| 159 | +static inline uint32_t le32_to_cpup(const uint32_t *p) | |
| 160 | +{ | |
| 161 | + return le32_to_cpu(*p); | |
| 162 | +} | |
| 163 | + | |
| 164 | +/* unaligned versions (optimized for frequent unaligned accesses)*/ | |
| 165 | + | |
| 166 | +#if defined(__i386__) || defined(__powerpc__) | |
| 167 | + | |
| 168 | +#define cpu_to_le16wu(p, v) cpu_to_le16w(p, v) | |
| 169 | +#define cpu_to_le32wu(p, v) cpu_to_le32w(p, v) | |
| 170 | +#define le16_to_cpupu(p) le16_to_cpup(p) | |
| 171 | +#define le32_to_cpupu(p) le32_to_cpup(p) | |
| 172 | + | |
| 173 | +#else | |
| 174 | + | |
| 175 | +static inline void cpu_to_le16wu(uint16_t *p, uint16_t v) | |
| 176 | +{ | |
| 177 | + uint8_t *p1 = (uint8_t *)p; | |
| 178 | + | |
| 179 | + p1[0] = v; | |
| 180 | + p1[1] = v >> 8; | |
| 181 | +} | |
| 182 | + | |
| 183 | +static inline void cpu_to_le32wu(uint32_t *p, uint32_t v) | |
| 184 | +{ | |
| 185 | + uint8_t *p1 = (uint8_t *)p; | |
| 186 | + | |
| 187 | + p1[0] = v; | |
| 188 | + p1[1] = v >> 8; | |
| 189 | + p1[2] = v >> 16; | |
| 190 | + p1[3] = v >> 24; | |
| 191 | +} | |
| 192 | + | |
| 193 | +static inline uint16_t le16_to_cpupu(const uint16_t *p) | |
| 194 | +{ | |
| 195 | + const uint8_t *p1 = (const uint8_t *)p; | |
| 196 | + return p1[0] | (p1[1] << 8); | |
| 197 | +} | |
| 198 | + | |
| 199 | +static inline uint32_t le32_to_cpupu(const uint32_t *p) | |
| 200 | +{ | |
| 201 | + const uint8_t *p1 = (const uint8_t *)p; | |
| 202 | + return p1[0] | (p1[1] << 8) | (p1[2] << 16) | (p1[3] << 24); | |
| 203 | +} | |
| 204 | + | |
| 205 | +#endif | |
| 144 | 206 | |
| 145 | 207 | /* vl.c */ |
| 146 | 208 | extern int reset_requested; | ... | ... |