summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix von Leitner <felix-libowfat@fefe.de>2017-11-15 14:09:06 +0000
committerFelix von Leitner <felix-libowfat@fefe.de>2017-11-15 14:09:06 +0000
commitf7078fbd432ff92be372f39129dd6b11835dc11b (patch)
treedb43751829506bc1bcd420a3094ce7d9141cc0aa
parent62fc452335063febfb09372d30fb2bbad1b260f8 (diff)
downloadlibowfat-f7078fbd432ff92be372f39129dd6b11835dc11b.tar.gz
libowfat-f7078fbd432ff92be372f39129dd6b11835dc11b.zip
support __builtin_swap16 and __builtin_swap32
-rw-r--r--uint16.h19
-rw-r--r--uint32.h19
2 files changed, 38 insertions, 0 deletions
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);