<p dir="ltr"><br>
On May 26, 2016 7:06 PM, "Ian Romanick" <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>> wrote:<br>
><br>
> On 05/26/2016 06:30 PM, Jason Ekstrand wrote:<br>
> > This shrinks the .text section of nir_opt_algebraic.o by 30.5 KB:<br>
> ><br>
> > text data bss dec hex filename<br>
> > 48703 64592 0 113295 1ba8f nir_opt_algebraic.o<br>
> > 17951 64584 0 82535 14267 nir_opt_algebraic.o<br>
> > ---<br>
> > src/compiler/nir/nir_search.h | 12 ++++++------<br>
> > 1 file changed, 6 insertions(+), 6 deletions(-)<br>
> ><br>
> > diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h<br>
> > index 888a2a3..b97522a 100644<br>
> > --- a/src/compiler/nir/nir_search.h<br>
> > +++ b/src/compiler/nir/nir_search.h<br>
> > @@ -39,23 +39,23 @@ typedef enum {<br>
> > } nir_search_value_type;<br>
> ><br>
> > typedef struct {<br>
> > - nir_search_value_type type;<br>
> > + uint8_t type; /* enum nir_search_value_type */<br>
><br>
> Do we lose any checking by having this not be an enum? Places where the<br>
> compiler would warning about missing cases, etc. Would telling GCC to<br>
> pack the enum be just as good? I've gotten similar feedback on similar<br>
> kinds of patches.</p>
<p dir="ltr">The C99 spec states that bit-field elements must be an integer type or _Bool. Everything I find indicates that enums aren't allowed. That said, GCC does allow them and we did use an enum in a bit-field for nir_variable.data.mode for a while. IIRC, it was making MSVC grumpy which is why we stopped.</p>
<p dir="ltr">I'd personally rather keep it as an enum four the sake of type safety as you say. Since this is never included from C++ we may be able to get away with it but I'm not actually sure that makes a difference. I added Jose to the Cc; maybe he can shed sine light on it.</p>
<p dir="ltr">--Jason</p>
<p dir="ltr">> ><br>
> > - unsigned bit_size;<br>
> > + uint8_t bit_size;<br>
> > } nir_search_value;<br>
> ><br>
> > typedef struct {<br>
> > nir_search_value value;<br>
> ><br>
> > /** The variable index; Must be less than NIR_SEARCH_MAX_VARIABLES */<br>
> > - unsigned variable;<br>
> > + unsigned variable:7;<br>
> ><br>
> > /** Indicates that the given variable must be a constant<br>
> > *<br>
> > * This is only allowed in search expressions and indicates that the<br>
> > * given variable is only allowed to match constant values.<br>
> > */<br>
> > - bool is_constant;<br>
> > + bool is_constant:1;<br>
> ><br>
> > /** Indicates that the given variable must have a certain type<br>
> > *<br>
> > @@ -67,13 +67,13 @@ typedef struct {<br>
> > * Note: A variable that is both constant and has a non-void type will<br>
> > * never match anything.<br>
> > */<br>
> > - nir_alu_type type;<br>
> > + uint8_t type; /* enum nir_alu_type */<br>
> > } nir_search_variable;<br>
> ><br>
> > typedef struct {<br>
> > nir_search_value value;<br>
> ><br>
> > - nir_alu_type type;<br>
> > + uint8_t type; /* enum nir_alu_type */<br>
> ><br>
> > union {<br>
> > uint64_t u;<br>
> ><br>
><br>
</p>