Commit 83d73968500d903a8dde19298a324bf45be7b3ee
1 parent
6b2d3e3c
faster big endian accesses on i386 - big endian ldsw_raw fix
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@632 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
78 additions
and
4 deletions
cpu-all.h
| ... | ... | @@ -56,6 +56,39 @@ typedef union { |
| 56 | 56 | |
| 57 | 57 | /* CPU memory access without any memory or io remapping */ |
| 58 | 58 | |
| 59 | +/* | |
| 60 | + * the generic syntax for the memory accesses is: | |
| 61 | + * | |
| 62 | + * load: ld{type}{sign}{size}{endian}_{access_type}(ptr) | |
| 63 | + * | |
| 64 | + * store: st{type}{size}{endian}_{access_type}(ptr, val) | |
| 65 | + * | |
| 66 | + * type is: | |
| 67 | + * (empty): integer access | |
| 68 | + * f : float access | |
| 69 | + * | |
| 70 | + * sign is: | |
| 71 | + * (empty): for floats or 32 bit size | |
| 72 | + * u : unsigned | |
| 73 | + * s : signed | |
| 74 | + * | |
| 75 | + * size is: | |
| 76 | + * b: 8 bits | |
| 77 | + * w: 16 bits | |
| 78 | + * l: 32 bits | |
| 79 | + * q: 64 bits | |
| 80 | + * | |
| 81 | + * endian is: | |
| 82 | + * (empty): target cpu endianness or 8 bit access | |
| 83 | + * r : reversed target cpu endianness (not implemented yet) | |
| 84 | + * be : big endian (not implemented yet) | |
| 85 | + * le : little endian (not implemented yet) | |
| 86 | + * | |
| 87 | + * access_type is: | |
| 88 | + * raw : host memory access | |
| 89 | + * user : user mode access using soft MMU | |
| 90 | + * kernel : kernel mode access using soft MMU | |
| 91 | + */ | |
| 59 | 92 | static inline int ldub_raw(void *ptr) |
| 60 | 93 | { |
| 61 | 94 | return *(uint8_t *)ptr; |
| ... | ... | @@ -195,20 +228,47 @@ static inline void stfq_raw(void *ptr, double v) |
| 195 | 228 | |
| 196 | 229 | static inline int lduw_raw(void *ptr) |
| 197 | 230 | { |
| 231 | +#if defined(__i386__) | |
| 232 | + int val; | |
| 233 | + asm volatile ("movzwl %1, %0\n" | |
| 234 | + "xchgb %b0, %h0\n" | |
| 235 | + : "=q" (val) | |
| 236 | + : "m" (*(uint16_t *)ptr)); | |
| 237 | + return val; | |
| 238 | +#else | |
| 198 | 239 | uint8_t *b = (uint8_t *) ptr; |
| 199 | - return (b[0]<<8|b[1]); | |
| 240 | + return ((b[0] << 8) | b[1]); | |
| 241 | +#endif | |
| 200 | 242 | } |
| 201 | 243 | |
| 202 | 244 | static inline int ldsw_raw(void *ptr) |
| 203 | 245 | { |
| 204 | - int8_t *b = (int8_t *) ptr; | |
| 205 | - return (b[0]<<8|b[1]); | |
| 246 | +#if defined(__i386__) | |
| 247 | + int val; | |
| 248 | + asm volatile ("movzwl %1, %0\n" | |
| 249 | + "xchgb %b0, %h0\n" | |
| 250 | + : "=q" (val) | |
| 251 | + : "m" (*(uint16_t *)ptr)); | |
| 252 | + return (int16_t)val; | |
| 253 | +#else | |
| 254 | + uint8_t *b = (uint8_t *) ptr; | |
| 255 | + return (int16_t)((b[0] << 8) | b[1]); | |
| 256 | +#endif | |
| 206 | 257 | } |
| 207 | 258 | |
| 208 | 259 | static inline int ldl_raw(void *ptr) |
| 209 | 260 | { |
| 261 | +#if defined(__i386__) | |
| 262 | + int val; | |
| 263 | + asm volatile ("movl %1, %0\n" | |
| 264 | + "bswap %0\n" | |
| 265 | + : "=r" (val) | |
| 266 | + : "m" (*(uint32_t *)ptr)); | |
| 267 | + return val; | |
| 268 | +#else | |
| 210 | 269 | uint8_t *b = (uint8_t *) ptr; |
| 211 | - return (b[0]<<24|b[1]<<16|b[2]<<8|b[3]); | |
| 270 | + return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; | |
| 271 | +#endif | |
| 212 | 272 | } |
| 213 | 273 | |
| 214 | 274 | static inline uint64_t ldq_raw(void *ptr) |
| ... | ... | @@ -221,18 +281,32 @@ static inline uint64_t ldq_raw(void *ptr) |
| 221 | 281 | |
| 222 | 282 | static inline void stw_raw(void *ptr, int v) |
| 223 | 283 | { |
| 284 | +#if defined(__i386__) | |
| 285 | + asm volatile ("xchgb %b0, %h0\n" | |
| 286 | + "movw %w0, %1\n" | |
| 287 | + : "=q" (v) | |
| 288 | + : "m" (*(uint16_t *)ptr), "0" (v)); | |
| 289 | +#else | |
| 224 | 290 | uint8_t *d = (uint8_t *) ptr; |
| 225 | 291 | d[0] = v >> 8; |
| 226 | 292 | d[1] = v; |
| 293 | +#endif | |
| 227 | 294 | } |
| 228 | 295 | |
| 229 | 296 | static inline void stl_raw(void *ptr, int v) |
| 230 | 297 | { |
| 298 | +#if defined(__i386__) | |
| 299 | + asm volatile ("bswap %0\n" | |
| 300 | + "movl %0, %1\n" | |
| 301 | + : "=r" (v) | |
| 302 | + : "m" (*(uint32_t *)ptr), "0" (v)); | |
| 303 | +#else | |
| 231 | 304 | uint8_t *d = (uint8_t *) ptr; |
| 232 | 305 | d[0] = v >> 24; |
| 233 | 306 | d[1] = v >> 16; |
| 234 | 307 | d[2] = v >> 8; |
| 235 | 308 | d[3] = v; |
| 309 | +#endif | |
| 236 | 310 | } |
| 237 | 311 | |
| 238 | 312 | static inline void stq_raw(void *ptr, uint64_t v) | ... | ... |