[PATCH 1/2] Add generic LE/BE load store uint type convertors

Max max.suraev at fairwaves.ru
Fri Jan 31 14:01:38 UTC 2014


---
 include/osmocom/core/bits.h | 291 +++++++++++++++++++++++++++++++++++++++++++-
 include/osmocom/core/msgb.h |  23 ++--
 src/gsm/libosmogsm.map      |  23 ++++
 tests/bits/bitrev_test.c    | 134 +++++++++++++++++++-
 tests/bits/bitrev_test.ok   |  15 +++
 5 files changed, 472 insertions(+), 14 deletions(-)

diff --git a/include/osmocom/core/bits.h b/include/osmocom/core/bits.h
index 4c68532..fa4d900 100644
--- a/include/osmocom/core/bits.h
+++ b/include/osmocom/core/bits.h
@@ -2,7 +2,7 @@
 #define _OSMO_BITS_H
 
 #include <stdint.h>
-
+#include <stddef.h>
 /*! \defgroup bits soft, unpacked and packed bits
  *  @{
  */
@@ -15,6 +15,285 @@ typedef int8_t  sbit_t;		/*!< \brief soft bit (-127...127) */
 typedef uint8_t ubit_t;		/*!< \brief unpacked bit (0 or 1) */
 typedef uint8_t pbit_t;		/*!< \brief packed bis (8 bits in a byte) */
 
+/* Load unaligned 16-bit integer (little-endian encoding) */
+static inline uint16_t osmo_load16le(const uint8_t *p)
+{
+	return ((uint16_t)p[0]) | ((uint16_t)p[1] << 8);
+}
+
+/* Load unaligned 16-bit integer (big-endian encoding) */
+static inline uint16_t osmo_load16be(const uint8_t *p)
+{
+	return ((uint16_t)p[0] << 8) | ((uint16_t)p[1]);
+}
+
+/* Load unaligned 24-bit integer (little-endian encoding) */
+static inline uint32_t osmo_load24le(const uint8_t *p)
+{
+	return ((uint32_t)p[0]) |
+		((uint32_t)p[1] << 8) |
+		((uint32_t)p[2] << 16);
+}
+
+/* Load unaligned 24-bit integer (big-endian encoding) */
+static inline uint32_t osmo_load24be(const uint8_t *p)
+{
+	return ((uint32_t)p[0] << 16) |
+		((uint32_t)p[1] << 8) |
+		((uint32_t)p[2]);
+}
+
+/* Load unaligned 32-bit integer (little-endian encoding) */
+static inline uint32_t osmo_load32le(const uint8_t *p)
+{
+	return ((uint32_t)p[0]) |
+		((uint32_t)p[1] << 8) |
+		((uint32_t)p[2] << 16) |
+		((uint32_t)p[3] << 24);
+}
+
+/* Load unaligned 32-bit integer (big-endian encoding) */
+static inline uint32_t osmo_load32be(const uint8_t *p)
+{
+	return ((uint32_t)p[0] << 24) |
+		((uint32_t)p[1] << 16) |
+		((uint32_t)p[2] << 8) |
+		((uint32_t)p[3]);
+}
+
+/* Load unaligned 40-bit integer (little-endian encoding) */
+static inline uint64_t osmo_load40le(const uint8_t *p)
+{
+	return ((uint64_t)p[0]) |
+		((uint64_t)p[1] << 8) |
+		((uint64_t)p[2] << 16) |
+		((uint64_t)p[3] << 24) |
+		((uint64_t)p[4] << 32);
+}
+
+/* Load unaligned 40-bit integer (big-endian encoding) */
+static inline uint64_t osmo_load40be(const uint8_t *p)
+{
+	return (((uint64_t)p[0]) << 32) |
+		((uint64_t)p[1] << 24) |
+		((uint64_t)p[2] << 16) |
+		((uint64_t)p[3] << 8) |
+		((uint64_t)p[4]);
+}
+
+/* Load unaligned 48-bit integer (little-endian encoding) */
+static inline uint64_t osmo_load48le(const uint8_t *p)
+{
+	return ((uint64_t)p[0]) |
+		((uint64_t)p[1] << 8) |
+		((uint64_t)p[2] << 16) |
+		((uint64_t)p[3] << 24) |
+		((uint64_t)p[4] << 32) |
+		((uint64_t)p[5] << 40);
+}
+
+/* Load unaligned 48-bit integer (big-endian encoding) */
+static inline uint64_t osmo_load48be(const uint8_t *p)
+{
+	return (((uint64_t)p[0]) << 40) |
+		((uint64_t)p[1] << 32) |
+		((uint64_t)p[2] << 24) |
+		((uint64_t)p[3] << 16) |
+		((uint64_t)p[4] << 8) |
+		((uint64_t)p[5]);
+}
+
+/* Load unaligned 56-bit integer (little-endian encoding) */
+static inline uint64_t osmo_load56le(const uint8_t *p)
+{
+	return ((uint64_t)p[0]) |
+		((uint64_t)p[1] << 8) |
+		((uint64_t)p[2] << 16) |
+		((uint64_t)p[3] << 24) |
+		((uint64_t)p[4] << 32) |
+		((uint64_t)p[5] << 40) |
+		((uint64_t)p[6] << 48);
+}
+
+/* Load unaligned 56-bit integer (big-endian encoding) */
+static inline uint64_t osmo_load56be(const uint8_t *p)
+{
+	return (((uint64_t)p[0]) << 48) |
+		((uint64_t)p[1] << 40) |
+		((uint64_t)p[2] << 32) |
+		((uint64_t)p[3] << 24) |
+		((uint64_t)p[4] << 16) |
+		((uint64_t)p[5] << 8) |
+		((uint64_t)p[6]);
+}
+
+/* Load unaligned 64-bit integer (little-endian encoding) */
+static inline uint64_t osmo_load64le(const uint8_t *p)
+{
+	return ((uint64_t)p[0]) |
+		((uint64_t)p[1] << 8) |
+		((uint64_t)p[2] << 16) |
+		((uint64_t)p[3] << 24) |
+		((uint64_t)p[4] << 32) |
+		((uint64_t)p[5] << 40) |
+		((uint64_t)p[6] << 48) |
+		((uint64_t)p[7] << 56);
+}
+
+/* Load unaligned 64-bit integer (big-endian encoding) */
+static inline uint64_t osmo_load64be(const uint8_t *p)
+{
+	return (((uint64_t)p[0]) << 56) |
+		((uint64_t)p[1] << 48) |
+		((uint64_t)p[2] << 40) |
+		((uint64_t)p[3] << 32) |
+		((uint64_t)p[4] << 24) |
+		((uint64_t)p[5] << 16) |
+		((uint64_t)p[6] << 8) |
+		((uint64_t)p[7]);
+}
+
+/* Store unaligned 16-bit integer (little-endian encoding) */
+static inline void osmo_store16le(uint16_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = (a) & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+}
+
+/* Store unaligned 16-bit integer (big-endian encoding) */
+static inline void osmo_store16be(uint16_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[1] = (a) & 0xFF;
+}
+
+/* Store unaligned 24-bit integer (little-endian encoding) */
+static inline void osmo_store24le(uint32_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = a & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 16) & 0xFF;
+}
+
+/* Store unaligned 24-bit integer (big-endian encoding) */
+static inline void osmo_store24be(uint32_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[2] = a & 0xFF;
+}
+
+/* Store unaligned 32-bit integer (little-endian encoding) */
+static inline void osmo_store32le(uint32_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = a & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 24) & 0xFF;
+}
+
+/* Store unaligned 32-bit integer (big-endian encoding) */
+static inline void osmo_store32be(uint32_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[1] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[3] = a & 0xFF;
+}
+
+/* Store unaligned 40-bit integer (little-endian encoding) */
+static inline void osmo_store40le(uint64_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = a & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[4] = (a >> 32) & 0xFF;
+}
+
+/* Store unaligned 40-bit integer (big-endian encoding) */
+static inline void osmo_store40be(uint64_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = (a >> 32) & 0xFF;
+	((uint8_t *)p)[1] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[4] = a & 0xFF;
+}
+
+/* Store unaligned 48-bit integer (little-endian encoding) */
+static inline void osmo_store48le(uint64_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = a & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[4] = (a >> 32) & 0xFF;
+	((uint8_t *)p)[5] = (a >> 40) & 0xFF;
+}
+
+/* Store unaligned 48-bit integer (big-endian encoding) */
+static inline void osmo_store48be(uint64_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = (a >> 40) & 0xFF;
+	((uint8_t *)p)[1] = (a >> 32) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[4] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[5] = a & 0xFF;
+}
+
+/* Store unaligned 56-bit integer (little-endian encoding) */
+static inline void osmo_store56le(uint64_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = a & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[4] = (a >> 32) & 0xFF;
+	((uint8_t *)p)[5] = (a >> 40) & 0xFF;
+	((uint8_t *)p)[6] = (a >> 48) & 0xFF;
+}
+
+/* Store unaligned 56-bit integer (big-endian encoding) */
+static inline void osmo_store56be(uint64_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = (a >> 48) & 0xFF;
+	((uint8_t *)p)[1] = (a >> 40) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 32) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[4] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[5] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[6] = a & 0xFF;
+}
+
+/* Store unaligned 64-bit integer (little-endian encoding) */
+static inline void osmo_store64le(uint64_t a, uint8_t *p)
+{
+	((uint8_t *)p)[0] = a & 0xFF;
+	((uint8_t *)p)[1] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[4] = (a >> 32) & 0xFF;
+	((uint8_t *)p)[5] = (a >> 40) & 0xFF;
+	((uint8_t *)p)[6] = (a >> 48) & 0xFF;
+	((uint8_t *)p)[7] = (a >> 56) & 0xFF;
+}
+
+/* Store unaligned 64-bit integer (big-endian encoding) */
+static inline void osmo_store64be(uint64_t a, uint8_t *p)
+{
+
+	((uint8_t *)p)[0] = (a >> 56) & 0xFF;
+	((uint8_t *)p)[1] = (a >> 48) & 0xFF;
+	((uint8_t *)p)[2] = (a >> 40) & 0xFF;
+	((uint8_t *)p)[3] = (a >> 32) & 0xFF;
+	((uint8_t *)p)[4] = (a >> 24) & 0xFF;
+	((uint8_t *)p)[5] = (a >> 16) & 0xFF;
+	((uint8_t *)p)[6] = (a >> 8) & 0xFF;
+	((uint8_t *)p)[7] = a & 0xFF;
+}
+
 /*
    NOTE on the endianess of pbit_t:
    Bits in a pbit_t are ordered MSB first, i.e. 0x80 is the first bit.
@@ -73,6 +352,16 @@ uint32_t osmo_revbytebits_8(uint8_t x);
 /* \brief reverse the bits of each byte in a given buffer */
 void osmo_revbytebits_buf(uint8_t *buf, int len);
 
