On Tue, 13 Dec 2022 00:05:14 +0100 Philippe Mathieu-Daudé <phi...@linaro.org> wrote:
> Since the device endianness doesn't change at runtime, > use the cached value instead of evaluating it on each call. > > Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org> > --- > include/hw/virtio/virtio-access.h | 44 +++++++++++++++---------------- > 1 file changed, 22 insertions(+), 22 deletions(-) > > diff --git a/include/hw/virtio/virtio-access.h > b/include/hw/virtio/virtio-access.h > index 07aae69042..985f39fe16 100644 > --- a/include/hw/virtio/virtio-access.h > +++ b/include/hw/virtio/virtio-access.h > @@ -43,7 +43,7 @@ static inline uint16_t virtio_lduw_phys(VirtIODevice *vdev, > hwaddr pa) > { > AddressSpace *dma_as = vdev->dma_as; > > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { For x86, virtio_access_is_big_endian() expands to : static inline bool virtio_access_is_big_endian(VirtIODevice *vdev) { return false; } When I added these memory accessors, there was a strong requirement from MST that x86 shouldn't have to pay for an out-of-line check when it is known that everything is always little endian. Not sure exactly what you're trying to achieve with VirtIODevice::access_is_big_endian but this shouldn't mess with this fast path. > return lduw_be_phys(dma_as, pa); > } > return lduw_le_phys(dma_as, pa); > @@ -53,7 +53,7 @@ static inline uint32_t virtio_ldl_phys(VirtIODevice *vdev, > hwaddr pa) > { > AddressSpace *dma_as = vdev->dma_as; > > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return ldl_be_phys(dma_as, pa); > } > return ldl_le_phys(dma_as, pa); > @@ -63,7 +63,7 @@ static inline uint64_t virtio_ldq_phys(VirtIODevice *vdev, > hwaddr pa) > { > AddressSpace *dma_as = vdev->dma_as; > > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return ldq_be_phys(dma_as, pa); > } > return ldq_le_phys(dma_as, pa); > @@ -74,7 +74,7 @@ static inline void virtio_stw_phys(VirtIODevice *vdev, > hwaddr pa, > { > AddressSpace *dma_as = vdev->dma_as; > > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > stw_be_phys(dma_as, pa, value); > } else { > stw_le_phys(dma_as, pa, value); > @@ -86,7 +86,7 @@ static inline void virtio_stl_phys(VirtIODevice *vdev, > hwaddr pa, > { > AddressSpace *dma_as = vdev->dma_as; > > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > stl_be_phys(dma_as, pa, value); > } else { > stl_le_phys(dma_as, pa, value); > @@ -95,7 +95,7 @@ static inline void virtio_stl_phys(VirtIODevice *vdev, > hwaddr pa, > > static inline void virtio_stw_p(VirtIODevice *vdev, void *ptr, uint16_t v) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > stw_be_p(ptr, v); > } else { > stw_le_p(ptr, v); > @@ -104,7 +104,7 @@ static inline void virtio_stw_p(VirtIODevice *vdev, void > *ptr, uint16_t v) > > static inline void virtio_stl_p(VirtIODevice *vdev, void *ptr, uint32_t v) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > stl_be_p(ptr, v); > } else { > stl_le_p(ptr, v); > @@ -113,7 +113,7 @@ static inline void virtio_stl_p(VirtIODevice *vdev, void > *ptr, uint32_t v) > > static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > stq_be_p(ptr, v); > } else { > stq_le_p(ptr, v); > @@ -122,7 +122,7 @@ static inline void virtio_stq_p(VirtIODevice *vdev, void > *ptr, uint64_t v) > > static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return lduw_be_p(ptr); > } else { > return lduw_le_p(ptr); > @@ -131,7 +131,7 @@ static inline int virtio_lduw_p(VirtIODevice *vdev, const > void *ptr) > > static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return ldl_be_p(ptr); > } else { > return ldl_le_p(ptr); > @@ -140,7 +140,7 @@ static inline int virtio_ldl_p(VirtIODevice *vdev, const > void *ptr) > > static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return ldq_be_p(ptr); > } else { > return ldq_le_p(ptr); > @@ -150,9 +150,9 @@ static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, > const void *ptr) > static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s) > { > #if HOST_BIG_ENDIAN > - return virtio_access_is_big_endian(vdev) ? s : bswap16(s); > + return vdev->access_is_big_endian ? s : bswap16(s); > #else > - return virtio_access_is_big_endian(vdev) ? bswap16(s) : s; > + return vdev->access_is_big_endian ? bswap16(s) : s; > #endif > } > > @@ -160,7 +160,7 @@ static inline uint16_t > virtio_lduw_phys_cached(VirtIODevice *vdev, > MemoryRegionCache *cache, > hwaddr pa) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return lduw_be_phys_cached(cache, pa); > } > return lduw_le_phys_cached(cache, pa); > @@ -170,7 +170,7 @@ static inline uint32_t > virtio_ldl_phys_cached(VirtIODevice *vdev, > MemoryRegionCache *cache, > hwaddr pa) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return ldl_be_phys_cached(cache, pa); > } > return ldl_le_phys_cached(cache, pa); > @@ -180,7 +180,7 @@ static inline uint64_t > virtio_ldq_phys_cached(VirtIODevice *vdev, > MemoryRegionCache *cache, > hwaddr pa) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > return ldq_be_phys_cached(cache, pa); > } > return ldq_le_phys_cached(cache, pa); > @@ -190,7 +190,7 @@ static inline void virtio_stw_phys_cached(VirtIODevice > *vdev, > MemoryRegionCache *cache, > hwaddr pa, uint16_t value) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > stw_be_phys_cached(cache, pa, value); > } else { > stw_le_phys_cached(cache, pa, value); > @@ -201,7 +201,7 @@ static inline void virtio_stl_phys_cached(VirtIODevice > *vdev, > MemoryRegionCache *cache, > hwaddr pa, uint32_t value) > { > - if (virtio_access_is_big_endian(vdev)) { > + if (vdev->access_is_big_endian) { > stl_be_phys_cached(cache, pa, value); > } else { > stl_le_phys_cached(cache, pa, value); > @@ -216,9 +216,9 @@ static inline void virtio_tswap16s(VirtIODevice *vdev, > uint16_t *s) > static inline uint32_t virtio_tswap32(VirtIODevice *vdev, uint32_t s) > { > #if HOST_BIG_ENDIAN > - return virtio_access_is_big_endian(vdev) ? s : bswap32(s); > + return vdev->access_is_big_endian ? s : bswap32(s); > #else > - return virtio_access_is_big_endian(vdev) ? bswap32(s) : s; > + return vdev->access_is_big_endian ? bswap32(s) : s; > #endif > } > > @@ -230,9 +230,9 @@ static inline void virtio_tswap32s(VirtIODevice *vdev, > uint32_t *s) > static inline uint64_t virtio_tswap64(VirtIODevice *vdev, uint64_t s) > { > #if HOST_BIG_ENDIAN > - return virtio_access_is_big_endian(vdev) ? s : bswap64(s); > + return vdev->access_is_big_endian ? s : bswap64(s); > #else > - return virtio_access_is_big_endian(vdev) ? bswap64(s) : s; > + return vdev->access_is_big_endian ? bswap64(s) : s; > #endif > } >