kvm-guest-drivers-windows icon indicating copy to clipboard operation
kvm-guest-drivers-windows copied to clipboard

viogpu_queue: rearrange virtio_gpu_vbuffer struct to reduce size by 8 bytes

Open sharkautarch opened this issue 8 months ago • 4 comments

Signed-off-by: sharkautarch [email protected]

Note that this change only makes a difference for x86_64 and ARM64 targets; the size of the struct will remain the same for x86.

This struct isn't packed, so padding/alignment of each member can increase the size. Reduces size of the struct from 72 bytes to 64 bytes. tested in godbolt: https://godbolt.org/z/M7abMvYhh

Rearrangement is based off of the idea of ordering the members of a struct from biggest to smallest. (I learned about that trick from a comment in this video about padding/alignment: https://www.youtube.com/watch?v=E0QhZ6tNoRg)

EDIT: I just realized that u32 is actually unsigned long (defined in VirtIO/linux/types.h), but it is still only 32 bits (same size as unsigned int because apparently long is 32 bits on 64bit windows). which I guess is why it is called u32 updated godbolt: https://godbolt.org/z/ffeGh4nvT clang now prints out 72 bytes for both, but the assembly for msvc x64 shows that the size is still reduced to 64 bytes

sharkautarch avatar Jun 11 '24 15:06 sharkautarch