bswap: Cleanups around 'qemu/bswap.h' header
Subsystems (3)
v2 cover bswap: Cleanups around 'qemu/bswap.h' header
The point of this cleanup series is to avoid a circular dependency problem between "qemu/bswap.h" and "exec/memop.h", since I want to add a ld/st variant in "qemu/bswap.h" that takes a MemOp arg.
Otherwise I get:
In file included from ../../util/qemu-timer-common.c:25:
In file included from include/qemu/timer.h:4:
In file included from include/qemu/bitops.h:16:
In file included from include/qemu/host-utils.h:33:
In file included from include/qemu/bswap.h:6:
include/exec/memop.h:182:19: error: call to undeclared function 'ctz32'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
182 | return (MemOp)ctz32(size);
| ^
In file included from ../../util/qemu-timer-common.c:25:
In file included from include/qemu/timer.h:4:
In file included from include/qemu/bitops.h:16:
include/qemu/host-utils.h:236:19: error: static declaration of 'ctz32' follows non-static declaration
236 | static inline int ctz32(uint32_t val)
| ^
include/exec/memop.h:182:19: note: previous implicit declaration is here
182 | return (MemOp)ctz32(size);
| ^
2 errors generated.
Philippe Mathieu-Daudé (4):
tests/qtest: Remove unnecessary 'qemu/bswap.h' include
bswap: Use 'qemu/bswap.h' instead of 'qemu/host-utils.h'
bswap: Include missing 'qemu/bswap.h' header
bswap: Consistently use builtin bswap() functions
block/qcow2.h | 1 + include/qemu/host-utils.h | 7 +++---- include/qemu/int128.h | 7 +++---- tests/qtest/pnv-xive2-common.h | 1 - audio/audio.c | 1 + block/blklogwrites.c | 1 + block/export/vduse-blk.c | 1 + block/export/vhost-user-blk-server.c | 1 + block/export/virtio-blk-handler.c | 1 + block/parallels-ext.c | 1 + hw/9pfs/9p-local.c | 1 + hw/block/cdrom.c | 1 + hw/block/hd-geometry.c | 1 + hw/net/can/ctucan_core.c | 1 + hw/nvram/xlnx-efuse.c | 1 + hw/scsi/scsi-generic.c | 1 + hw/sd/sd.c | 1 + hw/sd/ssi-sd.c | 1 + net/l2tpv3.c | 1 + qga/commands-linux.c | 1 + scsi/pr-manager-helper.c | 1 + target/arm/tcg/arith_helper.c | 1 + tests/qtest/acpi-utils.c | 1 + tests/qtest/ahci-test.c | 2 +- tests/qtest/aspeed-hace-utils.c | 1 + tests/qtest/aspeed_smc-test.c | 1 - tests/qtest/ast2700-smc-test.c | 1 - tests/qtest/bios-tables-test.c | 1 + tests/qtest/libqos/ahci.c | 2 +- tests/qtest/libqos/fw_cfg.c | 1 - tests/qtest/libqos/generic-pcihost.c | 2 +- tests/qtest/libqos/i2c-omap.c | 1 - tests/qtest/libqos/igb.c | 1 + tests/qtest/libqos/pci-spapr.c | 2 +- tests/qtest/libqos/virtio-9p-client.c | 1 + tests/qtest/migration/framework.c | 1 + tests/qtest/npcm7xx_emc-test.c | 1 + tests/qtest/pnv-spi-seeprom-test.c | 1 - tests/qtest/tpm-emu.c | 1 + tests/qtest/ufs-test.c | 1 + tests/qtest/vmgenid-test.c | 1 + tests/unit/test-hbitmap.c | 1 + util/bitmap.c | 1 + util/hbitmap.c | 2 +- 44 files changed, 42 insertions(+), 19 deletions(-)
Signature · 1 line
2.52.0
PATCH v2 1/4 tests/qtest: Remove unnecessary 'qemu/bswap.h' include
None of these files use API declared in "qemu/bswap.h", remove the unnecessary inclusion.
--- tests/qtest/pnv-xive2-common.h | 1 - tests/qtest/aspeed_smc-test.c | 1 - tests/qtest/ast2700-smc-test.c | 1 - tests/qtest/libqos/fw_cfg.c | 1 - tests/qtest/libqos/i2c-omap.c | 1 - tests/qtest/pnv-spi-seeprom-test.c | 1 - 6 files changed, 6 deletions(-)
tests/qtest/pnv-xive2-common.h +0 -1
@@ -15,7 +15,6 @@#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs))#define PPC_BITMASK32 (bs, be) ((PPC_BIT32(bs) - PPC_BIT32(be)) | \ PPC_BIT32(bs)) -#include "qemu/bswap.h" #include "hw/intc/pnv_xive2_regs.h" #include "hw/ppc/xive_regs.h" #include "hw/ppc/xive2_regs.h"
tests/qtest/aspeed_smc-test.c +0 -1
@@ -24,7 +24,6 @@*/ #include "qemu/osdep.h" -#include "qemu/bswap.h" #include "libqtest-single.h" #include "qemu/bitops.h" #include "aspeed-smc-utils.h"
tests/qtest/ast2700-smc-test.c +0 -1
@@ -7,7 +7,6 @@*/ #include "qemu/osdep.h" -#include "qemu/bswap.h" #include "libqtest-single.h" #include "qemu/bitops.h" #include "aspeed-smc-utils.h"
tests/qtest/libqos/fw_cfg.c +0 -1
@@ -17,7 +17,6 @@#include "malloc-pc.h" #include "libqos-malloc.h" #include "../libqtest.h" -#include "qemu/bswap.h" #include "hw/nvram/fw_cfg.h" void qfw_cfg_select (QFWCFG *fw_cfg,uint16_t key)
tests/qtest/libqos/i2c-omap.c +0 -1
@@ -10,7 +10,6 @@#include "i2c.h" -#include "qemu/bswap.h" #include "../libqtest.h" enum OMAPI2CRegisters {
tests/qtest/pnv-spi-seeprom-test.c +0 -1
@@ -7,7 +7,6 @@*/ #include "qemu/osdep.h" #include "libqtest.h" -#include "qemu/bswap.h" #include "hw/ssi/pnv_spi_regs.h" #include "pnv-xscom.h"
Signature · 1 line
2.52.0
PATCH v2 2/4 bswap: Use 'qemu/bswap.h' instead of 'qemu/host-utils.h'
In reply to Philippe Mathieu-DaudéThese files only require "qemu/bswap.h", not "qemu/host-utils.h".
--- tests/qtest/ahci-test.c | 2 +- tests/qtest/libqos/ahci.c | 2 +- tests/qtest/libqos/generic-pcihost.c | 2 +- tests/qtest/libqos/pci-spapr.c | 2 +- util/hbitmap.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
tests/qtest/ahci-test.c +1 -1
@@ -31,7 +31,7 @@#include "libqos/pci-pc.h" #include "qobject/qdict.h" -#include "qemu/host-utils.h" +#include "qemu/bswap.h" #include "hw/pci/pci_ids.h" #include "hw/pci/pci_regs.h"
tests/qtest/libqos/ahci.c +1 -1
@@ -28,7 +28,7 @@#include "ahci.h" #include "pci-pc.h" -#include "qemu/host-utils.h" +#include "qemu/bswap.h" #include "hw/pci/pci_ids.h" #include "hw/pci/pci_regs.h"
tests/qtest/libqos/generic-pcihost.c +1 -1
@@ -15,7 +15,7 @@#include "generic-pcihost.h" #include "qobject/qdict.h" #include "hw/pci/pci_regs.h" -#include "qemu/host-utils.h" +#include "qemu/bswap.h" #include "qemu/module.h"
tests/qtest/libqos/pci-spapr.c +1 -1
@@ -13,7 +13,7 @@#include "hw/pci/pci_regs.h" -#include "qemu/host-utils.h" +#include "qemu/bswap.h" #include "qemu/module.h" /*
util/hbitmap.c +1 -1
@@ -10,8 +10,8 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "qemu/hbitmap.h" -#include "qemu/host-utils.h" #include "trace.h" #include "crypto/hash.h"
Signature · 1 line
2.52.0
Re: [PATCH v2 2/4] bswap: Use 'qemu/bswap.h' instead of 'qemu/host-utils.h'
Quoted 6 lines · Philippe Mathieu-Daudé
tests/qtest/libqos/ahci.c +0
-0
tests/qtest/libqos/ahci.c line 34
Quoted 8 lines
tests/qtest/libqos/ahci.c +1
-1@@ -28,7 +28,7 @@#include "ahci.h" #include "pci-pc.h" -#include "qemu/host-utils.h" +#include "qemu/bswap.h" #include "hw/pci/pci_ids.h" #include "hw/pci/pci_regs.h"
I'm getting a compilation error in ahci.c:
../tests/qtest/libqos/ahci.c: In function ‘ahci_hba_enable’:
../tests/qtest/libqos/ahci.c:252:52: error: implicit declaration of function ‘ctzl’ [-Werror=implicit-function-declaration]
ctzl is defined in host-utils.h. (Build platform is Ubuntu 24.04 x86_64)
Jim
PATCH v2 3/4 bswap: Include missing 'qemu/bswap.h' header
In reply to Philippe Mathieu-DaudéAll these files indirectly include the "qemu/bswap.h" header. Make this inclusion explicit to avoid build errors when refactoring unrelated headers.
--- block/qcow2.h | 1 + audio/audio.c | 1 + block/blklogwrites.c | 1 + block/export/vduse-blk.c | 1 + block/export/vhost-user-blk-server.c | 1 + block/export/virtio-blk-handler.c | 1 + block/parallels-ext.c | 1 + hw/9pfs/9p-local.c | 1 + hw/block/cdrom.c | 1 + hw/block/hd-geometry.c | 1 + hw/net/can/ctucan_core.c | 1 + hw/nvram/xlnx-efuse.c | 1 + hw/scsi/scsi-generic.c | 1 + hw/sd/sd.c | 1 + hw/sd/ssi-sd.c | 1 + net/l2tpv3.c | 1 + qga/commands-linux.c | 1 + scsi/pr-manager-helper.c | 1 + target/arm/tcg/arith_helper.c | 1 + tests/qtest/acpi-utils.c | 1 + tests/qtest/aspeed-hace-utils.c | 1 + tests/qtest/bios-tables-test.c | 1 + tests/qtest/libqos/igb.c | 1 + tests/qtest/libqos/virtio-9p-client.c | 1 + tests/qtest/migration/framework.c | 1 + tests/qtest/npcm7xx_emc-test.c | 1 + tests/qtest/tpm-emu.c | 1 + tests/qtest/ufs-test.c | 1 + tests/qtest/vmgenid-test.c | 1 + tests/unit/test-hbitmap.c | 1 + util/bitmap.c | 1 + 31 files changed, 31 insertions(+)
block/qcow2.h +1 -0
@@ -26,6 +26,7 @@#define BLOCK_QCOW2_H #include "crypto/block.h" +#include "qemu/bswap.h" #include "qemu/coroutine.h" #include "qemu/units.h" #include "block/block_int.h"
audio/audio.c +1 -0
@@ -32,6 +32,7 @@#include "qapi/qapi-visit-audio.h" #include "qapi/qapi-commands-audio.h" #include "qobject/qdict.h" +#include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/log.h" #include "qemu/module.h"
block/blklogwrites.c +1 -0
@@ -16,6 +16,7 @@#include "block/block_int.h" #include "qobject/qdict.h" #include "qobject/qstring.h" +#include "qemu/bswap.h" #include "qemu/cutils.h" #include "qemu/module.h" #include "qemu/option.h"
block/export/vduse-blk.c +1 -0
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include <sys/eventfd.h> +#include "qemu/bswap.h" #include "qapi/error.h" #include "block/export.h" #include "qemu/error-report.h"
block/export/vhost-user-blk-server.c +1 -0
@@ -10,6 +10,7 @@* later. See the COPYING file in the top-level directory. */ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "qemu/error-report.h" #include "block/block.h" #include "subprojects/libvhost-user/libvhost-user.h" /* only for the type definitions */
block/export/virtio-blk-handler.c +1 -0
@@ -13,6 +13,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "qemu/error-report.h" #include "virtio-blk-handler.h"
block/parallels-ext.c +1 -0
@@ -30,6 +30,7 @@#include "block/dirty-bitmap.h" #include "parallels.h" #include "crypto/hash.h" +#include "qemu/bswap.h" #include "qemu/uuid.h" #include "qemu/memalign.h"
hw/9pfs/9p-local.c +1 -0
@@ -28,6 +28,7 @@#include <sys/un.h> #include "qemu/xattr.h" #include "qapi/error.h" +#include "qemu/bswap.h" #include "qemu/cutils.h" #include "qemu/error-report.h" #include "qemu/option.h"
hw/block/cdrom.c +1 -0
@@ -26,6 +26,7 @@here. */ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "hw/scsi/scsi.h" static void lba_to_msf (uint8_t *buf,int lba)
hw/block/hd-geometry.c +1 -0
@@ -31,6 +31,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "system/block-backend.h" #include "qapi/qapi-types-block.h" #include "hw/block/block.h"
hw/net/can/ctucan_core.c +1 -0
@@ -29,6 +29,7 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/bitops.h" +#include "qemu/bswap.h" #include "hw/core/irq.h" #include "migration/vmstate.h" #include "net/can_emu.h"
hw/nvram/xlnx-efuse.c +1 -0
@@ -27,6 +27,7 @@#include "qemu/osdep.h" #include "hw/nvram/xlnx-efuse.h" +#include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/log.h" #include "qapi/error.h"
hw/scsi/scsi-generic.c +1 -0
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/bswap.h" #include "qemu/ctype.h" #include "qemu/error-report.h" #include "qemu/module.h"
hw/sd/sd.c +1 -0
@@ -35,6 +35,7 @@#include "qemu/osdep.h" #include "qemu/units.h" #include "qemu/cutils.h" +#include "qemu/bswap.h" #include "hw/core/irq.h" #include "hw/core/registerfields.h" #include "system/block-backend.h"
hw/sd/ssi-sd.c +1 -0
@@ -19,6 +19,7 @@#include "hw/ssi/ssi.h" #include "migration/vmstate.h" #include "hw/sd/sd.h" +#include "qemu/bswap.h" #include "qemu/crc-ccitt.h" #include "qom/object.h"
net/l2tpv3.c +1 -0
@@ -29,6 +29,7 @@#include "net/net.h" #include "clients.h" #include "qapi/error.h" +#include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/sockets.h"
qga/commands-linux.c +1 -0
@@ -12,6 +12,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "qapi/error.h" #include "qga-qapi-commands.h" #include "qapi/error.h"
scsi/pr-manager-helper.c +1 -0
@@ -19,6 +19,7 @@#include "pr-helper.h" #include "qapi/qapi-events-block.h" #include "qemu/module.h" +#include "qemu/bswap.h" #include <scsi/sg.h> #include "qom/object.h"
target/arm/tcg/arith_helper.c +1 -0
@@ -6,6 +6,7 @@* SPDX-License-Identifier: GPL-2.0-or-later */ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "qemu/crc32c.h" #include <zlib.h> /* for crc32 */
tests/qtest/acpi-utils.c +1 -0
@@ -15,6 +15,7 @@#include "qemu/osdep.h" #include <glib/gstdio.h> #include "qemu/bitmap.h" +#include "qemu/bswap.h" #include "acpi-utils.h" #include "boot-sector.h"
tests/qtest/aspeed-hace-utils.c +1 -0
@@ -8,6 +8,7 @@#include "qemu/osdep.h" #include "libqtest.h" #include "qemu/bitops.h" +#include "qemu/bswap.h" #include "aspeed-hace-utils.h" /*
tests/qtest/bios-tables-test.c +1 -0
@@ -59,6 +59,7 @@#include <glib/gstdio.h> #include "hw/firmware/smbios.h" #include "qemu/bitmap.h" +#include "qemu/bswap.h" #include "acpi-utils.h" #include "boot-sector.h" #include "tpm-emu.h"
tests/qtest/libqos/igb.c +1 -0
@@ -27,6 +27,7 @@#include "qemu/iov.h" #include "qemu/module.h" #include "qemu/bitops.h" +#include "qemu/bswap.h" #include "libqos-malloc.h" #include "qgraph.h" #include "e1000e.h"
tests/qtest/libqos/virtio-9p-client.c +1 -0
@@ -13,6 +13,7 @@*/ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "virtio-9p-client.h" #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000)
tests/qtest/migration/framework.c +1 -0
@@ -21,6 +21,7 @@#include "qapi/error.h" #include "qobject/qjson.h" #include "qobject/qlist.h" +#include "qemu/bswap.h" #include "qemu/module.h" #include "qemu/option.h" #include "qemu/range.h"
tests/qtest/npcm7xx_emc-test.c +1 -0
@@ -19,6 +19,7 @@#include "qobject/qdict.h" #include "qobject/qnum.h" #include "qemu/bitops.h" +#include "qemu/bswap.h" #include "qemu/iov.h" /* Name of the emc device. */
tests/qtest/tpm-emu.c +1 -0
@@ -16,6 +16,7 @@#include "backends/tpm/tpm_ioctl.h" #include "io/channel-socket.h" #include "qapi/error.h" +#include "qemu/bswap.h" #include "qobject/qlist.h" #include "qobject/qstring.h" #include "tpm-emu.h"
tests/qtest/ufs-test.c +1 -0
@@ -14,6 +14,7 @@#include "scsi/constants.h" #include "block/ufs.h" #include "qemu/bitmap.h" +#include "qemu/bswap.h" #define DWORD_BYTE 4/* Test images sizes in Bytes */
tests/qtest/vmgenid-test.c +1 -0
@@ -10,6 +10,7 @@#include "qemu/osdep.h" #include "qemu/bitmap.h" +#include "qemu/bswap.h" #include "qemu/uuid.h" #include "hw/acpi/acpi-defs.h" #include "boot-sector.h"
tests/unit/test-hbitmap.c +1 -0
@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu/hbitmap.h" #include "qemu/bitmap.h" +#include "qemu/bswap.h" #include "block/block.h" #define LOG_BITS_PER_LONG (BITS_PER_LONG == 32 ? 5 : 6)
util/bitmap.c +1 -0
@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "qemu/bitops.h" #include "qemu/bitmap.h" +#include "qemu/bswap.h" #include "qemu/atomic.h" /*
Signature · 1 line
2.52.0
PATCH v2 4/4 bswap: Consistently use builtin bswap() functions
In reply to Philippe Mathieu-DaudéSince these headers use some __builtin_bswap*(), use it consistently in all the cases, allowing to remove the "qemu/bswap.h" inclusion (which only defines bswap* to the builtin equivalent).
--- include/qemu/host-utils.h | 7 +++---- include/qemu/int128.h | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-)
include/qemu/host-utils.h +3 -4
@@ -30,7 +30,6 @@#ifndef HOST_UTILS_H #define HOST_UTILS_H -#include "qemu/bswap.h" #include "qemu/int128.h" #ifdef CONFIG_INT128
@@ -380,7 +379,7 @@ static inline uint16_t revbit16(uint16_t x)return __builtin_bitreverse16 (x);#else /* Assign the correct byte position. */ - x =bswap16 (x); + x =__builtin_bswap16 (x);/* Assign the correct nibble position. */ x = ((x &0xf0f0 ) >>4 ) | ((x &0x0f0f ) <<4 );
@@ -403,7 +402,7 @@ static inline uint32_t revbit32(uint32_t x)return __builtin_bitreverse32 (x);#else /* Assign the correct byte position. */ - x =bswap32 (x); + x =__builtin_bswap32 (x);/* Assign the correct nibble position. */ x = ((x &0xf0f0f0f0u ) >>4 ) | ((x &0x0f0f0f0fu ) <<4 );
@@ -426,7 +425,7 @@ static inline uint64_t revbit64(uint64_t x)return __builtin_bitreverse64 (x);#else /* Assign the correct byte position. */ - x =bswap64 (x); + x =__builtin_bswap64 (x);/* Assign the correct nibble position. */ x = ((x &0xf0f0f0f0f0f0f0f0ull ) >>4 ) | ((x &0x0f0f0f0f0f0f0f0full ) <<4 );
include/qemu/int128.h +3 -4
@@ -1,8 +1,6 @@#ifndef INT128_H #define INT128_H -#include "qemu/bswap.h" -/* * With TCI, we need to use libffi for interfacing with TCG helpers. * But libffi does not support __int128_t, and therefore cannot pass
@@ -189,7 +187,8 @@ static inline Int128 bswap128(Int128 a)#if __has_builtin (__builtin_bswap128)return __builtin_bswap128 (a);#else -return int128_make128 (bswap64 (int128_gethi (a)),bswap64 (int128_getlo (a))); +return int128_make128 (__builtin_bswap64 (int128_gethi (a)), +__builtin_bswap64 (int128_getlo (a)));#endif }
@@ -451,7 +450,7 @@ static inline void int128_subfrom(Int128 *a, Int128 b)static inline Int128 bswap128 (Int128 a) { -return int128_make128 (bswap64 (a.hi),bswap64 (a.lo)); +return int128_make128 (__builtin_bswap64 (a.hi),__builtin_bswap64 (a.lo)); }static inline int clz128 (Int128 a)
Signature · 1 line
2.52.0
Re: [PATCH v2 4/4] bswap: Consistently use builtin bswap() functions
Quoted 10 lines · Philippe Mathieu-Daudé
Since these headers use some __builtin_bswap*(), use it consistently in all the cases, allowing to remove the "
qemu/bswap.h" inclusion (which only defines bswap* to the builtin equivalent).Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/qemu/host-utils.h | 7 +++---- include/qemu/int128.h | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-)
r~