third draft: add bitfields to D
Dom DiSc
dominikus at scherkl.de
Sun Jul 21 10:25:29 UTC 2024
On Sunday, 21 July 2024 at 06:14:05 UTC, IchorDev wrote:
> Let's say we have a 64 bit pointer (U='unused'; P=pointer bits;
> X=zeroed bits ; C=our data):
> `UUUUUUUU UUUUUUUU PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP
> PPPPPPPP`
> Now we shift 3 bits to the right:
> `XXXUUUUU UUUUUUUU UUUPPPPP PPPPPPPP PPPPPPPP PPPPPPPP PPPPPPPP
> PPPPPPPP`
> We just lost the 3 least significant bits of the original
> pointer, so unless it was storing a multiple of 8 we just lost
> important data.
No. This is a misunderstanding.
My idea is to store all pointers as "61bit address"+"3bit
bitoffset (0..7 within a byte). No lower bits will be lost.
To read we give the system only the address (so p>>3) and then
mask out the requested bit. Of course this address will contain 3
leading (unused) zeroes. As long as the system don't abuse these
unused bits, everything is fine.
Also this is no "extra data". It's just adding the 3 missing
address lines that are necessary to address single bits instead
of blocks of 8 bits (yes, bytes are just a 8bit alignment, they
shouldn't be fundamental - but as long as these 3 lines are
missing, we need a workaround like in the 68000er times, where
another line was missing). And yes, the workaround is time
consuming - but really not that bad. And less bad if you require
"even" types to be aligned to there size, as it is also required
for bytes and shorts or even for ints on 64bit systems.
More information about the dip.development
mailing list