diff options
author | Tom Gundersen <teg@jklm.no> | 2014-11-04 19:52:04 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-11-05 16:54:22 +0100 |
commit | 617e79465249e694d697fd78704571b3d00338c8 (patch) | |
tree | 10b6c91f2a508c9982cd218ed92b6a80682e5f21 /src/shared | |
parent | 9eec671331adeb3f9a81b390758000364388a042 (diff) |
shared: unaligned - use void* instead of unaligned be16_t*
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/unaligned.h | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/src/shared/unaligned.h b/src/shared/unaligned.h index b194d71017..d6181dd9a9 100644 --- a/src/shared/unaligned.h +++ b/src/shared/unaligned.h @@ -23,34 +23,44 @@ #include <stdint.h> -#include "sparse-endian.h" +static inline uint16_t unaligned_read_be16(const void *_u) { + const uint8_t *u = _u; -static inline uint16_t unaligned_read_be16(const be16_t *u) { - return (((uint16_t) ((uint8_t*) u)[0]) << 8) | - ((uint16_t) ((uint8_t*) u)[1]); + return (((uint16_t) u[0]) << 8) | + ((uint16_t) u[1]); } -static inline uint32_t unaligned_read_be32(const be32_t *u) { - return (((uint32_t) unaligned_read_be16((be16_t*) u)) << 16) | - ((uint32_t) unaligned_read_be16((be16_t*) u + 1)); +static inline uint32_t unaligned_read_be32(const void *_u) { + const uint8_t *u = _u; + + return (((uint32_t) unaligned_read_be16(u)) << 16) | + ((uint32_t) unaligned_read_be16(u + 2)); } -static inline uint64_t unaligned_read_be64(const be64_t *u) { - return (((uint64_t) unaligned_read_be32((be32_t*) u)) << 32) | - ((uint64_t) unaligned_read_be32((be32_t*) u + 1)); +static inline uint64_t unaligned_read_be64(const void *_u) { + const uint8_t *u = _u; + + return (((uint64_t) unaligned_read_be32(u)) << 32) | + ((uint64_t) unaligned_read_be32(u + 4)); } -static inline void unaligned_write_be16(be16_t *u, uint16_t a) { - ((uint8_t*) u)[0] = (uint8_t) (a >> 8); - ((uint8_t*) u)[1] = (uint8_t) a; +static inline void unaligned_write_be16(void *_u, uint16_t a) { + uint8_t *u = _u; + + u[0] = (uint8_t) (a >> 8); + u[1] = (uint8_t) a; } -static inline void unaligned_write_be32(be32_t *u, uint32_t a) { - unaligned_write_be16((be16_t*) u, (uint16_t) (a >> 16)); - unaligned_write_be16((be16_t*) u + 1, (uint16_t) a); +static inline void unaligned_write_be32(void *_u, uint32_t a) { + uint8_t *u = _u; + + unaligned_write_be16(u, (uint16_t) (a >> 16)); + unaligned_write_be16(u + 2, (uint16_t) a); } -static inline void unaligned_write_be64(be64_t *u, uint64_t a) { - unaligned_write_be32((be32_t*) u, (uint32_t) (a >> 32)); - unaligned_write_be32((be32_t*) u + 1, (uint32_t) a); +static inline void unaligned_write_be64(void *_u, uint64_t a) { + uint8_t *u = _u; + + unaligned_write_be32(u, (uint32_t) (a >> 32)); + unaligned_write_be32(u + 4, (uint32_t) a); } |