From d9a460b2b6190096f2a546e1f9cdc89885b512ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 1 Jul 2025 13:39:00 +0200 Subject: [PATCH] Adjust bitfields in struct Condition As is usually the case, the bitfields don't create the expected space savings, because the field that follows needs to be aligned. But we don't want to fully drop the bitfields here, because then ConditionType and ConditionResult are each 4 bytes, and the whole struct grows from 32 to 40 bytes (on amd64). We potentially have lots of little Conditions and that'd waste some memory. Make each of the four fields one byte. This still allows the compiler to generate simpler code without changing the struct size: E.g. in condition_test: c->result = CONDITION_ERROR; - 78fab: 48 8b 45 e8 mov -0x18(%rbp),%rax - 78faf: 0f b6 50 01 movzbl 0x1(%rax),%edx - 78fb3: 83 e2 03 and $0x3,%edx - 78fb6: 83 ca 0c or $0xc,%edx - 78fb9: 88 50 01 mov %dl,0x1(%rax) + 78f8b: 48 8b 45 e8 mov -0x18(%rbp),%rax + 78f8f: c6 40 03 03 movb $0x3,0x3(%rax) --- src/shared/condition.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/shared/condition.h b/src/shared/condition.h index c25b9643b90..90d896c85ce 100644 --- a/src/shared/condition.h +++ b/src/shared/condition.h @@ -58,12 +58,13 @@ typedef enum ConditionResult { } ConditionResult; typedef struct Condition { + /* Use bitfields for ConditionType and ConditionResult to keep the whole struct in 32 bytes. */ ConditionType type:8; - bool trigger:1; - bool negate:1; + bool trigger; + bool negate; - ConditionResult result:6; + ConditionResult result:8; char *parameter; -- 2.47.3