<div dir="ltr">Wow... This is an impressive quantity of infastructure just to get the number of bits in a field...<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 21, 2017 at 4:02 PM, Chad Versace <span dir="ltr"><<a href="mailto:chadversary@chromium.org" target="_blank">chadversary@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">genX_bits.h contains the sizes of bitfields in genxml instructions,<br>
structures, and registers. It also defines some functions to query those<br>
sizes.<br>
<br>
Currently, the bitfields in genX_bits.h are those whose name matches<br>
/.*Surface(Q?)Pitch/.<br>
<br>
isl_surf_init() will use the new header to validate that requested<br>
pitches fit in their destination bitfields.<br>
<br>
What's currently in genX_bits.h:<br>
<br>
  - Each macro in gen*_pack.h that whose name matches<br>
    /.*Surface(Q?)Pitch_bits$/ is also in genX_bits.h.<br>
<br>
  - For each set of macros whose name, after stripping the GEN prefix,<br>
    is the same, genX_bits.h contains a query function. See the examples<br>
    below.<br>
<br>
The generated file is not committed, so here are some excerpts:<br>
<br>
Example: The GEN7 and GEN6 sections:<br>
<br>
    #define GEN7_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits              18<br>
    #define GEN7_RENDER_SURFACE_STATE_<wbr>MCSSurfacePitch_bits            9<br>
    #define GEN7_3DSTATE_DEPTH_BUFFER_<wbr>SurfacePitch_bits              18<br>
    #define GEN7_3DSTATE_HIER_DEPTH_<wbr>BUFFER_SurfacePitch_bits         17<br>
    #define GEN7_3DSTATE_STENCIL_BUFFER_<wbr>SurfacePitch_bits            17<br>
<br>
    #define GEN6_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits              17<br>
    #define GEN6_3DSTATE_DEPTH_BUFFER_<wbr>SurfacePitch_bits              17<br>
    #define GEN6_3DSTATE_HIER_DEPTH_<wbr>BUFFER_SurfacePitch_bits         17<br>
    #define GEN6_3DSTATE_STENCIL_BUFFER_<wbr>SurfacePitch_bits            17<br>
<br>
Example: The SurfacePitch and AuxiliarySurfacePitch functions for<br>
RENDER_SURFACE_STATE:<br>
<br>
   static inline uint32_t __attribute__((const))<br>
   RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits(int gen_10x)<br>
   {<br>
      switch (gen_10x) {<br>
      case 90: return GEN9_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      case 80: return GEN8_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      case 75: return GEN75_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      case 70: return GEN7_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      case 60: return GEN6_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      case 50: return GEN5_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      case 45: return GEN45_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      case 40: return GEN4_RENDER_SURFACE_STATE_<wbr>SurfacePitch_bits;<br>
      default: return 0;<br>
      }<br>
   }<br>
<br>
   static inline uint32_t __attribute__((const))<br>
   RENDER_SURFACE_STATE_<wbr>AuxiliarySurfacePitch_bits(int gen_10x)<br>
   {<br>
      switch (gen_10x) {<br>
      case 90: return GEN9_RENDER_SURFACE_STATE_<wbr>AuxiliarySurfacePitch_bits;<br>
      case 80: return GEN8_RENDER_SURFACE_STATE_<wbr>AuxiliarySurfacePitch_bits;<br>
      case 75: return GEN75_RENDER_SURFACE_STATE_<wbr>MCSSurfacePitch_bits;<br>
      case 70: return GEN7_RENDER_SURFACE_STATE_<wbr>MCSSurfacePitch_bits;<br>
      default: return 0;<br>
      }<br>
   }<br>
---<br>
 src/intel/<a href="http://Makefile.genxml.am" rel="noreferrer" target="_blank">Makefile.genxml.am</a>        |   9 +-<br>
 src/intel/Makefile.sources          |   6 +-<br>
 src/intel/genxml/.gitignore         |   1 +<br>
 src/intel/genxml/gen_bits_<wbr>header.py | 164 ++++++++++++++++++++++++++++++<wbr>++++++<br>
 4 files changed, 178 insertions(+), 2 deletions(-)<br>
 create mode 100644 src/intel/genxml/gen_bits_<wbr>header.py<br>
<br>
diff --git a/src/intel/<a href="http://Makefile.genxml.am" rel="noreferrer" target="_blank">Makefile.genxml.am</a> b/src/intel/<a href="http://Makefile.genxml.am" rel="noreferrer" target="_blank">Makefile.genxml.am</a><br>
index bea0aab817f..586e551e79b 100644<br>
--- a/src/intel/<a href="http://Makefile.genxml.am" rel="noreferrer" target="_blank">Makefile.genxml.am</a><br>
+++ b/src/intel/<a href="http://Makefile.genxml.am" rel="noreferrer" target="_blank">Makefile.genxml.am</a><br>
@@ -29,7 +29,7 @@ EXTRA_DIST += \<br>
<br>
 SUFFIXES = _pack.h _xml.h .xml<br>
<br>
-$(GENXML_GENERATED_FILES): genxml/gen_pack_header.py<br>
+$(GENXML_PACK_GENERATED_<wbr>FILES): genxml/gen_pack_header.py<br>
<br>
 .xml_pack.h:<br>
        $(MKDIR_GEN)<br>
@@ -41,6 +41,12 @@ $(GENXML_GENERATED_FILES): genxml/gen_zipped_file.py<br>
        $(MKDIR_GEN)<br>
        $(AM_V_GEN) $(PYTHON2) $(srcdir)/genxml/gen_zipped_<wbr>file.py $< > $@ || ($(RM) $@; false)<br>
<br>
+genxml/genX_bits.h: genxml/gen_bits_header.py<br>
+genxml/genX_bits.h: $(GENXML_PACK_GENERATED_FILES)<br>
+       $(MKDIR_GEN)<br>
+       $(AM_V_GEN) $(PYTHON2) $(srcdir)/genxml/gen_bits_<wbr>header.py \<br>
+               $(GENXML_PACK_GENERATED_FILES) > $@ || ($(RM) $@; false)<br>
+<br>
 EXTRA_DIST += \<br>
        genxml/gen4.xml \<br>
        genxml/gen45.xml \<br>
@@ -50,6 +56,7 @@ EXTRA_DIST += \<br>
        genxml/gen75.xml \<br>
        genxml/gen8.xml \<br>
        genxml/gen9.xml \<br>
+       genxml/genX_bits.h \<br>
        genxml/genX_pack.h \<br>
        genxml/gen_macros.h \<br>
        genxml/gen_pack_header.py \<br>
diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources<br>
index 839ea47d752..af85d448eb8 100644<br>
--- a/src/intel/Makefile.sources<br>
+++ b/src/intel/Makefile.sources<br>
@@ -107,7 +107,7 @@ COMPILER_FILES = \<br>
 COMPILER_GENERATED_FILES = \<br>
        compiler/brw_nir_trig_<wbr>workarounds.c<br>
<br>
-GENXML_GENERATED_FILES = \<br>
+GENXML_PACK_GENERATED_FILES = \<br>
        genxml/gen4_pack.h \<br>
        genxml/gen45_pack.h \<br>
        genxml/gen5_pack.h \<br>
@@ -117,6 +117,10 @@ GENXML_GENERATED_FILES = \<br>
        genxml/gen8_pack.h \<br>
        genxml/gen9_pack.h<br>
<br>
+GENXML_GENERATED_FILES = \<br>
+       $(GENXML_PACK_GENERATED_FILES) \<br>
+       genxml/genX_bits.h<br>
+<br>
 AUBINATOR_GENERATED_FILES = \<br>
        genxml/gen6_xml.h \<br>
        genxml/gen7_xml.h \<br>
diff --git a/src/intel/genxml/.gitignore b/src/intel/genxml/.gitignore<br>
index c5672b5595c..3e2f1cfa9f0 100644<br>
--- a/src/intel/genxml/.gitignore<br>
+++ b/src/intel/genxml/.gitignore<br>
@@ -1,2 +1,3 @@<br>
+gen*_bits.h<br>
 gen*_pack.h<br>
 gen*_xml.h<br>
diff --git a/src/intel/genxml/gen_bits_<wbr>header.py b/src/intel/genxml/gen_bits_<wbr>header.py<br>
new file mode 100644<br>
index 00000000000..a6630cb89ed<br>
--- /dev/null<br>
+++ b/src/intel/genxml/gen_bits_<wbr>header.py<br>
@@ -0,0 +1,164 @@<br>
+#encoding=utf-8<br>
+<br>
+from __future__ import (<br>
+    absolute_import, division, print_function, unicode_literals<br>
+)<br>
+<br>
+import io<br>
+import os<br>
+import os.path<br>
+import re<br>
+import sys<br>
+from sys import stdout<br>
+from textwrap import dedent<br>
+<br>
+prologue = dedent("""\<br>
+    /*<br>
+     * Copyright (C) 2017 Intel Corporation<br>
+     *<br>
+     * Permission is hereby granted, free of charge, to any person obtaining a<br>
+     * copy of this software and associated documentation files (the "Software"),<br>
+     * to deal in the Software without restriction, including without limitation<br>
+     * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+     * and/or sell copies of the Software, and to permit persons to whom the<br>
+     * Software is furnished to do so, subject to the following conditions:<br>
+     *<br>
+     * The above copyright notice and this permission notice (including the next<br>
+     * paragraph) shall be included in all copies or substantial portions of the<br>
+     * Software.<br>
+     *<br>
+     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+     * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+     * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+     * IN THE SOFTWARE.<br>
+     */<br>
+<br>
+    /* THIS FILE HAS BEEN GENERATED, DO NOT HAND EDIT.<br>
+     *<br>
+     * Sizes of bitfields in genxml instructions, structures, and registers.<br>
+     */<br>
+<br>
+    #ifndef GENX_BITS_H<br>
+    #define GENX_BITS_H<br>
+<br>
+    #include <stdint.h><br>
+<br>
+    #ifdef __cplusplus<br>
+    extern "C" {<br>
+    #endif<br>
+<br>
+    """)<br>
+<br>
+epilogue = dedent("""\<br>
+    #ifdef __cplusplus<br>
+    }<br>
+    #endif<br>
+<br>
+    #endif /* GENX_BITS_H */<br>
+    """)<br>
+<br>
+def sanitize_token(t):<br>
+    if t[0].isdigit():<br>
+        return '_' + t<br>
+    else:<br>
+        return t<br>
+<br>
+def genx_prefix(x):<br>
+    return 'GENX_' + x<br>
+<br>
+class BitsLine:<br>
+<br>
+    __slots__ = (<br>
+        'orig_line',<br>
+        'gen_10x',<br>
+        'token_name',<br>
+        'token_basename',<br>
+    )<br>
+<br>
+    REGEX = re.compile('^#define (?P<token_name>GEN(?P<gen>[0-<wbr>9]+)_(?P<token_basename>\w*<wbr>Surface(Q?)Pitch)_bits).*$')<br></blockquote><div><br></div><div>Can we please not use XML to generate a header and then use regex to parse the header?  Let's just use XML for both.<br><br></div><div>I hate to ask for a rewrite, but you should have seen that coming...<br><br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+    def __init__(self, match):<br>
+        self.orig_line = match.group(0)<br>
+<br>
+        self.gen_10x = int(match.group('gen'))<br>
+        if self.gen_10x < 10:<br>
+            self.gen_10x *= 10<br>
+<br>
+        self.token_name = match.group('token_name')<br>
+        self.token_basename = match.group('token_basename')<br>
+<br>
+        # MCSSurfacePitch in older gens is analogous to AuxiliarySurfacePitch<br>
+        # in newer gens.<br>
+        self.token_basename = \<br>
+            self.token_basename.replace('<wbr>MCSSurfacePitch', 'AuxiliarySurfacePitch')<br>
+<br>
+class BitsCollection:<br>
+<br>
+    def __init__(self):<br>
+        self.by_gen_10x = {}<br>
+        self.by_token_basenames = {}<br>
+<br>
+    def add(self, bits_line):<br>
+        # We don't care about 3DSTATE_STREAMOUT.<br>
+        if ('STREAMOUT' in bits_line.token_name or<br>
+            'SO_BUFFER' in bits_line.token_name):<br>
+            return<br>
+<br>
+        self.by_gen_10x.setdefault(<wbr>bits_line.gen_10x, []).append(bits_line)<br>
+        self.by_token_basenames.<wbr>setdefault(bits_line.token_<wbr>basename, []).append(bits_line)<br>
+<br>
+    def read_filepath(self, path):<br>
+        with open(path) as file:<br>
+            for line in file:<br>
+                m = BitsLine.REGEX.match(line)<br>
+                if not m:<br>
+                    continue<br>
+                self.add(BitsLine(m))<br>
+<br>
+    def write_macros(self, out):<br>
+        for gen_10x in sorted(self.by_gen_10x.keys(), reverse=True):<br>
+            for bits_line in self.by_gen_10x[gen_10x]:<br>
+                out.write(bits_line.orig_line)<br>
+                out.write('\n')<br>
+            out.write('\n')<br>
+<br>
+    def write_funcs(self, out):<br>
+        for token_basename in sorted(self.by_token_<wbr>basenames.keys()):<br>
+            out.write('static inline uint32_t __attribute__((const))\n')<br>
+            out.write('{}_bits(int gen_10x)\n'.format(sanitize_<wbr>token(token_basename)))<br>
+            out.write('{\n')<br>
+            out.write('   switch (gen_10x) {\n')<br>
+<br>
+            def sort_key(bits_line):<br>
+                return bits_line.gen_10x<br>
+<br>
+            for bits_line in sorted(self.by_token_<wbr>basenames[token_basename],<br>
+                                    key=sort_key, reverse=True):<br>
+                out.write('   case {}: return {};\n'.format(bits_line.gen_<wbr>10x, bits_line.token_name))<br>
+<br>
+            out.write('   default: return 0;\n')<br>
+            out.write('   }\n')<br>
+            out.write('}\n')<br>
+            out.write('\n')<br>
+<br>
+def main():<br>
+    sources = sorted(sys.argv[1:])<br>
+    if len(sources) == 0:<br>
+        sys.stderr.write('error: no source files\n')<br>
+        sys.exit(1)<br>
+<br>
+    bits_collection = BitsCollection()<br>
+<br>
+    for path in sources:<br>
+        bits_collection.read_filepath(<wbr>path)<br>
+<br>
+    sys.stdout.write(prologue)<br>
+    bits_collection.write_macros(<wbr>stdout)<br>
+    bits_collection.write_funcs(<wbr>stdout)<br>
+    sys.stdout.write(epilogue)<br>
+<br>
+if __name__ == '__main__':<br>
+    main()<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.12.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>