[Mesa-dev] [PATCH 05/16] glsl: Add constant evaluation of bit built-ins.

Chris Forbes chrisf at ijw.co.nz
Mon Apr 22 18:53:36 PDT 2013


+   case ir_unop_find_msb:
+      for (unsigned c = 0; c < components; c++) {
+         int v = op[0]->value.i[c];
+
+         if (v == 0 || (op[0]->type->base_type == GLSL_TYPE_INT && v == -1))
+            data.i[c] = -1;
+         else {
+            int count = 0;
+            int top_bit = op[0]->type->base_type == GLSL_TYPE_UINT
+                          ? 0 : v & (1 << 31);
+
+            while (((v & (1 << 31)) == top_bit) && count != 32) {
+               count++;
+               v <<= 1;
+            }
+
+            data.i[c] = count;

Assuming the bits are numbered from the LSB, this probably wants to be

              data.i[c] = 32 - count;

-- Chris


More information about the mesa-dev mailing list