dmd.expression: Utilize padding between Expression and derived AST nodes to store bitfields - #23604
dmd.expression: Utilize padding between Expression and derived AST nodes to store bitfields#23604ibuclaw wants to merge 1 commit into
Conversation
76e2bd7 to
b8eaefa
Compare
| * Returns: | ||
| * The previous value of `stageflags` | ||
| */ | ||
| extern (D) StageFlags setStageFlag(StageFlags flag) |
There was a problem hiding this comment.
Moving the stageflags field into bitFields could be done in a separate PR. Though it does nothing to reduce the instance size of StructLiteralExp itself.
|
FYI @rikkimax this |
…des to store bitfields - Reduces the class instance size of SliceExp from 57 -> 56. - Reduces the class instance size of StructLiteralExp from 72 -> 64. Can be used to make more space reductions too. - DsymbolExp, SymbolExp, DotVarExp, DelegateExp: hasOverloads field - StringExp, InterpExp, VectorExp, ArrayLiteralExp, AssocArrayLiteralExp: all contain ownByCtfe and bool flags that fit. - NewExp, VarExp, DotIdExp, CallExp, DeleteExp, ArrayExp, CommaExp, IndexExp: all contain bool flags that fit. - FuncExp, IsExp, CastExp, AssignExp, DefaultInitExp: all contain one or two byte fields that fit.
b8eaefa to
899d5ee
Compare
|
#23519 does the same slightly more transparently for all expressions. |
Oh nice that someone else came to the same realisation. :-) You can do it for more expressions. But I agree that the 16 byte allocations used by bump-the-pointer may well make it underwhelming. I was a bit annoyed of having reduced StringExp to a non-multiple of 8 ( |
rainers
left a comment
There was a problem hiding this comment.
My PR didn't touch stageFlags, so can add on top of this by also using astNodeBitFields on other Expressions.
| EXP op; // to minimize use of dynamic_cast | ||
| private: | ||
| uint8_t bitFields; | ||
| uint16_t astNodeBitFields; |
There was a problem hiding this comment.
I made bitFields an ushort instead in #23519, but that causes a padding byte before it. Your versions allows accessing all 21 remaining bits and is probably simpler most of the time. "Appending" to an existing bitfield might be needed with mutliple derivation steps, but I don't remember actually requiring that.
There was a problem hiding this comment.
I think you can get around that with the bitOff parameter.
class Base {
ushort padding;
}
class Derive1 : Base {
struct BitFields { ubyte field; }
mixin(generateBitFields!(BitFields, ushort, "padding");
}
class Derive2 : Derive1 {
struct BitFields { bool flag; }
mixin(generateBitFields!(BitFields, ushort, "padding", 8);
}It's a bit awkward, and I guess none of this is actually unit-tested. :-)
There was a problem hiding this comment.
I think you can get around that with the
bitOffparameter.
That's what the appendBitfields mixin in my PR does, but also evaluates the offset automatically from the base class.
|
@rainers FYI, these were the other two potential follow up commits.
|
I don't think that's much of a concern my end at least.
|
|
I'll leave this in draft for ~72h, so that everyone has enough time to reflect. Also, so I can consider what's going on in #23519 too. |
Unfortunately, dmd cannot do it ilke that, it has to be built with LDC or GDC to not increase compile times by about 30%.
Yes, the PR already does something similar, i.e. checks whether |
|
It's only a problem if the builds of LDC or GDC used for that never get updated again, which seems unlikely. It might just take a little while for things to improve. |
Can be used to make more space reductions too.