]> xenbits.xensource.com Git - people/andrewcoop/xen.git/commitdiff
xen/decompressors: Remove use of *_to_cpup() helpers
authorLin Liu <lin.liu@citrix.com>
Thu, 21 Oct 2021 02:52:39 +0000 (02:52 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 18 Apr 2025 14:16:12 +0000 (15:16 +0100)
These wrappers simply hide a deference, which adds to the cognitive complexity
of reading the code.  As such, they're not going to be included in the new
byteswap infrastructure.

No functional change.

Signed-off-by: Lin Liu <lin.liu@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
tools/libs/guest/xg_dom_decompress_lz4.c
tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c
tools/libs/guest/xg_dom_decompress_unsafe_xz.c
xen/common/lz4/defs.h
xen/common/unlzo.c
xen/common/xz/private.h

index b26cce3ec532db975383a9701073e2c771852dde..53ef0bf328ed6a68e31ed15e920cae392eb37cf5 100644 (file)
@@ -3,6 +3,8 @@
 #include <inttypes.h>
 #include <stdint.h>
 
+#include INCLUDE_ENDIAN_H
+
 #define XG_NEED_UNALIGNED
 #include "xg_private.h"
 #include "xg_dom_decompress.h"
@@ -17,9 +19,13 @@ typedef uint64_t u64;
 #define likely(a) a
 #define unlikely(a) a
 
-static inline uint_fast16_t le16_to_cpup(const unsigned char *buf)
+static inline uint16_t le16_to_cpu(uint16_t v)
 {
-    return buf[0] | (buf[1] << 8);
+#if BYTE_ORDER == BIG_ENDIAN
+    return __builtin_bswap16(v);
+#else
+    return v;
+#endif
 }
 
 #include "../../xen/include/xen/lz4.h"
index e58c1b95ed17c043cff7d26f6e6ad18aeb48b68b..ca2f37d915047fff375da4535af1eaa23001afc1 100644 (file)
@@ -16,25 +16,10 @@ typedef uint64_t u64;
 #define noinline
 #define unlikely(a) a
 
-static inline u16 be16_to_cpup(const u16 *p)
+static inline uint16_t be16_to_cpu(const uint16_t v)
 {
-       u16 v = *p;
 #if BYTE_ORDER == LITTLE_ENDIAN
-       return (((v & 0x00ffU) << 8) |
-                ((v & 0xff00U) >> 8));
-#else
-       return v;
-#endif
-}
-
-static inline u32 be32_to_cpup(const u32 *p)
-{
-       u32 v = *p;
-#if BYTE_ORDER == LITTLE_ENDIAN
-       return (((v & 0x000000ffUL) << 24) |
-                ((v & 0x0000ff00UL) <<  8) |
-                ((v & 0x00ff0000UL) >>  8) |
-                ((v & 0xff000000UL) >> 24));
+       return __builtin_bswap16(v);
 #else
        return v;
 #endif
index 80eed912dd6822b1145baa9490c31aa3bb06b6c2..1f5287534012616ff4c19a56ddff1b676694e823 100644 (file)
@@ -16,21 +16,22 @@ typedef uint16_t u16;
 typedef uint32_t u32;
 typedef uint32_t __le32;
 
-static inline u32 cpu_to_le32(const u32 v)
+static inline uint32_t cpu_to_le32(const uint32_t v)
 {
 #if BYTE_ORDER == BIG_ENDIAN
-       return (((v & 0x000000ffUL) << 24) |
-               ((v & 0x0000ff00UL) <<  8) |
-               ((v & 0x00ff0000UL) >>  8) |
-               ((v & 0xff000000UL) >> 24));
+       return __builtin_bswap32(v);
 #else
        return v;
 #endif
 }
 
-static inline u32 le32_to_cpup(const u32 *p)
+static inline uint32_t le32_to_cpu(const uint32_t p)
 {
-       return cpu_to_le32(*p);
+#if BYTE_ORDER == BIG_ENDIAN
+       return __builtin_bswap32(v);
+#else
+       return v;
+#endif
 }
 
 #define __force
index ecfbf07f832378edd40b5536fc4a48ea86b853a4..46ec46708061da915e00b61ce058bde6e4353f23 100644 (file)
 #include <xen/unaligned.h>
 #else
 
-static inline u16 get_unaligned_le16(const void *p)
+static inline uint16_t get_unaligned_le16(const void *p)
 {
-       return le16_to_cpup(p);
+       uint16_t v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return le16_to_cpu(v);
 }
 
 #endif
index acb8dff600fcb43eb773b8bd1027bedaa2a0ea53..9022c8f47db67d3e544ee511af998a192660d115 100644 (file)
 #include <xen/unaligned.h>
 #else
 
-static inline u16 get_unaligned_be16(const void *p)
+static inline uint16_t get_unaligned_be16(const void *p)
 {
-       return be16_to_cpup(p);
+       uint16_t v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return be16_to_cpu(v);
 }
 
-static inline u32 get_unaligned_be32(const void *p)
+static inline uint32_t get_unaligned_be32(const void *p)
 {
-       return be32_to_cpup(p);
+       uint32_t v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return be32_to_cpu(v);
 }
 
 #endif
index 2299705378ac612d1f6dbcf099ae7c1baec7620c..d70b2ea6dc21e893b69a5cc39da1c11fe2ff8c59 100644 (file)
 #include <xen/unaligned.h>
 #else
 
-static inline u32 get_unaligned_le32(const void *p)
+static inline uint32_t get_unaligned_le32(const void *p)
 {
-       return le32_to_cpup(p);
+       uint32_t v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return le32_to_cpu(v);
 }
 
-static inline void put_unaligned_le32(u32 val, void *p)
+static inline void put_unaligned_le32(uint32_t val, void *p)
 {
-       *(__force __le32*)p = cpu_to_le32(val);
+       uint32_t v = cpu_to_le32(val);
+
+       memcpy(p, &v, sizeof(v));
 }
 
 #endif
 
-#define get_le32(p) le32_to_cpup((const uint32_t *)(p))
+#define get_le32(p) le32_to_cpu(*(const uint32_t *)(p))
 
 #define false 0
 #define true 1