DRuiz9
New Contributor
5 years agoOpenCL Intel FPGA shift and masking
Hi. I'm trying to perform shift right operations via bit masking. I want realize a 16 bit right shift, therefore I have to take only the 16 MSB from the result. value variable is a 32 bits integer. One way to achieve this that works (obviously) is apply :
result = value >> 16
The Intel OpenCL documentation puts an example to use masking:
__kernel fixed_point_add (__global const unsigned int * restrict a, __global const unsigned int * restrict b, __global unsigned int * restrict result) { size_t gid = get_global_id(0); unsigned int temp; temp = 0x3_FFFF & ((0x1_FFFF & a[gid]) + ((0x1_FFFF & b[gid])); result[gid] = temp & 0x3_FFFF; }
I understand that:
- 0x1_FFFF := 0000 0000 0000 0001 1111 1111 1111 1111
- 0x3_FFFF := 0000 0000 0000 0011 1111 1111 1111 1111
Thus, to get the 16 MSB bits I will have to set a mask like this:
- 0xFFFF0000 := 1111 1111 1111 1111 0000 0000 0000 0000
result = (0xFFFF0000 & value)
But, the result that I get is always 0...
To sum up:
- How it actually works bit masking in OpenCL?
- Is possible get specific bits from a int data type and assign them to other int?