[Mesa-dev] [PATCH 1/2] nir: Fix searching for 32-bit signed integers.

Eric Anholt eric at anholt.net
Thu Jan 19 11:40:11 UTC 2017


The python code stores the integer match values to the 64-bit unsigned
field, so 32-bit values like 0xff000000 don't get sign extended.  However,
~0 gets printed as -0x1, so it does get stored as ~0ull.

To be able to match both ways that the python code generates integers,
cast the 64-bit int value back to int32_t and then re-sign-extend it.
---
 src/compiler/nir/nir_search.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
index 68275e442fca..8ad69e980a26 100644
--- a/src/compiler/nir/nir_search.c
+++ b/src/compiler/nir/nir_search.c
@@ -211,10 +211,18 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
 
       case nir_type_int:
          for (unsigned i = 0; i < num_components; ++i) {
+            int64_t const_int = const_val->data.i;
             int64_t val;
             switch (load->def.bit_size) {
             case 32:
                val = load->value.i32[new_swizzle[i]];
+               /* The python code sometimes stores the ints it's searching for
+                * as 32-bit unsigned (like 0xff000000), and sometimes as
+                * 64-bit signed (like -0x1).  Make sure that we get both
+                * sign-extended from 32 bits the same as we sign-extend our
+                * NIR constant load.
+                */
+               const_int = (int32_t)const_val->data.i;
                break;
             case 64:
                val = load->value.i64[new_swizzle[i]];
@@ -223,7 +231,7 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
                unreachable("unknown bit size");
             }
 
-            if (val != const_val->data.i)
+            if (val != const_int)
                return false;
          }
          return true;
-- 
2.11.0



More information about the mesa-dev mailing list