On 8/20/26 02:46, BillXiang wrote:
diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index 387d65c..c23f5a2 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -255,6 +255,20 @@ static inline int lduw_he_p(const void *ptr)
return r;
}
+static inline int lduw_he_p_aligned(const void *ptr)
+{
+ uint16_t r;
+ __builtin_memcpy(&r, __builtin_assume_aligned(ptr, sizeof(r)), sizeof(r));
+ return r;
+}
If you know it's aligned, then you don't need anything special: just a normal C memory
access. E.g.
*(uint16_t *)ptr
and then of course no need for a wrapper function.
+static inline int lduw_le_p_aligned(const void *ptr)
+{
+ return (uint16_t)le_bswap(lduw_he_p_aligned(ptr), 16);
+}
And this: le16_to_cpu(*(uint16_t *)ptr)
r~