gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] 01/02: mhd_bithelpers.h: fixed macro for BE


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 01/02: mhd_bithelpers.h: fixed macro for BE mode, added macros to GET/PUT data in BE mode, added macro for bits rotation
Date: Fri, 19 Apr 2019 08:18:23 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 0b8c463dd87a739075518e3c48792e259171ca2e
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Fri Apr 19 09:08:53 2019 +0300

    mhd_bithelpers.h: fixed macro for BE mode, added macros to GET/PUT
    data in BE mode, added macro for bits rotation
---
 src/microhttpd/mhd_bithelpers.h | 107 ++++++++++++++++++++++++++++++++--------
 1 file changed, 87 insertions(+), 20 deletions(-)

diff --git a/src/microhttpd/mhd_bithelpers.h b/src/microhttpd/mhd_bithelpers.h
index d4a47ce4..bf20293f 100644
--- a/src/microhttpd/mhd_bithelpers.h
+++ b/src/microhttpd/mhd_bithelpers.h
@@ -29,32 +29,99 @@
 #include "mhd_byteorder.h"
 #include <stdint.h>
 
-
+/* _MHD_PUT_64BIT_LE (addr, value64)
+ * put native-endian 64-bit value64 to addr
+ * in little-endian mode.
+ */
 #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
-#define _MHD_PUT_64BIT_LE(addr, value64) \
-  ((*(uint64_t*)(addr)) = (uint64_t)(value64))
+#define _MHD_PUT_64BIT_LE(addr, value64)             \
+        ((*(uint64_t*)(addr)) = (uint64_t)(value64))
 #else  /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
-#define _MHD_PUT_64BIT_LE(addr, value64) do {                           \
-        (uint8_t*(addr))[7] = (uint8_t)((value64) >> 56);               \
-        (uint8_t*(addr))[6] = (uint8_t)((value64) >> 48);               \
-        (uint8_t*(addr))[5] = (uint8_t)((value64) >> 40);               \
-        (uint8_t*(addr))[4] = (uint8_t)((value64) >> 32);               \
-        (uint8_t*(addr))[3] = (uint8_t)((value64) >> 24);               \
-        (uint8_t*(addr))[2] = (uint8_t)((value64) >> 16);               \
-        (uint8_t*(addr))[1] = (uint8_t)((value64) >> 8);                \
-        (uint8_t*(addr))[0] = (uint8_t)((value64)); } while (0)
+#define _MHD_PUT_64BIT_LE(addr, value64) do {                            \
+        ((uint8_t*)(addr))[0] = (uint8_t)((uint64_t)(value64));           \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint64_t)(value64)) >> 8);    \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint64_t)(value64)) >> 16);   \
+        ((uint8_t*)(addr))[3] = (uint8_t)(((uint64_t)(value64)) >> 24);   \
+        ((uint8_t*)(addr))[4] = (uint8_t)(((uint64_t)(value64)) >> 32);   \
+        ((uint8_t*)(addr))[5] = (uint8_t)(((uint64_t)(value64)) >> 40);   \
+        ((uint8_t*)(addr))[6] = (uint8_t)(((uint64_t)(value64)) >> 48);   \
+        ((uint8_t*)(addr))[7] = (uint8_t)(((uint64_t)(value64)) >> 56);   \
+        } while (0)
 #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
 
+/* _MHD_PUT_32BIT_LE (addr, value32)
+ * put native-endian 32-bit value32 to addr
+ * in little-endian mode.
+ */
 #if _MHD_BYTE_ORDER == _MHD_LITTLE_ENDIAN
-#define _MHD_PUT_32BIT_LE(addr, value32) \
-  ((*(uint32_t*)(addr)) = (uint32_t)(value32))
+#define _MHD_PUT_32BIT_LE(addr, value32)             \
+        ((*(uint32_t*)(addr)) = (uint32_t)(value32))
 #else  /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
