OpenCL fake bitfield

Is it possible AT ALL? I know that OpenCL doesn't support normal bitfields right now.

Could there be a way to get a definite 64-bits out of bool myBool[64] or something like

union newType{
    double value;
    bool bit[64];
};

or anything at all remotely related that could be helpful? i'ld like to have some static bit patterns to compare against value and be able to quickly manipulate single bits of the patterns.

Upvotes: 1

Views: 1481

Answers (2)

user57368
user57368

Reputation: 5765

The OpenCL Spec guarantees that a double will be 64 bits and that you can reinterpret it using as_long() or a union to get a long, which is 64 bits.

Reinterpreting a 64 bit scalar to something like a char[8] or a char8 is legal (using a union and as_char8() respectively), but the result is implementation-defined. Things like endianness conversions may occur, so you may have to watch out if your GPU behaves differently from your CPU in that respect.

The only portable way to do bit manipulation on a double is to use bitwise operators on a 64-bit scalar integer type, meaining long or ulong.

Upvotes: 2

EnabrenTane
EnabrenTane

Reputation: 7466

Yes it is possible. Use binary operators on a 64 bit int, Not sure if 64 bit ints are valid, so just make a struct with 2 ints and mask and shift as desired.

I suggest you investigate the operators & | ^ ~

Upvotes: 1

Related Questions