diff --git a/uint16.h b/uint16.h index 53c6d1c..091e51a 100644 --- a/uint16.h +++ b/uint16.h @@ -25,9 +25,28 @@ static inline uint16 uint16_read(const char* in) { return *(const uint16*)in; } +#if defined(__x86_64__) && defined(__GNUC__) + +static inline void uint16_pack_big(char* out,uint16 in) { + *(uint16*)out=__builtin_bswap16(in); +} + +static inline void uint16_unpack_big(const char *in,uint16* out) { + *out=__builtin_bswap16(*(const uint16*)in); +} + +static inline uint16 uint16_read_big(const char* in) { + return __builtin_bswap16(*(const uint16*)in); +} + +#else + void uint16_pack_big(char *out,uint16 in); void uint16_unpack_big(const char *in,uint16* out); uint16 uint16_read_big(const char *in); + +#endif + #else void uint16_pack(char *out,uint16 in); diff --git a/uint32.h b/uint32.h index eb3f6cc..fb94f0e 100644 --- a/uint32.h +++ b/uint32.h @@ -25,9 +25,28 @@ static inline uint32 uint32_read(const char* in) { return *(const uint32*)in; } +#if defined(__x86_64__) && defined(__GNUC__) + +static inline void uint32_pack_big(char *out,uint32 in) { + *(uint32*)out=__builtin_bswap32(in); +} + +static inline void uint32_unpack_big(const char *in,uint32* out) { + *out=__builtin_bswap32(*(const uint32*)in); +} + +static inline uint32 uint32_read_big(const char *in) { + return __builtin_bswap32(*(const uint32*)in); +} + +#else + void uint32_pack_big(char *out,uint32 in); void uint32_unpack_big(const char *in,uint32* out); uint32 uint32_read_big(const char *in); + +#endif + #else void uint32_pack(char *out,uint32 in);