<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 22, 2017 at 2: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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Wed 22 Mar 2017, Jason Ekstrand wrote:<br>
> Wow... This is an impressive quantity of infastructure just to get the<br>
> number of bits in a field...<br>
<br>
</span>In the initial patch, I hand-wrote macros and functions. And I made<br>
mistakes. That's when I decided to eliminate the mistakes with<br>
generation. That's why we have the genxml, after all.<br>
<span class="gmail-"><br>
> On Tue, Mar 21, 2017 at 4:02 PM, Chad Versace <<a href="mailto:chadversary@chromium.org">chadversary@chromium.org</a>><br>
> wrote:<br>
<br>
<br>
</span><span class="gmail-">> > +    REGEX = re.compile('^#define (?P<token_name>GEN(?P<gen>[0-<br>
> > 9]+)_(?P<token_basename>\w*<wbr>Surface(Q?)Pitch)_bits).*$')<br>
> ><br>
><br>
> Can we please not use XML to generate a header and then use regex to parse<br>
> the header?  Let's just use XML for both.<br>
><br>
> I hate to ask for a rewrite, but you should have seen that coming...<br>
<br>
</span>Argh... yes, I knew it was coming. Yes, I knew I shouldn't have. But it<br>
was SOOOO easy.<br>
<br>
Now that I've had time to ponder my sin, I no longer want to maintain<br>
a giant pile of Python "just to get the number of bits in a field". Let<br>
me propose an alternative: Keep the Python changes to gen_pack_header.py<br>
that emits the GEN_*Pitch_bits macros, but hand-write the genX_bits.h<br>
headers. I think that's good compromise. What do you think?<br>
</blockquote></div><br></div><div class="gmail_extra">Seems reasonable.  You can even do a #define like so:<br><br></div><div class="gmail_extra">#define GENX_BITS_DECLARE_LOOKUP(field) \<br></div><div class="gmail_extra">   static inline uint32_t \<br></div><div class="gmail_extra">   field##_bits(const struct gen_device_info *devinfo) \<br>   { \<br></div><div class="gmail_extra">      switch (devinfo->gen) {<br></div><div class="gmail_extra">      case 4: return devinfo->is_g4x ? GEN4_##field##_bits : GEN45_##field##_bits;<br></div><div class="gmail_extra">      case 5: return GEN5_##field##_bits;<br>      case 6: return GEN6_##field##_bits;<br>      case 7: return devinfo->is_haswell ? GEN75_##field##_bits : GEN7_##field##_bits;<br>      case 8: return GEN8_##field##_bits;<br>      case 9: return GEN9_##field##_bits;</div><div class="gmail_extra">      }<br>   }<br><br></div><div class="gmail_extra">GENX_BITS_DECLARE_LOOKUP(RENDER_SURFACE_STATE_SurfacePitch)<br><br></div><div class="gmail_extra">Unfortunately, this won't be able to deal with field renames but I think the right way to deal with that is to just fix the XML.  Also, I didn't think you actually could include all of the genX_pack headers at the same time due to name conflicts.  Is this not true?<br></div></div>