viogpu_queue: rearrange virtio_gpu_vbuffer struct to reduce size by 8 bytes #1106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signed-off-by: sharkautarch 128002472+sharkautarch@users.noreply.github.com
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 actuallyunsigned long
(defined in VirtIO/linux/types.h), but it is still only 32 bits (same size asunsigned int
because apparentlylong
is 32 bits on 64bit windows). which I guess is why it is called u32updated 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