2 Replies Latest reply on Sep 17, 2009 1:25 PM by Schmendrick

    Logical right-shifts (>>) in Brook+  - is it possible?

    Schmendrick
      Is it possible to use Logical right-shift in Brook++ instead of Algebraic (sign-preserving) right shifts?

      Hello everyone!

      Here is my problem:

      Logical Right-shift for one bit (>>1):

      Before:

      01234567

      11000101 

      After:

      01234567

      01100010

      Logical right-shift always writes 0 at the new leftmost bit

       

      Algebraic Right-shift for one bit (>>1)

      Before:

      01234567

      11000101

      After:

      11100010

      Algebraic right-shift writes 0 as the leftmost bit, if the old leftmost bit was 0, and writes 1 if the old leftmost bit was 1 (this is to preserve the sign of the variable).

       

      The GPU supports both kinds of shifts. But the Brook+ seems to always use the sign-preserving version! And that is not even mentioned anywhere in the documentation!

      I've lost several days to find this out, since standard C uses the other (Logical) version of the shift.

      At the end i was able to make my code to behave correctly on the GPU, but the computational cost of the workaround was too high (~2-3 times slower then the non-workaround version).

      Now, I know that i can always go the GPU assembler route, but the astronomical number of lines of cryptic assembler code for my GPU kernel produced by the "kernel analyzer" app terrifies me to no end...


      So, here is the question:

      is it possible to switch the type of right-shift operation associated with ">>"in Brook+ from "Scalar Algebraic Shift Right"(ASHR_INT) to "Scalar Logical Shift Right" (LSHR_INT)?