+/* \brief reverse the order of the bytes in a given buffer */
+void osmo_revbytes_buf(uint8_t *buf, size_t len);
+
+/* \brief left circular shift */
+static inline uint16_t rol16(uint16_t in, unsigned shift)
+{
+    return (in << shift) | (in >> (16 - shift));
+}
+
+
 /*! @} */
 
 #endif /* _OSMO_BITS_H */
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h
index fe2733b..72fdc24 100644
--- a/include/osmocom/core/msgb.h
+++ b/include/osmocom/core/msgb.h
@@ -23,6 +23,7 @@
 #include <stdint.h>
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/utils.h>
+#include <osmocom/core/bits.h>
 
 /*! \defgroup msgb Message buffers
  *  @{
@@ -204,8 +205,7 @@ static inline void msgb_put_u8(struct msgb *msgb, uint8_t word)
 static inline void msgb_put_u16(struct msgb *msgb, uint16_t word)
 {
 	uint8_t *space = msgb_put(msgb, 2);
-	space[0] = word >> 8 & 0xFF;
-	space[1] = word & 0xFF;
+	osmo_store16be(word, space);
 }
 
 /*! \brief append a uint32 value to the end of the message
@@ -215,10 +215,7 @@ static inline void msgb_put_u16(struct msgb *msgb, uint16_t word)
 static inline void msgb_put_u32(struct msgb *msgb, uint32_t word)
 {
 	uint8_t *space = msgb_put(msgb, 4);
-	space[0] = word >> 24 & 0xFF;
-	space[1] = word >> 16 & 0xFF;
-	space[2] = word >> 8 & 0xFF;
-	space[3] = word & 0xFF;
+	osmo_store32be(word, space);
 }
 
 /*! \brief remove data from end of message
@@ -235,6 +232,7 @@ static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len)
 	msgb->len -= len;
 	return tmp;
 }
+
 /*! \brief remove uint8 from end of message
  *  \param[in] msgb message buffer
  *  \returns 8bit value taken from end of msgb
@@ -244,6 +242,7 @@ static inline uint8_t msgb_get_u8(struct msgb *msgb)
 	uint8_t *space = msgb_get(msgb, 1);
 	return space[0];
 }
+
 /*! \brief remove uint16 from end of message
  *  \param[in] msgb message buffer
  *  \returns 16bit value taken from end of msgb
@@ -251,8 +250,9 @@ static inline uint8_t msgb_get_u8(struct msgb *msgb)
 static inline uint16_t msgb_get_u16(struct msgb *msgb)
 {
 	uint8_t *space = msgb_get(msgb, 2);
-	return space[0] << 8 | space[1];
+	return osmo_load16be(space);
 }
+
 /*! \brief remove uint32 from end of message
  *  \param[in] msgb message buffer
  *  \returns 32bit value taken from end of msgb
@@ -260,7 +260,7 @@ static inline uint16_t msgb_get_u16(struct msgb *msgb)
 static inline uint32_t msgb_get_u32(struct msgb *msgb)
 {
 	uint8_t *space = msgb_get(msgb, 4);
-	return space[0] << 24 | space[1] << 16 | space[2] << 8 | space[3];
+	return osmo_load32be(space);
 }
 
 /*! \brief prepend (push) some data to start of message
@@ -284,6 +284,7 @@ static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len)
 	msgb->len += len;
 	return msgb->data;
 }
+
 /*! \brief remove (pull) a header from the front of the message buffer
  *  \param[in] msgb message buffer
  *  \param[in] len number of octets to be pulled
@@ -308,6 +309,7 @@ static inline uint8_t msgb_pull_u8(struct msgb *msgb)
 	uint8_t *space = msgb_pull(msgb, 1) - 1;
 	return space[0];
 }
+
 /*! \brief remove uint16 from front of message
  *  \param[in] msgb message buffer
  *  \returns 16bit value taken from end of msgb
@@ -315,8 +317,9 @@ static inline uint8_t msgb_pull_u8(struct msgb *msgb)
 static inline uint16_t msgb_pull_u16(struct msgb *msgb)
 {
 	uint8_t *space = msgb_pull(msgb, 2) - 2;
-	return space[0] << 8 | space[1];
+	return osmo_load16be(space);
 }
+
 /*! \brief remove uint32 from front of message
  *  \param[in] msgb message buffer
  *  \returns 32bit value taken from end of msgb
@@ -324,7 +327,7 @@ static inline uint16_t msgb_pull_u16(struct msgb *msgb)
 static inline uint32_t msgb_pull_u32(struct msgb *msgb)
 {
 	uint8_t *space = msgb_pull(msgb, 4) - 4;
-	return space[0] << 24 | space[1] << 16 | space[2] << 8 | space[3];
+	return osmo_load32be(space);
 }
 
 /*! \brief Increase headroom of empty msgb, reducing the tailroom
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 9d15d66..d54f940 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -22,6 +22,29 @@ abis_nm_test_name;
 
 osmo_sitype_strs;
 
+osmo_load16le;
+osmo_load16be;
+osmo_load24le;
+osmo_load24be;
+osmo_load32le;
+osmo_load32be;
+osmo_load64le;
+osmo_load64be;
+osmo_store16le;
+osmo_store16be;
+osmo_store24le;
+osmo_store24be;
+osmo_store32le;
+osmo_store32be;
+osmo_store40le;
+osmo_store40be;
+osmo_store48le;
+osmo_store48be;
+osmo_store56le;
+osmo_store56be;
+osmo_store64le;
+osmo_store64be;
+
 comp128;
 dbm2rxlev;
 
diff --git a/tests/bits/bitrev_test.c b/tests/bits/bitrev_test.c
index 5eca990..f82dbf3 100644
--- a/tests/bits/bitrev_test.c
+++ b/tests/bits/bitrev_test.c
@@ -1,4 +1,4 @@
-
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -12,9 +12,10 @@ static const uint8_t exp_out[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x0
 
 int main(int argc, char **argv)
 {
-	uint8_t out[ARRAY_SIZE(input)];
+	uint8_t out[ARRAY_SIZE(input)], test[8];
 	unsigned int offs;
-
+	char s[18], *p;
+	
 	for (offs = 0; offs < sizeof(out); offs++) {
 		uint8_t *start = out + offs;
 		uint8_t len = sizeof(out) - offs;
@@ -32,5 +33,132 @@ int main(int argc, char **argv)
 		printf("\n");
 	}
 
+	printf("checking byte packing...\n");
+
+	uint64_t _test64 = ((uint64_t)rand() << 32) + rand();
+	osmo_store64be(_test64, test);
+
+	snprintf(s, 17, "%.16" PRIx64, _test64);
+	p = osmo_hexdump_nospc(test, 8);
+	if (0 != memcmp(s, p, 8)) {
+		printf ("%s\t", s);
+		printf ("%s\t", p);
+		printf("64 BE FAILED!\n");
+	} else printf("64 BE OK\n");
+	
+	osmo_store64le(_test64, test);
+	if (osmo_load64le(test) == _test64)
+		printf("64 LE OK\n");
+	else
+		printf("64 LE FAILED: %s, %.16" PRIx64 ", %.16" PRIx64 "\n", osmo_hexdump(test, 8), osmo_load64le(test), _test64);
+
+
+	uint64_t _test56 = ((((uint64_t)rand() << 32) + rand()) << 8) >> 8;
+	osmo_store56be(_test56, test);
+
+	snprintf(s, 17, "%.14" PRIx64, _test56);
+	p = osmo_hexdump_nospc(test, 7);
+	if (0 != memcmp(s, p, 7)) {
+		printf ("%s\t", s);
+		printf ("%s\t", p);
+		printf("56 BE FAILED!\n");
+	} else printf("56 BE OK\n");
+	
+	osmo_store56le(_test56, test);
+	if (osmo_load56le(test) == _test56)
+		printf("56 LE OK\n");
+	else
+		printf("56 LE FAILED: %s, %.14" PRIx64 ", %.14" PRIx64 "\n", osmo_hexdump(test, 7), osmo_load56le(test), _test56);
+
+
+	uint64_t _test48 = ((((uint64_t)rand() << 32) + rand()) << 16) >> 16;
+	osmo_store48be(_test48, test);
+
+	snprintf(s, 17, "%.12" PRIx64, _test48);
+	p = osmo_hexdump_nospc(test, 6);
+	if (0 != memcmp(s, p, 6)) {
+		printf ("%s\t", s);
+		printf ("%s\t", p);
+		printf("48 BE FAILED!\n");
+	} else printf("48 BE OK\n");
+	
+	osmo_store48le(_test48, test);
+	if (osmo_load48le(test) == _test48)
+		printf("48 LE OK\n");
+	else
+		printf("48 LE FAILED: %s, %.12" PRIx64 ", %.12" PRIx64 "\n", osmo_hexdump(test, 6), osmo_load48le(test), _test48);
+
+
+	uint64_t _test40 = ((((uint64_t)rand() << 32) + rand()) << 24) >> 24;
+	osmo_store40be(_test40, test);
+
+	snprintf(s, 17, "%.10" PRIx64, _test40);
+	p = osmo_hexdump_nospc(test, 5);
+	if (0 != memcmp(s, p, 5)) {
+		printf ("%s\t", s);
+		printf ("%s\t", p);
+		printf("40 BE FAILED!\n");
+	} else printf("40 BE OK\n");
+	
+	osmo_store40le(_test40, test);
+	if (osmo_load40le(test) == _test40)
+		printf("40 LE OK\n");
+	else
+		printf("40 LE FAILED: %s, %.10" PRIx64 ", %.10" PRIx64 "\n", osmo_hexdump(test, 5), osmo_load40le(test), _test40);
+
+
+	uint32_t _test32 = (uint32_t)rand();
+	osmo_store32be(_test32, test);
+
+	snprintf(s, 17, "%.8" PRIx32, _test32);
+	p = osmo_hexdump_nospc(test, 4);
+	if (0 != memcmp(s, p, 4)) {
+		printf ("%s\t", s);
+		printf ("%s\t", p);
+		printf("32 BE FAILED!\n");
+	} else printf("32 BE OK\n");
+	
+	osmo_store32le(_test32, test);
+	if (osmo_load32le(test) == _test32)
+		printf("32 LE OK\n");
+	else
+		printf("32 LE FAILED: %s, %.8" PRIx32 ", %.8" PRIx32 "\n", osmo_hexdump(test, 4), osmo_load32le(test), _test32);
+
+
+	uint32_t _test24 = ((uint32_t)rand() << 8) >> 8;
+	osmo_store24be(_test24, test);
+
+	snprintf(s, 17, "%.6" PRIx32, _test24);
+	p = osmo_hexdump_nospc(test, 3);
+	if (0 != memcmp(s, p, 3)) {
+		printf ("%s\t", s);
+		printf ("%s\t", p);
+		printf("24 BE FAILED!\n");
+	} else printf("24 BE OK\n");
+	
+	osmo_store24le(_test24, test);
+	if (osmo_load24le(test) == _test24)
+		printf("24 LE OK\n");
+	else
+		printf("24 LE FAILED: %s, %.6" PRIx32 ", %.6" PRIx32 "\n", osmo_hexdump(test, 3), osmo_load24le(test), _test24);
+
+
+	uint16_t _test16 = (uint16_t)rand();
+	osmo_store16be(_test16, test);
+
+	snprintf(s, 17, "%.4" PRIx16, _test16);
+	p = osmo_hexdump_nospc(test, 2);
+	if (0 != memcmp(s, p, 2)) {
+		printf ("%s\t", s);
+		printf ("%s\t", p);
+		printf("16 BE FAILED!\n");
+	} else printf("16 BE OK\n");
+	
+	osmo_store16le(_test16, test);
+	if (osmo_load16le(test) == _test16)
+		printf("16 LE OK\n");
+	else
+		printf("16 LE FAILED: %s, %.4" PRIx16 ", %.4" PRIx16 "\n", osmo_hexdump(test, 2), osmo_load16le(test), _test16);
+
 	return 0;
 }
diff --git a/tests/bits/bitrev_test.ok b/tests/bits/bitrev_test.ok
index 47f402f..e319af2 100644
--- a/tests/bits/bitrev_test.ok
+++ b/tests/bits/bitrev_test.ok
@@ -22,3 +22,18 @@ REVERSED: 02 01
 INORDER:  80 
 REVERSED: 01 
 
+checking byte packing...
+64 BE OK
+64 LE OK
+56 BE OK
+56 LE OK
+48 BE OK
+48 LE OK
+40 BE OK
+40 LE OK
+32 BE OK
+32 LE OK
+24 BE OK
+24 LE OK
+16 BE OK
+16 LE OK
-- 
1.8.3.2


--------------060209070104080702030101
Content-Type: text/x-patch;
 name="0002-Add-Kasumi-cipher-implementation.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0002-Add-Kasumi-cipher-implementation.patch"



More information about the baseband-devel mailing list