[libbdplus-devel] Replace byteswapping macros with inline functions

anonymous git at videolan.org
Thu Mar 16 13:24:52 CET 2017


libbdplus | branch: master | anonymous <anonymous at anonymous.org> | Thu Mar 16 13:46:54 2017 +0200| [089f21879cff9786bb852c98528338a59df3437a] | committer: anonymous

Replace byteswapping macros with inline functions

> http://git.videolan.org/gitweb.cgi/libbdplus.git/?a=commit;h=089f21879cff9786bb852c98528338a59df3437a
---

 src/util/macro.h | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/src/util/macro.h b/src/util/macro.h
index 6774c1e..fcbc2e6 100644
--- a/src/util/macro.h
+++ b/src/util/macro.h
@@ -36,18 +36,43 @@
  */
 
 // endian safe fetch
-#define FETCH4(X) (uint32_t)(((X)[0]<<24)|(X)[1]<<16|(X)[2]<<8|(X)[3])
-#define FETCHU2(X) (uint32_t)((uint16_t)(((X)[0]<<8)|(X)[1]))
 
-// Sign extended version
-#define FETCHS2(X) (int32_t)((int16_t)(((X)[0]<<8)|(X)[1]))
-
-#define STORE8(X, Y) (X)[7]=((Y)&0xff);(X)[6]=(((Y)>>8)&0xff);(X)[5]=(((Y)>>16)&0xff);(X)[4]=(((Y)>>24)&0xff);(X)[3]=(((Y)>>32)&0xff);(X)[2]=(((Y)>>40)&0xff);(X)[1]=(((Y)>>48)&0xff);(X)[0]=(((Y)>>56)&0xff);
+//#define FETCH4(X) (uint32_t)(((uint32_t)(X)[0]<<24)|(X)[1]<<16|(X)[2]<<8|(X)[3])
+static inline uint32_t FETCH4(const void *pv) {
+  const uint8_t *p = pv;
+  return (uint32_t)p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
 
-#define STORE4(X, Y) (X)[3]=((Y)&0xff);(X)[2]=(((Y)>>8)&0xff);(X)[1]=(((Y)>>16)&0xff);(X)[0]=(((Y)>>24)&0xff);
+//#define FETCHU2(X) (uint32_t)((uint16_t)(((X)[0]<<8)|(X)[1]))
+static inline uint32_t FETCHU2(const void *pv) {
+  const uint8_t *p = pv;
+  return (uint32_t)p[0] << 8 | p[1];
+}
 
-#define STORE2(X, Y) (X)[1]=(((Y))&0xff);(X)[0]=(((Y)>>8)&0xff);
+// Sign extended version
+//#define FETCHS2(X) (int32_t)((int16_t)(((X)[0]<<8)|(X)[1]))
+static inline int32_t FETCHS2(const void *pv) {
+  return (int32_t)(int16_t)FETCHU2(pv);
+}
 
+//#define STORE2(X, Y) (X)[1]=(((Y))&0xff);(X)[0]=(((Y)>>8)&0xff);
+static inline void STORE2(void *pv, uint32_t v) {
+  uint8_t *p = pv;
+  p[1] = v;
+  p[0] = v >> 8;
+}
+//#define STORE4(X, Y) (X)[3]=((Y)&0xff);(X)[2]=(((Y)>>8)&0xff);(X)[1]=(((Y)>>16)&0xff);(X)[0]=(((Y)>>24)&0xff);
+static inline void STORE4(void *pv, uint32_t v) {
+  uint8_t *p = pv;
+  STORE2(p + 2, v);
+  STORE2(p,     v >> 16);
+}
+//#define STORE8(X, Y) (X)[7]=((Y)&0xff);(X)[6]=(((Y)>>8)&0xff);(X)[5]=(((Y)>>16)&0xff);(X)[4]=(((Y)>>24)&0xff);(X)[3]=(((Y)>>32)&0xff);(X)[2]=(((Y)>>40)&0xff);(X)[1]=(((Y)>>48)&0xff);(X)[0]=(((Y)>>56)&0xff);
+static inline void STORE8(void *pv, uint64_t v) {
+  uint8_t *p = pv;
+  STORE4(p + 4, v);
+  STORE4(p,     v >> 32);
+}
 
 
 /*



More information about the libbdplus-devel mailing list