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@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Lin Liu authored and Andrew Cooper committed 2025-04-18 15:16:12 +01:00
1 parent f689c56076
commit 60dcff871e
6 files changed
+47 -37

No files matched your search

+8 -2
View File
@@ -3,6 +3,8 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h> #include <stdint.h>
#include INCLUDE_ENDIAN_H
#define XG_NEED_UNALIGNED #define XG_NEED_UNALIGNED
#include "xg_private.h" #include "xg_private.h"
#include "xg_dom_decompress.h" #include "xg_dom_decompress.h"
@@ -17,9 +19,13 @@ typedef uint64_t u64;
#define likely(a) a #define likely(a) a
#define unlikely(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" #include "../../xen/include/xen/lz4.h"
@@ -16,25 +16,10 @@ typedef uint64_t u64;
#define noinline #define noinline
#define unlikely(a) a #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 #if BYTE_ORDER == LITTLE_ENDIAN
return (((v & 0x00ffU) << 8) | return __builtin_bswap16(v);
((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));
#else #else
return v; return v;
#endif #endif
@@ -16,21 +16,22 @@ typedef uint16_t u16;
typedef uint32_t u32; typedef uint32_t u32;
typedef uint32_t __le32; 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 #if BYTE_ORDER == BIG_ENDIAN
return (((v & 0x000000ffUL) << 24) | return __builtin_bswap32(v);
((v & 0x0000ff00UL) << 8) |
((v & 0x00ff0000UL) >> 8) |
((v & 0xff000000UL) >> 24));
#else #else
return v; return v;
#endif #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 #define __force
+6 -2
View File
@@ -16,9 +16,13 @@
#include <xen/unaligned.h> #include <xen/unaligned.h>
#else #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 #endif
+12 -4
View File
@@ -37,14 +37,22 @@
#include <xen/unaligned.h> #include <xen/unaligned.h>
#else #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 #endif
+11 -5
View File
@@ -16,19 +16,25 @@
#include <xen/unaligned.h> #include <xen/unaligned.h>
#else #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 #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 false 0
#define true 1 #define true 1
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.