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

[xen master] xen/decompressors: Remove use of *_to_cpup() helpers



commit 60dcff871e34fd788bffccfcd5a936f7984d0a69
Author:     Lin Liu <lin.liu@xxxxxxxxxx>
AuthorDate: Thu Oct 21 02:52:39 2021 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri Apr 18 15:16:12 2025 +0100

    xen/decompressors: Remove use of *_to_cpup() helpers
    
    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@xxxxxxxxxx>
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 tools/libs/guest/xg_dom_decompress_lz4.c          | 10 ++++++++--
 tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c | 19 ++-----------------
 tools/libs/guest/xg_dom_decompress_unsafe_xz.c    | 15 ++++++++-------
 xen/common/lz4/defs.h                             |  8 ++++++--
 xen/common/unlzo.c                                | 16 ++++++++++++----
 xen/common/xz/private.h                           | 16 +++++++++++-----
 6 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/tools/libs/guest/xg_dom_decompress_lz4.c 
b/tools/libs/guest/xg_dom_decompress_lz4.c
index b26cce3ec5..53ef0bf328 100644
--- a/tools/libs/guest/xg_dom_decompress_lz4.c
+++ b/tools/libs/guest/xg_dom_decompress_lz4.c
@@ -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"
diff --git a/tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c 
b/tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c
index e58c1b95ed..ca2f37d915 100644
--- a/tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c
+++ b/tools/libs/guest/xg_dom_decompress_unsafe_lzo1x.c
@@ -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
diff --git a/tools/libs/guest/xg_dom_decompress_unsafe_xz.c 
b/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
index 80eed912dd..1f52875340 100644
--- a/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
+++ b/tools/libs/guest/xg_dom_decompress_unsafe_xz.c
@@ -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
diff --git a/xen/common/lz4/defs.h b/xen/common/lz4/defs.h
index ecfbf07f83..46ec467080 100644
--- a/xen/common/lz4/defs.h
+++ b/xen/common/lz4/defs.h
@@ -16,9 +16,13 @@
 #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
diff --git a/xen/common/unlzo.c b/xen/common/unlzo.c
index acb8dff600..9022c8f47d 100644
--- a/xen/common/unlzo.c
+++ b/xen/common/unlzo.c
@@ -37,14 +37,22 @@
 #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
diff --git a/xen/common/xz/private.h b/xen/common/xz/private.h
index 2299705378..d70b2ea6dc 100644
--- a/xen/common/xz/private.h
+++ b/xen/common/xz/private.h
@@ -16,19 +16,25 @@
 #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
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.