[Mesa-dev] [PATCH 06/11] glsl: Instead of walking the name pointer in get_intrinsic_opcode, advance an offset

Ian Romanick idr at freedesktop.org
Wed Jul 6 00:46:14 UTC 2016


From: Ian Romanick <ian.d.romanick at intel.com>

I think this makes the next patch more clear.

   text	   data	    bss	    dec	    hex	filename
7528883	 273096	  28584	7830563	 777c23	/tmp/i965_dri-64bit-before.so
7528835	 273096	  28584	7830515	 777bf3	/tmp/i965_dri-64bit-after.so

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/compiler/glsl/nir_intrinsic_map.py | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/compiler/glsl/nir_intrinsic_map.py b/src/compiler/glsl/nir_intrinsic_map.py
index 5962d4b..69d2360 100644
--- a/src/compiler/glsl/nir_intrinsic_map.py
+++ b/src/compiler/glsl/nir_intrinsic_map.py
@@ -139,32 +139,31 @@ def emit_trie_leaf(indent, d):
 
 
 def trie_as_C_code(trie, indent="   ", prefix_string="__intrinsic_"):
+    offset = len(prefix_string)
     conditional = "if"
 
     c_code = ""
     for (s, t, d) in trie:
         if d is not None:
-            c_code +=  "{}{} (name[0] == '\\0') {{\n".format(indent, conditional)
-            c_code += "{}   /* {} */\n".format(indent, prefix_string)
+            c_code +=  "{}{} (name[{}] == '\\0') {{\n".format(indent, conditional, offset)
+            c_code += "{}   assert(strcmp(name, \"{}\") == 0);\n".format(indent, prefix_string)
             c_code += emit_trie_leaf(indent + "   ", d);
 
         else:
             # Before emitting the string comparison, check to see of the
             # subtree has a single element with an empty string.  In that
-            # case, use strcmp() instead of strncmp() and don't advance the
-            # name pointer.
+            # case, use strcmp() instead of strncmp().
 
             if len(t) == 1 and t[0][2] is not None:
                 if s == "":
-                    c_code += "{}{} (name[0] == '\\0') {{\n".format(indent, conditional, s)
+                    c_code += "{}{} (name[{}] == '\\0') {{\n".format(indent, conditional, offset)
                 else:
-                    c_code += "{}{} (strcmp(name, \"{}\") == 0) {{\n".format(indent, conditional, s)
+                    c_code += "{}{} (strcmp(name + {}, \"{}\") == 0) {{\n".format(indent, conditional, offset, s)
 
-                c_code += "{}   /* {} */\n".format(indent, prefix_string + s)
+                c_code += "{}   assert(strcmp(name, \"{}\") == 0);\n".format(indent, prefix_string + s)
                 c_code += emit_trie_leaf(indent + "   ", t[0][2]);
             else:
-                c_code += "{}{} (strncmp(name, \"{}\", {}) == 0) {{\n".format(indent, conditional, s, len(s))
-                c_code += "{}   name += {};\n\n".format(indent, len(s))
+                c_code += "{}{} (strncmp(name + {}, \"{}\", {}) == 0) {{\n".format(indent, conditional, offset, s, len(s))
 
                 c_code += trie_as_C_code(t, indent + "   ", prefix_string + s)
 
@@ -189,10 +188,7 @@ namespace _glsl_to_nir {
 nir_intrinsic_op
 get_intrinsic_opcode(const char *name, const ir_dereference *return_deref)
 {
-   if (strncmp(name, "__intrinsic_", 12) == 0)
-      name += 12;
-   else
-      unreachable("Intrinsic name does not begin with '__intrinsic_'");
+   assert(strncmp(name, "__intrinsic_", 12) == 0);
 
    nir_intrinsic_op int_op;
    nir_intrinsic_op uint_op;
-- 
2.5.5



More information about the mesa-dev mailing list