shared/util: Add conversion function for 24 bits
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 4 Aug 2020 23:42:31 +0000 (16:42 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:36 +0000 (19:08 +0530)
This adds get/put 24 bits variants.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/shared/util.h

index 6090837..ac70117 100755 (executable)
@@ -131,6 +131,20 @@ static inline uint16_t get_be16(const void *ptr)
        return be16_to_cpu(get_unaligned((const uint16_t *) ptr));
 }
 
+static inline uint32_t get_le24(const void *ptr)
+{
+       const uint8_t *src = ptr;
+
+       return ((uint32_t)src[2] << 16) | get_le16(ptr);
+}
+
+static inline uint32_t get_be24(const void *ptr)
+{
+       const uint8_t *src = ptr;
+
+       return ((uint32_t)src[0] << 16) | get_be16(&src[1]);
+}
+
 static inline uint32_t get_le32(const void *ptr)
 {
        return le32_to_cpu(get_unaligned((const uint32_t *) ptr));
@@ -161,6 +175,18 @@ static inline void put_be16(uint16_t val, const void *ptr)
        put_unaligned(cpu_to_be16(val), (uint16_t *) ptr);
 }
 
+static inline void put_le24(uint32_t val, void *ptr)
+{
+       put_le16(val, ptr);
+       put_unaligned(val >> 16, (uint8_t *) ptr + 2);
+}
+
+static inline void put_be24(uint32_t val, void *ptr)
+{
+       put_unaligned(val >> 16, (uint8_t *) ptr + 2);
+       put_be16(val, ptr + 1);
+}
+
 static inline void put_le32(uint32_t val, void *dst)
 {
        put_unaligned(cpu_to_le32(val), (uint32_t *) dst);