Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20703 Discussions

OpenCL Intel FPGA shift and masking

DRuiz9
Novice
506 Views

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:

  1. How it actually works bit masking in OpenCL?
  2. Is possible get specific bits from a int data type and assign them to other int? 
0 Kudos
1 Reply
AnilErinch_A_Intel
404 Views

Hi ,

You can try the different bit wise operations as a sample code then print the results to understand their operations.

Thanks and Regards

Anil


0 Kudos
Reply