system/memory: Clarify unaligned load/store API
v2 cover system/memory: Clarify unaligned load/store API
I have been confused by the load/store 'host endian' API for years: this is just about unaligned loads/stores. Rename to clarify.
v2:
- No "memory_" since it's for host pointers and not guest memory addresses (Paolo)
- Fix regexps
Philippe Mathieu-Daudé (4):
docs/devel/loads-stores: Clarify regexp are POSIX basic ones docs/devel/loads-stores: Fix ld/stn_*_p() regexp system/memory: Extract 'qemu/ldst_unaligned.h' header system/memory: Rename unaligned load/store API
MAINTAINERS | 1 + docs/devel/loads-stores.rst | 47 ++++++++--------- include/qemu/bswap.h | 96 +++++++--------------------------- include/qemu/ldst_unaligned.h | 67 ++++++++++++++++++++++++ accel/tcg/translator.c | 7 +-- hw/display/ati_2d.c | 3 +- hw/display/sm501.c | 21 ++++---- hw/remote/vfio-user-obj.c | 5 +- hw/vmapple/virtio-blk.c | 3 +- net/checksum.c | 7 +-- system/memory.c | 4 +- system/physmem.c | 8 +-- ui/vnc-enc-tight.c | 3 +- util/bufferiszero.c | 8 +-- accel/tcg/ldst_atomicity.c.inc | 10 ++-- 15 files changed, 153 insertions(+), 137 deletions(-) create mode 100644 include/qemu/ldst_unaligned.h
Signature · 1 line
2.52.0
PATCH v2 1/4 docs/devel/loads-stores: Clarify regexp are POSIX basic ones
While git-grep uses POSIX basic regexp by default, git-config can select a distinct one. Add the '-G' (--basic-regexp) argument to be sure our regexps work on first try.
--- docs/devel/loads-stores.rst | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
docs/devel/loads-stores.rst +14 -14
@@ -63,7 +63,7 @@ which stores ``val`` to ``ptr`` as an ``{endian}`` order value of size ``sz`` bytes. -Regexes for git grep: +Regexes for git grep -G: - ``\<ld[us]\?[bwlq]\(_[hbl]e\)\?_p\>`` - ``\<st[bwlq]\(_[hbl]e\)\?_p\>`` - ``\<st24\(_[hbl]e\)\?_p\>``
@@ -120,7 +120,7 @@ store: ``cpu_st{size}{end}_mmu(env, ptr, val, oi, retaddr)`` - ``_be`` : big endian - ``_le`` : little endian -Regexes for git grep: +Regexes for git grep -G: - ``\<cpu_ld[bwlq]\(_[bl]e\)\?_mmu\>`` - ``\<cpu_st[bwlq]\(_[bl]e\)\?_mmu\>``
@@ -154,7 +154,7 @@ store: ``cpu_st{size}{end}_mmuidx_ra(env, ptr, val, mmuidx, retaddr)`` - ``_be`` : big endian - ``_le`` : little endian -Regexes for git grep: +Regexes for git grep -G: - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_mmuidx_ra\>`` - ``\<cpu_st[bwlq]\(_[bl]e\)\?_mmuidx_ra\>``
@@ -192,7 +192,7 @@ store: ``cpu_st{size}{end}_data_ra(env, ptr, val, ra)`` - ``_be`` : big endian - ``_le`` : little endian -Regexes for git grep: +Regexes for git grep -G: - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_data_ra\>`` - ``\<cpu_st[bwlq]\(_[bl]e\)\?_data_ra\>``
@@ -231,7 +231,7 @@ store: ``cpu_st{size}{end}_data(env, ptr, val)`` - ``_be`` : big endian - ``_le`` : little endian -Regexes for git grep: +Regexes for git grep -G: - ``\<cpu_ld[us]\?[bwlq]\(_[bl]e\)\?_data\>`` - ``\<cpu_st[bwlq]\(_[bl]e\)\?_data\+\>``
@@ -265,7 +265,7 @@ load: ``cpu_ld{sign}{size}_code(env, ptr)`` - ``l`` : 32 bits - ``q`` : 64 bits -Regexes for git grep: +Regexes for git grep -G: - ``\<cpu_ld[us]\?[bwlq]_code\>`` ``translator_ld*``
@@ -296,7 +296,7 @@ swap: ``translator_ld{sign}{size}_swap(env, ptr, swap)`` - ``l`` : 32 bits - ``q`` : 64 bits -Regexes for git grep: +Regexes for git grep -G: - ``\<translator_ld[us]\?[bwlq]\(_swap\)\?\>`` ``helper_{ld,st}*_mmu``
@@ -325,7 +325,7 @@ store: ``helper_{size}_mmu(env, addr, val, opindex, retaddr)`` - ``l`` : 32 bits - ``q`` : 64 bits -Regexes for git grep: +Regexes for git grep -G: - ``\<helper_ld[us]\?[bwlq]_mmu\>`` - ``\<helper_st[bwlq]_mmu\>``
@@ -382,7 +382,7 @@ succeeded using a MemTxResult return code. The ``_{endian}`` suffix is omitted for byte accesses. -Regexes for git grep: +Regexes for git grep -G: - ``\<address_space_\(read\|write\|rw\)\>`` - ``\<address_space_ldu\?[bwql]\(_[lb]e\)\?\>`` - ``\<address_space_st[bwql]\(_[lb]e\)\?\>``
@@ -400,7 +400,7 @@ Note that portions of the write which attempt to write data to a device will be silently ignored -- only real RAM and ROM will be written to. -Regexes for git grep: +Regexes for git grep -G: - ``address_space_write_rom`` ``{ld,st}*_phys``
@@ -438,7 +438,7 @@ device doing the access has no way to report such an error. The ``_{endian}_`` infix is omitted for byte accesses. -Regexes for git grep: +Regexes for git grep -G: - ``\<ldu\?[bwlq]\(_[bl]e\)\?_phys\>`` - ``\<st[bwlq]\(_[bl]e\)\?_phys\>``
@@ -460,7 +460,7 @@ For new code they are better avoided: ``cpu_physical_memory_write`` -Regexes for git grep: +Regexes for git grep -G: - ``\<cpu_physical_memory_\(read\|write\)\>`` ``cpu_memory_rw_debug``
@@ -495,7 +495,7 @@ make sure our existing code is doing things correctly. ``dma_memory_rw`` -Regexes for git grep: +Regexes for git grep -G: - ``\<dma_memory_\(read\|write\|rw\)\>`` - ``\<ldu\?[bwlq]\(_[bl]e\)\?_dma\>`` - ``\<st[bwlq]\(_[bl]e\)\?_dma\>``
@@ -536,7 +536,7 @@ correct address space for that device. The ``_{endian}_`` infix is omitted for byte accesses. -Regexes for git grep: +Regexes for git grep -G: - ``\<pci_dma_\(read\|write\|rw\)\>`` - ``\<ldu\?[bwlq]\(_[bl]e\)\?_pci_dma\>`` - ``\<st[bwlq]\(_[bl]e\)\?_pci_dma\>``
Signature · 1 line
2.52.0
Re: [PATCH v2 1/4] docs/devel/loads-stores: Clarify regexp are POSIX basic ones
Quoted 6 lines · Philippe Mathieu-Daudé
While git-grep uses POSIX basic regexp by default, git-config can select a distinct one. Add the '-G' (--basic-regexp) argument to be sure our regexps work on first try.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
It's a little unfortunate that now we suggest to the user to use an option that almost none of them will actually need to type (because -G is the default and most people probably don't reconfigure their git grep default options), but I don't have a better proposal, so:
thanks
-- PMM
PATCH v2 2/4 docs/devel/loads-stores: Fix ld/stn_*_p() regexp
In reply to Philippe Mathieu-Daudé--- docs/devel/loads-stores.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
docs/devel/loads-stores.rst +4 -4
@@ -52,12 +52,12 @@ files which are built per-target. There are also functions which take the size as an argument: -load: ``ldn{endian}_p(ptr, sz)`` +load: ``ldn_{endian}_p(ptr, sz)`` which performs an unsigned load of ``sz`` bytes from ``ptr`` as an ``{endian}`` order value and returns it in a uint64_t. -store: ``stn{endian}_p(ptr, sz, val)`` +store: ``stn_{endian}_p(ptr, sz, val)`` which stores ``val`` to ``ptr`` as an ``{endian}`` order value of size ``sz`` bytes.
@@ -67,8 +67,8 @@ Regexes for git grep -G: - ``\<ld[us]\?[bwlq]\(_[hbl]e\)\?_p\>`` - ``\<st[bwlq]\(_[hbl]e\)\?_p\>`` - ``\<st24\(_[hbl]e\)\?_p\>`` - - ``\<ldn_\([hbl]e\)\?_p\>`` - - ``\<stn_\([hbl]e\)\?_p\>`` + - ``\<ldn\(_[hbl]e\)\?_p\>`` + - ``\<stn\(_[hbl]e\)\?_p\>`` ``cpu_{ld,st}*_mmu`` ~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.52.0
Re: [PATCH v2 2/4] docs/devel/loads-stores: Fix ld/stn_*_p() regexp
Quoted 5 lines · Philippe Mathieu-Daudé
Fixes afa4f6653dc ("bswap: Add stn_*_p() and ldn_*_p() functions")Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- docs/devel/loads-stores.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
r~
PATCH v2 3/4 system/memory: Extract 'qemu/ldst_unaligned.h' header
In reply to Philippe Mathieu-DaudéUnaligned memcpy API is buried within 'qemu/bswap.h', supposed to be related to endianness swapping. Extract to a new header to clarify.
--- MAINTAINERS | 1 + include/qemu/bswap.h | 62 +------------------------------- include/qemu/ldst_unaligned.h | 67 +++++++++++++++++++++++++++++++++++ accel/tcg/translator.c | 1 + hw/display/ati_2d.c | 1 + hw/display/sm501.c | 2 +- hw/remote/vfio-user-obj.c | 1 + hw/vmapple/virtio-blk.c | 1 + net/checksum.c | 1 + ui/vnc-enc-tight.c | 1 + util/bufferiszero.c | 2 +- 11 files changed, 77 insertions(+), 63 deletions(-) create mode 100644 include/qemu/ldst_unaligned.h
MAINTAINERS +1 -0
@@ -3257,6 +3257,7 @@ R: Philippe Mathieu-Daudé <[email protected]> S: Supported F: include/system/ioport.h F: include/exec/memop.h +F: include/qemu/ldst_unaligned.h F: include/system/ram_addr.h F: include/system/memory.h F: include/system/physmem.h
include/qemu/bswap.h +1 -61
86 lines not on this page · raw message
include/qemu/ldst_unaligned.h new file +67 -0
67 lines not on this page · raw message
accel/tcg/translator.c +1 -0
@@ -9,6 +9,7 @@#include "qemu/osdep.h" #include "qemu/bswap.h" +#include "qemu/ldst_unaligned.h" #include "qemu/log.h" #include "qemu/error-report.h" #include "accel/tcg/cpu-ldst-common.h"
hw/display/ati_2d.c +1 -0
@@ -10,6 +10,7 @@#include "qemu/osdep.h" #include "ati_int.h" #include "ati_regs.h" +#include "qemu/ldst_unaligned.h" #include "qemu/log.h" #include "ui/pixel_ops.h" #include "ui/console.h"
hw/display/sm501.c +1 -1
@@ -28,6 +28,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/log.h" +#include "qemu/ldst_unaligned.h" #include "qemu/module.h" #include "hw/usb/hcd-ohci.h" #include "hw/char/serial-mm.h"
@@ -40,7 +41,6 @@#include "hw/display/i2c-ddc.h" #include "qemu/range.h" #include "ui/pixel_ops.h" -#include "qemu/bswap.h" #include "trace.h" #include "qom/object.h"
hw/remote/vfio-user-obj.c +1 -0
@@ -49,6 +49,7 @@#include "qapi/error.h" #include "qapi/qapi-visit-sockets.h" #include "qapi/qapi-events-misc.h" +#include "qemu/ldst_unaligned.h" #include "qemu/notify.h" #include "qemu/thread.h" #include "qemu/main-loop.h"
hw/vmapple/virtio-blk.c +1 -0
@@ -19,6 +19,7 @@#include "hw/vmapple/vmapple.h" #include "hw/virtio/virtio-blk.h" #include "hw/virtio/virtio-pci.h" +#include "qemu/ldst_unaligned.h" #include "qemu/log.h" #include "qemu/module.h" #include "qapi/error.h"
net/checksum.c +1 -0
@@ -16,6 +16,7 @@*/ #include "qemu/osdep.h" +#include "qemu/ldst_unaligned.h" #include "net/checksum.h" #include "net/eth.h"
ui/vnc-enc-tight.c +1 -0
@@ -42,6 +42,7 @@#include <jpeglib.h> #endif +#include "qemu/ldst_unaligned.h" #include "qemu/bswap.h" #include "vnc.h" #include "vnc-enc-tight.h"
util/bufferiszero.c +1 -1
@@ -23,7 +23,7 @@*/ #include "qemu/osdep.h" #include "qemu/cutils.h" -#include "qemu/bswap.h" +#include "qemu/ldst_unaligned.h" #include "host/cpuinfo.h" typedef bool (*biz_accel_fn )(const void *,size_t );
Signature · 1 line
2.52.0
Re: [PATCH v2 3/4] system/memory: Extract 'qemu/ldst_unaligned.h' header
Quoted 19 lines · Philippe Mathieu-Daudé
Unaligned memcpy API is buried within '
qemu/bswap.h', supposed to be related to endianness swapping. Extract to a new header to clarify.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
MAINTAINERS | 1 + include/qemu/bswap.h | 62 +------------------------------- include/qemu/ldst_unaligned.h | 67 +++++++++++++++++++++++++++++++++++ accel/tcg/translator.c | 1 + hw/display/ati_2d.c | 1 + hw/display/sm501.c | 2 +- hw/remote/vfio-user-obj.c | 1 + hw/vmapple/virtio-blk.c | 1 + net/checksum.c | 1 + ui/vnc-enc-tight.c | 1 + util/bufferiszero.c | 2 +- 11 files changed, 77 insertions(+), 63 deletions(-)
Quoted 1 line
create mode 100644
include/qemu/ldst_unaligned.h
Re: [PATCH v2 3/4] system/memory: Extract 'qemu/ldst_unaligned.h' header
In reply to Philippe Mathieu-DaudéQuoted 19 lines · Philippe Mathieu-Daudé
Unaligned memcpy API is buried within '
qemu/bswap.h', supposed to be related to endianness swapping. Extract to a new header to clarify.Suggested-by Paolo Bonzini<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- MAINTAINERS | 1 + include/qemu/bswap.h | 62 +------------------------------- include/qemu/ldst_unaligned.h | 67 +++++++++++++++++++++++++++++++++++ accel/tcg/translator.c | 1 + hw/display/ati_2d.c | 1 + hw/display/sm501.c | 2 +- hw/remote/vfio-user-obj.c | 1 + hw/vmapple/virtio-blk.c | 1 + net/checksum.c | 1 + ui/vnc-enc-tight.c | 1 + util/bufferiszero.c | 2 +- 11 files changed, 77 insertions(+), 63 deletions(-)
Quoted 1 line
create mode 100644
include/qemu/ldst_unaligned.h
r~
Re: [PATCH v2 3/4] system/memory: Extract 'qemu/ldst_unaligned.h' header
In reply to Philippe Mathieu-DaudéQuoted 7 lines · Philippe Mathieu-Daudé
Unaligned memcpy API is buried within '
qemu/bswap.h', supposed to be related to endianness swapping. Extract to a new header to clarify.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
I'm not very enthusiastic about this one, because it takes one set of functions out of a family of ones with related names, and moves it into a different header and drops it from the documentation comment:
include/qemu/bswap.h CPU_CONVERT(le, 64, uint64_t) · line 205
Quoted 13 lines
include/qemu/bswap.h +0
-3-/* unaligned/endian-independent pointer access */ -/* * the generic syntax is: * @@ -201,7 +200,6 @@ CPU_CONVERT(le, 64, uint64_t)* q: 64 bits * * endian is: -* he : host endian * be : big endian * le : little endian * te : target endian
These are all doing variants on the same thing, which is why they're all in one place and have the "same pattern" names they do.
thanks
-- PMM
PATCH v2 4/4 system/memory: Rename unaligned load/store API
In reply to Philippe Mathieu-DaudéRename the API methods using the explicit 'unaligned' description instead of 'he' which stands for 'host endianness'.
--- docs/devel/loads-stores.rst | 19 +++++++++---------- include/qemu/bswap.h | 34 +++++++++++++++++----------------- include/qemu/ldst_unaligned.h | 16 ++++++++-------- accel/tcg/translator.c | 6 +++--- hw/display/ati_2d.c | 2 +- hw/display/sm501.c | 19 +++++++++++-------- hw/remote/vfio-user-obj.c | 4 ++-- hw/vmapple/virtio-blk.c | 2 +- net/checksum.c | 6 +++--- system/memory.c | 4 ++-- system/physmem.c | 8 ++++---- ui/vnc-enc-tight.c | 2 +- util/bufferiszero.c | 6 +++--- accel/tcg/ldst_atomicity.c.inc | 10 +++++----- 14 files changed, 70 insertions(+), 68 deletions(-)
docs/devel/loads-stores.rst +9 -10
@@ -24,9 +24,9 @@ potentially unaligned pointer values. Function names follow the pattern: -load: ``ld{sign}{size}_{endian}_p(ptr)`` +load: ``ld{sign}{size}_{unaligned|endian}_p(ptr)`` -store: ``st{size}_{endian}_p(ptr, val)`` +store: ``st{size}_{unaligned|endian}_p(ptr, val)`` ``sign`` - (empty) : for 32 or 64 bit sizes
@@ -41,7 +41,6 @@ store: ``st{size}_{endian}_p(ptr, val)`` - ``q`` : 64 bits ``endian`` - - ``he`` : host endian - ``be`` : big endian - ``le`` : little endian
@@ -52,23 +51,23 @@ files which are built per-target. There are also functions which take the size as an argument: -load: ``ldn_{endian}_p(ptr, sz)`` +load: ``ldn_{unaligned|endian}_p(ptr, sz)`` which performs an unsigned load of ``sz`` bytes from ``ptr`` as an ``{endian}`` order value and returns it in a uint64_t. -store: ``stn_{endian}_p(ptr, sz, val)`` +store: ``stn_{unaligned|endian}_p(ptr, sz, val)`` which stores ``val`` to ``ptr`` as an ``{endian}`` order value of size ``sz`` bytes. Regexes for git grep -G: - - ``\<ld[us]\?[bwlq]\(_[hbl]e\)\?_p\>`` - - ``\<st[bwlq]\(_[hbl]e\)\?_p\>`` - - ``\<st24\(_[hbl]e\)\?_p\>`` - - ``\<ldn\(_[hbl]e\)\?_p\>`` - - ``\<stn\(_[hbl]e\)\?_p\>`` + - ``\<ld[us]\?[bwlq]\(_unaligned\|_[bl]e\)\?_p\>`` + - ``\<st[bwlq]\(_unaligned\|_[bl]e\)\?_p\>`` + - ``\<st24\(_unaligned\|_[bl]e\)\?_p\>`` + - ``\<ldn\(_unaligned\|_[bl]e\)\?_p\>`` + - ``\<stn\(_unaligned\|_[bl]e\)\?_p\>`` ``cpu_{ld,st}*_mmu`` ~~~~~~~~~~~~~~~~~~~~
include/qemu/bswap.h +17 -17
@@ -237,82 +237,82 @@ static inline void stb_p(void *ptr, uint8_t v)static inline int lduw_le_p (const void *ptr) { -return (uint16_t )le_bswap (lduw_he_p (ptr),16 ); +return (uint16_t )le_bswap (lduw_unaligned_p (ptr),16 ); }static inline int ldsw_le_p (const void *ptr) { -return (int16_t )le_bswap (lduw_he_p (ptr),16 ); +return (int16_t )le_bswap (lduw_unaligned_p (ptr),16 ); }static inline int ldl_le_p (const void *ptr) { -return le_bswap (ldl_he_p (ptr),32 ); +return le_bswap (ldl_unaligned_p (ptr),32 ); }static inline uint64_t ldq_le_p (const void *ptr) { -return le_bswap (ldq_he_p (ptr),64 ); +return le_bswap (ldq_unaligned_p (ptr),64 ); }static inline void stw_le_p (void *ptr,uint16_t v) { -stw_he_p (ptr,le_bswap (v,16 )); +stw_unaligned_p (ptr,le_bswap (v,16 )); }static inline void st24_le_p (void *ptr,uint32_t v) { -st24_he_p (ptr,le_bswap24 (v)); +st24_unaligned_p (ptr,le_bswap24 (v)); }static inline void stl_le_p (void *ptr,uint32_t v) { -stl_he_p (ptr,le_bswap (v,32 )); +stl_unaligned_p (ptr,le_bswap (v,32 )); }static inline void stq_le_p (void *ptr,uint64_t v) { -stq_he_p (ptr,le_bswap (v,64 )); +stq_unaligned_p (ptr,le_bswap (v,64 )); }static inline int lduw_be_p (const void *ptr) { -return (uint16_t )be_bswap (lduw_he_p (ptr),16 ); +return (uint16_t )be_bswap (lduw_unaligned_p (ptr),16 ); }static inline int ldsw_be_p (const void *ptr) { -return (int16_t )be_bswap (lduw_he_p (ptr),16 ); +return (int16_t )be_bswap (lduw_unaligned_p (ptr),16 ); }static inline int ldl_be_p (const void *ptr) { -return be_bswap (ldl_he_p (ptr),32 ); +return be_bswap (ldl_unaligned_p (ptr),32 ); }static inline uint64_t ldq_be_p (const void *ptr) { -return be_bswap (ldq_he_p (ptr),64 ); +return be_bswap (ldq_unaligned_p (ptr),64 ); }static inline void stw_be_p (void *ptr,uint16_t v) { -stw_he_p (ptr,be_bswap (v,16 )); +stw_unaligned_p (ptr,be_bswap (v,16 )); }static inline void st24_be_p (void *ptr,uint32_t v) { -st24_he_p (ptr,be_bswap24 (v)); +st24_unaligned_p (ptr,be_bswap24 (v)); }static inline void stl_be_p (void *ptr,uint32_t v) { -stl_he_p (ptr,be_bswap (v,32 )); +stl_unaligned_p (ptr,be_bswap (v,32 )); }static inline void stq_be_p (void *ptr,uint64_t v) { -stq_he_p (ptr,be_bswap (v,64 )); +stq_unaligned_p (ptr,be_bswap (v,64 )); }static inline unsigned long leul_to_cpu (unsigned long v)
@@ -363,7 +363,7 @@ static inline unsigned long leul_to_cpu(unsigned long v) } \ } -DO_STN_LDN_P(he) +DO_STN_LDN_P(unaligned) DO_STN_LDN_P(le) DO_STN_LDN_P(be)
include/qemu/ldst_unaligned.h +8 -8
@@ -16,50 +16,50 @@* of good performance. */ -static inline int lduw_he_p (const void *ptr) +static inline int lduw_unaligned_p (const void *ptr) {uint16_t r;__builtin_memcpy (&r, ptr,sizeof (r));return r; } -static inline int ldsw_he_p (const void *ptr) +static inline int ldsw_unaligned_p (const void *ptr) {int16_t r;__builtin_memcpy (&r, ptr,sizeof (r));return r; } -static inline void stw_he_p (void *ptr,uint16_t v) +static inline void stw_unaligned_p (void *ptr,uint16_t v) {__builtin_memcpy (ptr, &v,sizeof (v)); } -static inline void st24_he_p (void *ptr,uint32_t v) +static inline void st24_unaligned_p (void *ptr,uint32_t v) {__builtin_memcpy (ptr, &v,3 ); } -static inline int ldl_he_p (const void *ptr) +static inline int ldl_unaligned_p (const void *ptr) {int32_t r;__builtin_memcpy (&r, ptr,sizeof (r));return r; } -static inline void stl_he_p (void *ptr,uint32_t v) +static inline void stl_unaligned_p (void *ptr,uint32_t v) {__builtin_memcpy (ptr, &v,sizeof (v)); } -static inline uint64_t ldq_he_p (const void *ptr) +static inline uint64_t ldq_unaligned_p (const void *ptr) {uint64_t r;__builtin_memcpy (&r, ptr,sizeof (r));return r; } -static inline void stq_he_p (void *ptr,uint64_t v) +static inline void stq_unaligned_p (void *ptr,uint64_t v) {__builtin_memcpy (ptr, &v,sizeof (v)); }
accel/tcg/translator.c +3 -3
@@ -342,14 +342,14 @@ static bool translator_ld(CPUArchState *env, DisasContextBase *db,case 2 :if (QEMU_IS_ALIGNED (pc,2 )) {uint16_t t =qatomic_read ((uint16_t *)host); -stw_he_p (dest, t); +stw_unaligned_p (dest, t);return true; }break ;case 4 :if (QEMU_IS_ALIGNED (pc,4 )) {uint32_t t =qatomic_read ((uint32_t *)host); -stl_he_p (dest, t); +stl_unaligned_p (dest, t);return true; }break ;
@@ -357,7 +357,7 @@ static bool translator_ld(CPUArchState *env, DisasContextBase *db,case 8 :if (QEMU_IS_ALIGNED (pc,8 )) {uint64_t t =qatomic_read__nocheck ((uint64_t *)host); -stq_he_p (dest, t); +stq_unaligned_p (dest, t);return true; }break ;
hw/display/ati_2d.c +1 -1
@@ -222,7 +222,7 @@ void ati_2d_blt(ATIVGAState *s)for (y =0 ; y < s->regs.dst_height; y++) { i = dst_x * bypp + (dst_y + y) * dst_pitch;for (x =0 ; x < s->regs.dst_width; x++, i += bypp) { -stn_he_p (&dst_bits[i], bypp, filler); +stn_unaligned_p (&dst_bits[i], bypp, filler); } } }
hw/display/sm501.c +11 -8
@@ -768,7 +768,7 @@ static void sm501_2d_operation(SM501State *s)for (y =0 ; y < height; y++) { i = (dst_x + (dst_y + y) * dst_pitch) * bypp;for (x =0 ; x < width; x++, i += bypp) { -stn_he_p (&d[i], bypp, ~ldn_he_p (&d[i], bypp)); +stn_unaligned_p (&d[i], bypp, ~ldn_unaligned_p (&d[i], bypp)); } } }else if (!rop_mode && rop ==0x99 ) {
@@ -781,8 +781,9 @@ static void sm501_2d_operation(SM501State *s) i = (dst_x + (dst_y + y) * dst_pitch) * bypp; j = (src_x + (src_y + y) * src_pitch) * bypp;for (x =0 ; x < width; x++, i += bypp, j += bypp) { -stn_he_p (&d[i], bypp, - ~(ldn_he_p (&sp[j], bypp) ^ldn_he_p (&d[i], bypp))); +stn_unaligned_p (&d[i], bypp, + ~(ldn_unaligned_p (&sp[j], bypp) + ^ldn_unaligned_p (&d[i], bypp))); } } }else if (!rop_mode && rop ==0xee ) {
@@ -795,8 +796,9 @@ static void sm501_2d_operation(SM501State *s) i = (dst_x + (dst_y + y) * dst_pitch) * bypp; j = (src_x + (src_y + y) * src_pitch) * bypp;for (x =0 ; x < width; x++, i += bypp, j += bypp) { -stn_he_p (&d[i], bypp, -ldn_he_p (&sp[j], bypp) |ldn_he_p (&d[i], bypp)); +stn_unaligned_p (&d[i], bypp, +ldn_unaligned_p (&sp[j], bypp) + |ldn_unaligned_p (&d[i], bypp)); } } }else {
@@ -818,8 +820,9 @@ static void sm501_2d_operation(SM501State *s)if (width ==1 && height ==1 ) {unsigned int si = (src_x + src_y * src_pitch) * bypp;unsigned int di = (dst_x + dst_y * dst_pitch) * bypp; -stn_he_p (&s->local_mem[dst_base + di], bypp, -ldn_he_p (&s->local_mem[src_base + si], bypp)); +stn_unaligned_p (&s->local_mem[dst_base + di], bypp, +ldn_unaligned_p (&s->local_mem[src_base + si], + bypp));break ; }/* If reverse blit do simple check for overlaps */
@@ -917,7 +920,7 @@ static void sm501_2d_operation(SM501State *s)for (y =0 ; y < height; y++) { i = (dst_x + (dst_y + y) * dst_pitch) * bypp;for (x =0 ; x < width; x++, i += bypp) { -stn_he_p (&d[i], bypp, color); +stn_unaligned_p (&d[i], bypp, color); } } }
hw/remote/vfio-user-obj.c +2 -2
@@ -392,7 +392,7 @@ static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset, access_size =memory_access_size (mr, size, offset);if (is_write) { - val =ldn_he_p (ptr, access_size); + val =ldn_unaligned_p (ptr, access_size); result = memory_region_dispatch_write(mr, offset, val, size_memop(access_size),
@@ -402,7 +402,7 @@ static int vfu_object_mr_rw(MemoryRegion *mr, uint8_t *buf, hwaddr offset,size_memop (access_size), MEMTXATTRS_UNSPECIFIED); -stn_he_p (ptr, access_size, val); +stn_unaligned_p (ptr, access_size, val); }if (release_lock) {
hw/vmapple/virtio-blk.c +1 -1
@@ -79,7 +79,7 @@ static void vmapple_virtio_blk_get_config(VirtIODevice *vdev, uint8_t *config) g_assert(dev->parent_obj.config_size >= endof(struct virtio_blk_config, zoned));/* Apple abuses the field for max_secure_erase_sectors as type id */ -stl_he_p (&blkcfg->max_secure_erase_sectors, dev->apple_type); +stl_unaligned_p (&blkcfg->max_secure_erase_sectors, dev->apple_type); }static void vmapple_virtio_blk_class_init (ObjectClass *klass,const void *data)
net/checksum.c +3 -3
@@ -110,7 +110,7 @@ void net_checksum_calculate(void *data, int length, int csum_flag)/* Calculate IP checksum */ if (csum_flag &CSUM_IP ) { -stw_he_p (&ip->ip_sum,0 ); +stw_unaligned_p (&ip->ip_sum,0 ); csum =net_raw_checksum ((uint8_t *)ip,IP_HDR_GET_LEN (ip));stw_be_p (&ip->ip_sum, csum); }
@@ -142,7 +142,7 @@ void net_checksum_calculate(void *data, int length, int csum_flag) }/* Set csum to 0 */ -stw_he_p (&tcp->th_sum,0 ); +stw_unaligned_p (&tcp->th_sum,0 ); csum = net_checksum_tcpudp(ip_len, ip->ip_p, (uint8_t *)&ip->ip_src,
@@ -166,7 +166,7 @@ void net_checksum_calculate(void *data, int length, int csum_flag) }/* Set csum to 0 */ -stw_he_p (&udp->uh_sum,0 ); +stw_unaligned_p (&udp->uh_sum,0 ); csum = net_checksum_tcpudp(ip_len, ip->ip_p, (uint8_t *)&ip->ip_src,
system/memory.c +2 -2
@@ -1365,7 +1365,7 @@ static uint64_t memory_region_ram_device_read(void *opaque, hwaddr addr, unsigned size) {MemoryRegion *mr = opaque; -uint64_t data =ldn_he_p (mr->ram_block->host + addr, size); +uint64_t data =ldn_unaligned_p (mr->ram_block->host + addr, size);trace_memory_region_ram_device_read (get_cpu_index (), mr, addr, data, size);
@@ -1379,7 +1379,7 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr,trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); -stn_he_p (mr->ram_block->host + addr, size, data); +stn_unaligned_p (mr->ram_block->host + addr, size, data); }static const MemoryRegionOps ram_device_mem_ops = {
system/physmem.c +4 -4
@@ -3275,7 +3275,7 @@ static MemTxResult flatview_write_continue_step(MemTxAttrs attrs,/* * Assure Coverity (and ourselves) that we are not going to OVERRUN -* the buffer by following ldn_he_p(). +* the buffer by following ldn_unaligned_p(). */ #ifdef QEMU_STATIC_ANALYSIS assert((*l == 1 && len >= 1) ||
@@ -3283,7 +3283,7 @@ static MemTxResult flatview_write_continue_step(MemTxAttrs attrs, (*l ==4 && len >=4 ) || (*l == 8 && len >= 8));#endif - val =ldn_he_p (buf, *l); + val =ldn_unaligned_p (buf, *l); result =memory_region_dispatch_write (mr, mr_addr, val,size_memop (*l), attrs);if (release_lock) {
@@ -3370,7 +3370,7 @@ static MemTxResult flatview_read_continue_step(MemTxAttrs attrs, uint8_t *buf,/* * Assure Coverity (and ourselves) that we are not going to OVERRUN -* the buffer by following stn_he_p(). +* the buffer by following stn_unaligned_p(). */ #ifdef QEMU_STATIC_ANALYSIS assert((*l == 1 && len >= 1) ||
@@ -3378,7 +3378,7 @@ static MemTxResult flatview_read_continue_step(MemTxAttrs attrs, uint8_t *buf, (*l ==4 && len >=4 ) || (*l == 8 && len >= 8));#endif -stn_he_p (buf, *l, val); +stn_unaligned_p (buf, *l, val);if (release_lock) {bql_unlock ();
ui/vnc-enc-tight.c +1 -1
@@ -912,7 +912,7 @@ static void tight_pack24(VncState *vs, uint8_t *buf, size_t count, size_t *ret) }while (count--) { - pix =ldl_he_p (buf8); + pix =ldl_unaligned_p (buf8); *buf++ = (char )(pix >> rshift); *buf++ = (char )(pix >> gshift); *buf++ = (char )(pix >> bshift);
util/bufferiszero.c +3 -3
@@ -38,10 +38,10 @@ static bool buffer_is_zero_int_lt256(const void *buf, size_t len)* the beginning and end of the buffer. */ if (unlikely (len <=8 )) { -return (ldl_he_p (buf) |ldl_he_p (buf + len -4 )) ==0 ; +return (ldl_unaligned_p (buf) |ldl_unaligned_p (buf + len -4 )) ==0 ; } - t =ldq_he_p (buf) |ldq_he_p (buf + len -8 ); + t =ldq_unaligned_p (buf) |ldq_unaligned_p (buf + len -8 ); p =QEMU_ALIGN_PTR_DOWN (buf +8 ,8 ); e =QEMU_ALIGN_PTR_DOWN (buf + len -1 ,8 );
@@ -58,7 +58,7 @@ static bool buffer_is_zero_int_ge256(const void *buf, size_t len)* Use unaligned memory access functions to handle * the beginning and end of the buffer. */ -uint64_t t =ldq_he_p (buf) |ldq_he_p (buf + len -8 ); +uint64_t t =ldq_unaligned_p (buf) |ldq_unaligned_p (buf + len -8 );const uint64_t *p =QEMU_ALIGN_PTR_DOWN (buf +8 ,8 );const uint64_t *e =QEMU_ALIGN_PTR_DOWN (buf + len -1 ,8 );
accel/tcg/ldst_atomicity.c.inc +5 -5
@@ -415,7 +415,7 @@ static uint16_t load_atom_2(CPUState *cpu, uintptr_t ra, atmax = required_atomicity(cpu, pi, memop); switch (atmax) { case MO_8: - return lduw_he_p(pv); + return lduw_unaligned_p(pv); case MO_16: /* The only case remaining is MO_ATOM_WITHIN16. */ if (!HAVE_al8_fast && (pi & 3) == 1) {
@@ -512,7 +512,7 @@ static uint64_t load_atom_8(CPUState *cpu, uintptr_t ra, } switch (atmax) { case MO_8: - return ldq_he_p(pv); + return ldq_unaligned_p(pv); case MO_16: return load_atom_8_by_2(pv); case MO_32:
@@ -875,7 +875,7 @@ static void store_atom_2(CPUState *cpu, uintptr_t ra, atmax = required_atomicity(cpu, pi, memop); if (atmax == MO_8) { - stw_he_p(pv, val); + stw_unaligned_p(pv, val); return; }
@@ -928,7 +928,7 @@ static void store_atom_4(CPUState *cpu, uintptr_t ra, atmax = required_atomicity(cpu, pi, memop); switch (atmax) { case MO_8: - stl_he_p(pv, val); + stl_unaligned_p(pv, val); return; case MO_16: store_atom_4_by_2(pv, val);
@@ -996,7 +996,7 @@ static void store_atom_8(CPUState *cpu, uintptr_t ra, atmax = required_atomicity(cpu, pi, memop); switch (atmax) { case MO_8: - stq_he_p(pv, val); + stq_unaligned_p(pv, val); return; case MO_16: store_atom_8_by_2(pv, val);
Signature · 1 line
2.52.0
Re: [PATCH v2 4/4] system/memory: Rename unaligned load/store API
Quoted 3 lines · Philippe Mathieu-Daudé
Rename the API methods using the explicit 'unaligned' description instead of 'he' which stands for 'host endianness'.
I still think it would be easier to add a comment somewhere (or in documentation) that host endian stands for no swap just use what the host uses (that also explains what be|le will swap relative to) and then not rename any of these. The le|be variants are also based he so do you rename those to lduw_le_unaligned_p too? This gets unwieldy. If you want to get rid of he at any rate then maybe just drop it and make the host endian variants lduw_p without any endian notation but I see no problem keeping he and save the curn. Probably you only want to get rid of target endian or native endian and could leave the rest?
Regards,
BALATON Zoltan
Quoted 19 lines
Inspired-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
docs/devel/loads-stores.rst | 19 +++++++++---------- include/qemu/bswap.h | 34 +++++++++++++++++----------------- include/qemu/ldst_unaligned.h | 16 ++++++++-------- accel/tcg/translator.c | 6 +++--- hw/display/ati_2d.c | 2 +- hw/display/sm501.c | 19 +++++++++++-------- hw/remote/vfio-user-obj.c | 4 ++-- hw/vmapple/virtio-blk.c | 2 +- net/checksum.c | 6 +++--- system/memory.c | 4 ++-- system/physmem.c | 8 ++++---- ui/vnc-enc-tight.c | 2 +- util/bufferiszero.c | 6 +++--- accel/tcg/ldst_atomicity.c.inc | 10 +++++----- 14 files changed, 70 insertions(+), 68 deletions(-)
Re: [PATCH v2 4/4] system/memory: Rename unaligned load/store API
Quoted 6 lines · BALATON Zoltan
Quoted 3 lines · Philippe Mathieu-Daudé
Rename the API methods using the explicit 'unaligned' description instead of 'he' which stands for 'host endianness'.
I still think it would be easier to add a comment somewhere (or in documentation) that host endian stands for no swap just use what the host uses (that also explains what be|le will swap relative to) and then not rename any of these. The le|be variants are also based he so do you rename those to
lduw_le_unaligned_ptoo? This gets unwieldy. If you want to get rid of he at any rate then maybe just drop it and make the host endian variantslduw_pwithout any endian notation but I see no problem
lduw_p() implicitly uses *guest* endianness... If we remove it first, then w can have lduw_unaligned_p() become it. Quite some churn rework, but I'm OK to pay the price if the community is willing to go in this direction and we eventually get a clearer API.
Quoted 24 lines
keeping he and save the curn. Probably you only want to get rid of target endian or native endian and could leave the rest?
Regards,
BALATON ZoltanQuoted 19 lines
Inspired-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
docs/devel/loads-stores.rst | 19 +++++++++---------- include/qemu/bswap.h | 34 +++++++++++++++++----------------- include/qemu/ldst_unaligned.h | 16 ++++++++-------- accel/tcg/translator.c | 6 +++--- hw/display/ati_2d.c | 2 +-
hw/display/sm501.c | 19 +++++++++++-------- hw/remote/vfio-user-obj.c | 4 ++-- hw/vmapple/virtio-blk.c | 2 +-
net/checksum.c | 6 +++---
system/memory.c | 4 ++--
system/physmem.c | 8 ++++---- ui/vnc-enc-tight.c | 2 +-
util/bufferiszero.c | 6 +++--- accel/tcg/ldst_atomicity.c.inc | 10 +++++-----14 files changed, 70 insertions(+), 68 deletions(-)
Re: [PATCH v2 4/4] system/memory: Rename unaligned load/store API
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 5 lines · BALATON Zoltan
Quoted 3 lines · Philippe Mathieu-Daudé
Rename the API methods using the explicit 'unaligned' description instead of 'he' which stands for 'host endianness'.
Quoted 6 lines
Quoted 1 line
I still think it would be easier to add a comment somewhere (or in documentation) that host endian stands for no swap just use what the host uses (that also explains what be|le will swap relative to) and then not rename any of these. The le|be variants are also based he so do you rename those to
lduw_le_unaligned_ptoo? This gets unwieldy. If you want to get rid of he at any rate then maybe just drop it and make the host endian variantslduw_pwithout any endian notation but I see no problem
lduw_p()implicitly uses *guest* endianness... If we remove it first, then w can havelduw_unaligned_p()become it. Quite some churn rework, but I'm OK to pay the price if the community is willing to go in this direction and we eventually get a clearer API.
So then we could just leave it as "he" and document it better what it means, that seems to be the least churn to me. Adding unaligned only to the "he" variant does not seem to be improving naming as the others handle unaligned too so it's still unclear and renaming everyting would both be too long and too much churn. But if others think this improves it and is worth to do this rename for these he variants then I won't raise this again as I've explained my point sufficiently already. If nobody else cares then it's up to you.
Regards,
BALATON Zoltan
Quoted 21 lines
Quoted 19 lines
Quoted 19 lines
Inspired-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>---
docs/devel/loads-stores.rst | 19 +++++++++---------- include/qemu/bswap.h | 34 +++++++++++++++++----------------- include/qemu/ldst_unaligned.h | 16 ++++++++-------- accel/tcg/translator.c | 6 +++--- hw/display/ati_2d.c | 2 +-
hw/display/sm501.c | 19 +++++++++++-------- hw/remote/vfio-user-obj.c | 4 ++-- hw/vmapple/virtio-blk.c | 2 +-
net/checksum.c | 6 +++---
system/memory.c | 4 ++--
system/physmem.c | 8 ++++---- ui/vnc-enc-tight.c | 2 +-
util/bufferiszero.c | 6 +++--- accel/tcg/ldst_atomicity.c.inc | 10 +++++-----14 files changed, 70 insertions(+), 68 deletions(-)
Re: [PATCH v2 4/4] system/memory: Rename unaligned load/store API
Quoted 21 lines · BALATON Zoltan
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 5 lines · BALATON Zoltan
Quoted 3 lines · Philippe Mathieu-Daudé
Rename the API methods using the explicit 'unaligned' description instead of 'he' which stands for 'host endianness'.
Quoted 7 lines
I still think it would be easier to add a comment somewhere (or in documentation) that host endian stands for no swap just use what the host uses (that also explains what be|le will swap relative to) and then not rename any of these. The le|be variants are also based he so do you rename those to
lduw_le_unaligned_ptoo? This gets unwieldy. If you want to get rid of he at any rate then maybe just drop it and make the host endian variantslduw_pwithout any endian notation but I see no problemQuoted 4 lines
lduw_p()implicitly uses *guest* endianness... If we remove it first, then w can havelduw_unaligned_p()become it. Quite some churn rework, but I'm OK to pay the price if the community is willing to go in this direction and we eventually get a clearer API.
Quoted 8 lines
So then we could just leave it as "he" and document it better what it means, that seems to be the least churn to me. Adding unaligned only to the "he" variant does not seem to be improving naming as the others handle unaligned too so it's still unclear and renaming everyting would both be too long and too much churn. But if others think this improves it and is worth to do this rename for these he variants then I won't raise this again as I've explained my point sufficiently already. If nobody else cares then it's up to you.
I tend to agree with you -- _unaligned_ is rather long and obscures that we have this family of related functions.
The "no endianness indicator in the function name means target endianness" APIs are a bit of an unfortunate historical accident: we have ended up with a fair few places where we'd probably prefer to use the _le_ or _be_ versions explicitly instead these days. We could perhaps clean that up so they use a _te_ infix instead. I'm on the fence about whether I think that worth the effort or not.
-- PMM