| [160] | 1 | #ifndef SRL_ENDIANNESS_H_ | 
|---|
|  | 2 | #define SRL_ENDIANNESS_H_ | 
|---|
|  | 3 |  | 
|---|
|  | 4 | #include "srl_public_types.h" | 
|---|
|  | 5 |  | 
|---|
|  | 6 | /** @this reads a big endian 16 bits value */ | 
|---|
| [228] | 7 | #  define endian_le16(x)    (x) | 
|---|
| [160] | 8 | /** @this reads a big endian 32 bits value */ | 
|---|
| [228] | 9 | #  define endian_le32(x)    (x) | 
|---|
| [160] | 10 | /** @this reads a big endian 64 bits value */ | 
|---|
| [228] | 11 | //#  define endian_le64(x)    (x) | 
|---|
| [160] | 12 | /** @this reads a little endian 16 bits value */ | 
|---|
| [228] | 13 | #  define endian_be16(x)    endian_swap16(x) | 
|---|
| [160] | 14 | /** @this reads a little endian 32 bits value */ | 
|---|
| [228] | 15 | #  define endian_be32(x)    endian_swap32(x) | 
|---|
| [160] | 16 | /** @this reads a little endian 64 bits value */ | 
|---|
| [228] | 17 | //#  define endian_be64(x)    endian_swap64(x) | 
|---|
| [160] | 18 |  | 
|---|
|  | 19 | /** @internal */ | 
|---|
| [228] | 20 | static inline uint16_t endian_swap16(uint16_t x) { | 
|---|
|  | 21 | return (x >> 8) | (x << 8); | 
|---|
| [160] | 22 | } | 
|---|
|  | 23 |  | 
|---|
| [228] | 24 |  | 
|---|
| [160] | 25 | /** @internal */ | 
|---|
| [228] | 26 | static inline uint32_t endian_swap32(uint32_t x) { | 
|---|
|  | 27 | return (((x >> 24) & 0x000000ff) | | 
|---|
|  | 28 | ((x >> 8 ) & 0x0000ff00) | | 
|---|
|  | 29 | ((x << 8 ) & 0x00ff0000) | | 
|---|
|  | 30 | ((x << 24) & 0xff000000)); | 
|---|
| [160] | 31 | } | 
|---|
|  | 32 |  | 
|---|
| [228] | 33 |  | 
|---|
| [160] | 34 | /** @internal *//* | 
|---|
| [228] | 35 | static inline uint64_t __endian_swap64(uint64_t x) | 
|---|
|  | 36 | { | 
|---|
|  | 37 | return (((uint64_t)endian_swap32(x      ) << 32) | | 
|---|
|  | 38 | ((uint64_t)endian_swap32(x >> 32)      )); | 
|---|
|  | 39 | }*/ | 
|---|
| [160] | 40 |  | 
|---|
| [228] | 41 | static inline uint32_t srl_uint32_le_to_machine(uint32_t x) { | 
|---|
|  | 42 | return endian_le32(x); | 
|---|
| [160] | 43 | } | 
|---|
|  | 44 |  | 
|---|
| [228] | 45 |  | 
|---|
|  | 46 | static inline uint32_t srl_uint32_machine_to_le(uint32_t x) { | 
|---|
|  | 47 | return endian_le32(x); | 
|---|
| [160] | 48 | } | 
|---|
|  | 49 |  | 
|---|
| [228] | 50 |  | 
|---|
|  | 51 | static inline uint32_t srl_uint32_be_to_machine(uint32_t x) { | 
|---|
|  | 52 | return endian_be32(x); | 
|---|
| [160] | 53 | } | 
|---|
|  | 54 |  | 
|---|
| [228] | 55 |  | 
|---|
|  | 56 | static inline uint32_t srl_uint32_machine_to_be(uint32_t x) { | 
|---|
|  | 57 | return endian_be32(x); | 
|---|
| [160] | 58 | } | 
|---|
|  | 59 |  | 
|---|
| [228] | 60 |  | 
|---|
|  | 61 | static inline uint16_t srl_uint16_le_to_machine(uint16_t x) { | 
|---|
|  | 62 | return endian_le16(x); | 
|---|
| [160] | 63 | } | 
|---|
|  | 64 |  | 
|---|
| [228] | 65 |  | 
|---|
|  | 66 | static inline uint16_t srl_uint16_machine_to_le(uint16_t x) { | 
|---|
|  | 67 | return endian_le16(x); | 
|---|
| [160] | 68 | } | 
|---|
|  | 69 |  | 
|---|
| [228] | 70 |  | 
|---|
|  | 71 | static inline uint16_t srl_uint16_be_to_machine(uint16_t x) { | 
|---|
|  | 72 | return endian_be16(x); | 
|---|
| [160] | 73 | } | 
|---|
|  | 74 |  | 
|---|
| [228] | 75 |  | 
|---|
|  | 76 | static inline uint16_t srl_uint16_machine_to_be(uint16_t x) { | 
|---|
|  | 77 | return endian_be16(x); | 
|---|
| [160] | 78 | } | 
|---|
|  | 79 |  | 
|---|
|  | 80 |  | 
|---|
|  | 81 | #endif | 
|---|
| [228] | 82 |  | 
|---|
|  | 83 |  | 
|---|
|  | 84 | // Local Variables: | 
|---|
|  | 85 | // tab-width: 4 | 
|---|
|  | 86 | // c-basic-offset: 4 | 
|---|
|  | 87 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
|  | 88 | // indent-tabs-mode: nil | 
|---|
|  | 89 | // End: | 
|---|
|  | 90 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
|  | 91 |  | 
|---|