I need a 96-bit long structure that I can place custom bit fields into. The fields' lengths are all over the place, 8, 3, 26, 56. It's important that they remain these exact lengths (with one exception, see below).
I see numerous ways of concatenating the data into a single, compact field: std::bitset, structs (holding the fields contiguously), and of course just using ints. However:
The
bitsetapproach is problematic, because operations need to happen really fast: bitset doesn't provide a method to instantly set range(x..y)out of the whole range(0..96), with one atomic operation. Damned if I'm going to loop to set individual bits.The
structapproach is problematic, because of this restriction on length.The
intapproach is problematic, becauseint64_tis not long enough. I can of course use anint32_talongside this, however see below.
One solution that is obvious is to put the 56 + 8 fields into an int64_t, and the rest into an int32_t. The problem here is that the 56-long field is the only one which may in fact be reduced later on in development, and that will mean I will have some spare bits in the int64_t, and some 32 - (26 + 3) = 3 spare bits in the int32_t.
Are there any ways to store these as compactly as possible (from a code standpoint) while still being able to access broad areas by masking (unlike std::bitset)?