X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=bswap.h;h=1dd357eb9d5259225cb20b7e1de6f9f896f24f7c;hb=fd93a79999c728dd1f30bb2e726ce12bdf704e6d;hp=37fb04ed9777d1fc372023021e52da38bc433be4;hpb=188d857911636fa43628eb8a7beeab4702636317;p=qemu diff --git a/bswap.h b/bswap.h index 37fb04e..1dd357e 100644 --- a/bswap.h +++ b/bswap.h @@ -5,6 +5,12 @@ #include +#ifdef HAVE_MACHINE_BSWAP_H +#include +#include +#include +#else + #ifdef HAVE_BYTESWAP_H #include #else @@ -48,16 +54,18 @@ static inline uint16_t bswap16(uint16_t x) return bswap_16(x); } -static inline uint32_t bswap32(uint32_t x) +static inline uint32_t bswap32(uint32_t x) { return bswap_32(x); } -static inline uint64_t bswap64(uint64_t x) +static inline uint64_t bswap64(uint64_t x) { return bswap_64(x); } +#endif /* ! HAVE_MACHINE_BSWAP_H */ + static inline void bswap16s(uint16_t *s) { *s = bswap16(*s); @@ -126,12 +134,13 @@ CPU_CONVERT(le, 64, uint64_t) /* unaligned versions (optimized for frequent unaligned accesses)*/ -#if defined(__i386__) || defined(__powerpc__) +#if defined(__i386__) || defined(_ARCH_PPC) #define cpu_to_le16wu(p, v) cpu_to_le16w(p, v) #define cpu_to_le32wu(p, v) cpu_to_le32w(p, v) #define le16_to_cpupu(p) le16_to_cpup(p) #define le32_to_cpupu(p) le32_to_cpup(p) +#define be32_to_cpupu(p) be32_to_cpup(p) #define cpu_to_be16wu(p, v) cpu_to_be16w(p, v) #define cpu_to_be32wu(p, v) cpu_to_be32w(p, v) @@ -142,7 +151,7 @@ static inline void cpu_to_le16wu(uint16_t *p, uint16_t v) { uint8_t *p1 = (uint8_t *)p; - p1[0] = v; + p1[0] = v & 0xff; p1[1] = v >> 8; } @@ -150,7 +159,7 @@ static inline void cpu_to_le32wu(uint32_t *p, uint32_t v) { uint8_t *p1 = (uint8_t *)p; - p1[0] = v; + p1[0] = v & 0xff; p1[1] = v >> 8; p1[2] = v >> 16; p1[3] = v >> 24; @@ -168,12 +177,18 @@ static inline uint32_t le32_to_cpupu(const uint32_t *p) return p1[0] | (p1[1] << 8) | (p1[2] << 16) | (p1[3] << 24); } +static inline uint32_t be32_to_cpupu(const uint32_t *p) +{ + const uint8_t *p1 = (const uint8_t *)p; + return p1[3] | (p1[2] << 8) | (p1[1] << 16) | (p1[0] << 24); +} + static inline void cpu_to_be16wu(uint16_t *p, uint16_t v) { uint8_t *p1 = (uint8_t *)p; p1[0] = v >> 8; - p1[1] = v; + p1[1] = v & 0xff; } static inline void cpu_to_be32wu(uint32_t *p, uint32_t v) @@ -183,7 +198,7 @@ static inline void cpu_to_be32wu(uint32_t *p, uint32_t v) p1[0] = v >> 24; p1[1] = v >> 16; p1[2] = v >> 8; - p1[3] = v; + p1[3] = v & 0xff; } #endif