1 Reply Latest reply on Dec 24, 2009 12:03 AM by MicahVillmow

    Undefined behavior when indexing vector components

    BarnacleJunior

      Both the nvidia and ATI drivers compile this code without warning, but both exhibit apparently undefined behavior..

      In D3D you can index a vector component with [].  eg:

      uint4 foo; foo[2] = 3;  // now foo.z is 3.

      The OpenCL compilers compile that, but they don't work!

      eg


          // Load in a and b terms
          uint4 a, b;
         
          /*
          for(int i = 0; i < 4; ++i) {
              a = pass1_values[leftIndex + i];
              b
      = pass1_values[rightIndex + i];
          }
          */
          a.x = pass1_values[leftIndex + 0];
          a.y = pass1_values[leftIndex + 1];
          a.z = pass1_values[leftIndex + 2];
          a.w = pass1_values[leftIndex + 3];
          b.x = pass1_values[rightIndex + 0];
          b.y = pass1_values[rightIndex + 1];
          b.z = pass1_values[rightIndex + 2];
          b.w = pass1_values[rightIndex + 3];

      If I uncomment the commented part, the behavior is undefined.  Is this a legal kernel operation? If not, the compiler should error.

       

      .sean