-
-#define _MHD_PUT_32BIT_LE(addr, value32) do {                           \
-        (uint8_t*(addr))[3] = (uint8_t)((value32) >> 24);               \
-        (uint8_t*(addr))[2] = (uint8_t)((value32) >> 16);               \
-        (uint8_t*(addr))[1] = (uint8_t)((value32) >> 8);                \
-        (uint8_t*(addr))[0] = (uint8_t)((value32)); } while (0)
+#define _MHD_PUT_32BIT_LE(addr, value32) do {                            \
+        ((uint8_t*)(addr))[0] = (uint8_t)((uint32_t)(value32));           \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint32_t)(value32)) >> 8);    \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint32_t)(value32)) >> 16);   \
+        ((uint8_t*)(addr))[3] = (uint8_t)(((uint32_t)(value32)) >> 24);   \
+        } while (0)
 #endif /* _MHD_BYTE_ORDER != _MHD_LITTLE_ENDIAN */
 
+
+/* _MHD_PUT_64BIT_BE (addr, value64)
+ * put native-endian 64-bit value64 to addr
+ * in big-endian mode.
+ */
+#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
+#define _MHD_PUT_64BIT_BE(addr, value64)             \
+        ((*(uint64_t*)(addr)) = (uint64_t)(value64))
+#else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+#define _MHD_PUT_64BIT_BE(addr, value64) do {                            \
+        ((uint8_t*)(addr))[7] = (uint8_t)((uint64_t)(value64));           \
+        ((uint8_t*)(addr))[6] = (uint8_t)(((uint64_t)(value64)) >> 8);    \
+        ((uint8_t*)(addr))[5] = (uint8_t)(((uint64_t)(value64)) >> 16);   \
+        ((uint8_t*)(addr))[4] = (uint8_t)(((uint64_t)(value64)) >> 24);   \
+        ((uint8_t*)(addr))[3] = (uint8_t)(((uint64_t)(value64)) >> 32);   \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint64_t)(value64)) >> 40);   \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint64_t)(value64)) >> 48);   \
+        ((uint8_t*)(addr))[0] = (uint8_t)(((uint64_t)(value64)) >> 56);   \
+        } while (0)
+#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+
+/* _MHD_PUT_32BIT_BE (addr, value32)
+ * put native-endian 32-bit value32 to addr
+ * in big-endian mode.
+ */
+#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
+#define _MHD_PUT_32BIT_BE(addr, value32)             \
+        ((*(uint32_t*)(addr)) = (uint32_t)(value32))
+#else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+#define _MHD_PUT_32BIT_BE(addr, value32) do {                            \
+        ((uint8_t*)(addr))[3] = (uint8_t)((uint32_t)(value32));           \
+        ((uint8_t*)(addr))[2] = (uint8_t)(((uint32_t)(value32)) >> 8);    \
+        ((uint8_t*)(addr))[1] = (uint8_t)(((uint32_t)(value32)) >> 16);   \
+        ((uint8_t*)(addr))[0] = (uint8_t)(((uint32_t)(value32)) >> 24);   \
+        } while (0)
+#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+
+/* _MHD_GET_32BIT_BE (addr)
+ * get big-endian 32-bit value storied at addr
+ * and return it in native-endian mode.
+ */
+#if _MHD_BYTE_ORDER == _MHD_BIG_ENDIAN
+#define _MHD_GET_32BIT_BE(addr)             \
+        (*(uint32_t*)(addr))
+#else  /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+#define _MHD_GET_32BIT_BE(addr)                       \
+        ( (((uint32_t)(((uint8_t*)addr)[0])) << 24) | \
+          (((uint32_t)(((uint8_t*)addr)[1])) << 16) | \
+          (((uint32_t)(((uint8_t*)addr)[2])) << 8)  | \
+          ((uint32_t) (((uint8_t*)addr)[3])) )
+#endif /* _MHD_BYTE_ORDER != _MHD_BIG_ENDIAN */
+
+/**
+ * Rotate right 32-bit value by number of bits.
+ * bits parameter must be more than zero and must be less than 32.
+ * Defined in form which modern compiler could optimize.
+ */
+#define _MHD_ROTR32(value32, bits) ((value32) >> (bits) | (value32) << (32 - 
bits))
+
 #endif /* ! MHD_BITHELPERS_H */

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]