Results 1 to 5 of 5

Thread: Global Pointer - Bitwise operation

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2019
    Posts
    4

    Global Pointer - Bitwise operation

    Hi There,

    Is it possible to perform a bitwise xor, and, or on a __global uint * pointer in OpenCL? I'm trying to do this but compiler throws me an error.
    The goal is to perform something like:
    __global uint *p = an address on global memory
    then
    *p = some value
    *(p ^ 1) = other value

    In C we can manipulate pointers freely - can it be done on OpenCL?

    Thanks in advance.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2011
    Posts
    270
    Why not share the error the compiler threw? It would be helpful. Was it that "1" isn't the same type as "p"? If so, perhaps `*(p ^ (__global uint *)1)` would work. If not, try casting the pointer to an unsigned integer of the same width, then doing your bitops there, and then casting back.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2019
    Posts
    4
    Hi There,

    I have tried what you proposed - something like:
    __global uint *p1 = p2 ^ (__global uint *)1 (where p2 is a valid __global uint *)
    however compiler throws: "invalid operands to binary expression ('__global uint *' and '__global uint *')

  4. #4
    Senior Member Regular Contributor
    Join Date
    Dec 2011
    Posts
    270
    Seems like you'll need to use the cast to int, do xor, cast to ptr route.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2019
    Posts
    4
    OK - casting to ulong - then XORing - then cast to __global uint * - worked like a charm. Thanks.

    __global uint *p1 = (__global uint *)((ulong)p2 ^ 1);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean