On 22/01/2025 11.32, Philippe Mathieu-Daudé wrote:
As Daniel mentioned:

  "The number of instances of MachineClass is not large enough
   that we save a useful amount of memory through bitfields."

Also, see recent commit ecbf3567e21 ("docs/devel/style: add a
section about bitfield, and disallow them for packed structures").

Convert the MachineClass bitfields used as boolean as real ones.

Suggested-by: Daniel P. Berrangé <berra...@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
  include/hw/boards.h        | 14 +++++++-------
  hw/arm/aspeed.c            |  6 +++---
  hw/arm/fby35.c             |  4 ++--
  hw/arm/npcm7xx_boards.c    |  6 +++---
  hw/arm/raspi.c             |  6 +++---
  hw/arm/sbsa-ref.c          |  2 +-
  hw/arm/virt.c              |  2 +-
  hw/arm/xilinx_zynq.c       |  2 +-
  hw/avr/arduino.c           |  6 +++---
  hw/core/null-machine.c     | 10 +++++-----
  hw/i386/microvm.c          |  2 +-
  hw/i386/pc_piix.c          |  2 +-
  hw/i386/pc_q35.c           |  4 ++--
  hw/loongarch/virt.c        |  2 +-
  hw/m68k/virt.c             |  6 +++---
  hw/ppc/pnv.c               |  2 +-
  hw/ppc/spapr.c             |  2 +-
  hw/riscv/virt.c            |  2 +-
  hw/s390x/s390-virtio-ccw.c |  8 ++++----
  hw/xtensa/sim.c            |  2 +-
  20 files changed, 45 insertions(+), 45 deletions(-)

So if you are touching all these files, why not go with an even more meaningful rework instead? Flip the meaning of the "no_*" flags to the opposite, so that we e.g. have "has_default_cdrom" instead of "no_cdrom", then new boards would not have to remember to set these ugly "no_" flags anymore. It's quite a bit of work, but it could certainly be helpful in the long run.

 Thomas


diff --git a/include/hw/boards.h b/include/hw/boards.h
index 2ad711e56db..ff5904d6fd8 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -279,13 +279,13 @@ struct MachineClass {
      int max_cpus;
      int min_cpus;
      int default_cpus;
-    unsigned int no_serial:1,
-        no_parallel:1,
-        no_floppy:1,
-        no_cdrom:1,
-        no_sdcard:1,
-        pci_allow_0_address:1,
-        legacy_fw_cfg_order:1;
+    bool no_serial;
+    bool no_parallel;
+    bool no_floppy;
+    bool no_cdrom;
+    bool no_sdcard;
+    bool pci_allow_0_address;
+    bool legacy_fw_cfg_order;
      bool is_default;
      const char *default_machine_opts;
      const char *default_boot_order;


Reply via email to