]> 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, 28 Mar 2025 14:12:39 +0000 (14:12 +0000)
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>
---
CC: Anthony PERARD <anthony.perard@vates.tech>
CC: Michal Orzel <michal.orzel@amd.com>
CC: Jan Beulich <jbeulich@suse.com>
CC: Julien Grall <julien@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
CC: Bertrand Marquis <bertrand.marquis@arm.com>
CC: Shawn Anastasio <sanastasio@raptorengineering.com>
CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
CC: Daniel P. Smith <dpsmith@apertussolutions.com>
CC: Lin Liu <lin.liu@citrix.com>
v6:
 * Fix lz4 and lzo1x too.

v5:
 * Rebase
 * Rearranged from other patches

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..3f6b133ccf9dec4a9950f70b1680a407d53ffded 100644 (file)
@@ -16,25 +16,19 @@ typedef uint64_t u64;
 #define noinline
 #define unlikely(a) a
 
-static inline u16 be16_to_cpup(const u16 *p)
+static inline u16 be16_to_cpu(const u16 v)
 {
-       u16 v = *p;
 #if BYTE_ORDER == LITTLE_ENDIAN
-       return (((v & 0x00ffU) << 8) |
-                ((v & 0xff00U) >> 8));
+       return __builtin_bswap16(v);
 #else
        return v;
 #endif
 }
 
-static inline u32 be32_to_cpup(const u32 *p)
+static inline u32 be32_to_cpup(const u32 v)
 {
-       u32 v = *p;
 #if BYTE_ORDER == LITTLE_ENDIAN
-       return (((v & 0x000000ffUL) << 24) |
-                ((v & 0x0000ff00UL) <<  8) |
-                ((v & 0x00ff0000UL) >>  8) |
-                ((v & 0xff000000UL) >> 24));
+       return __builtin_bswap32(v);
 #else
        return v;
 #endif
index 80eed912dd6822b1145baa9490c31aa3bb06b6c2..7dbd2622c3b8d5c3e27cb6a8c311060f7d8e1689 100644 (file)
@@ -19,18 +19,19 @@ typedef uint32_t __le32;
 static inline u32 cpu_to_le32(const u32 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 u32 le32_to_cpu(const u32 p)
 {
-       return cpu_to_le32(*p);
+#if BYTE_ORDER == BIG_ENDIAN
+        return __builtin_bswap32(v);
+#else
+       return v;
+#endif
 }
 
 #define __force
index ecfbf07f832378edd40b5536fc4a48ea86b853a4..e477806634c1501c9fdfa410269301a1176400b2 100644 (file)
 
 static inline u16 get_unaligned_le16(const void *p)
 {
-       return le16_to_cpup(p);
+       u16 v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return le16_to_cpu(v);
 }
 
 #endif
index acb8dff600fcb43eb773b8bd1027bedaa2a0ea53..17efb1cc8f1daca2fe57522eb7305520e40b4541 100644 (file)
 
 static inline u16 get_unaligned_be16(const void *p)
 {
-       return be16_to_cpup(p);
+       u16 v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return be16_to_cpu(v);
 }
 
 static inline u32 get_unaligned_be32(const void *p)
 {
-       return be32_to_cpup(p);
+       u32 v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return be32_to_cpu(v);
 }
 
 #endif
index 2299705378ac612d1f6dbcf099ae7c1baec7620c..a63379994fd61fd7dca179fff95f6fd01b7f8dee 100644 (file)
 
 static inline u32 get_unaligned_le32(const void *p)
 {
-       return le32_to_cpup(p);
+       u32 v;
+
+       memcpy(&v, p, sizeof(v));
+
+       return le32_to_cpu(v);
 }
 
 static inline void put_unaligned_le32(u32 val, void *p)
 {
-       *(__force __le32*)p = cpu_to_le32(val);
+       u32 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