Bitmagic !

We need a way to produce realy compacted bit encodings that
can be compressed into variables, or bit arrays.

Eg. we need a way to read/write single bits from/to a holder variable, like
a one byte variable like bool char or __int8.

A 1 byte variable like bool, contains 8 bits, where only one would suffice.
This way 8 booleans could be compressed into one bolean type variable.

That is; people who striclty use boolean encodings could have their solutions run 8 times faster, and take 8 times less memory, probably increasing the benefit of shared memory substantialy.

Similarly an 8 bit int which contain 8 bits, could descripe 4 2 bit numbers
(of 1-4)…

etc ect

But since Cuda does not support Bit Fields, what is a good way of acheiving this ??,
I know Simon Greens image proccessing example puts 4 8 bit int’s into one 32 bit float.

But I need to put 1 boolean, 1 3 bit int, and one 4 bit int, into a 8 bit container (like bool or __int8 or whatever is the best…)

Dear Cuda Gurus, does there exist a good solution for this ?

Is there bit array support in Cuda ??

Have you checked if you can use AND and OR, bit flags and bit shifts to do this? The meaning is the same as bit arrays, only the syntax is different really.

Thanks kristleifur, youre right, it wasnt that hard after all, these seems to work fine;

//get a bit from a variable
#define GETBIT(var, bit)(((var) >> (bit)) & 1)

//set a bit to 1
#define SETBIT(var, bit)var |= (1 << (bit))

//set a bit to 0
#define CLRBIT(var, bit)var &= (~(1 << (bit)))