[Mesa-dev] [PATCH 02/19] i965: Mark brw_reg_type and register_file enums as PACKED.

Matt Turner mattst88 at gmail.com
Fri Feb 21 14:43:23 PST 2014


On Fri, Feb 21, 2014 at 2:25 PM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> Generally, I only use PACKED when something -relies- on a particular
> memory layout.  Is it really worth second guessing the compiler here?
> Presumably it had a reason for choosing a larger size other than sheer
> stupidity...

We're not second guessing the compiler.

The C99 spec says the type of an enum is implementation defined.
Adding __attribute__((__packed__)) to an enum has the same behavior as
gcc's -fshort-enum flag, but the flag would obviously cover all enums.
The gcc non-bugs page [0] says that they don't want to make
-fshort-enums the default because of [ABI] incompatibilities with
other compilers. They suggest setting a field width of the enum in a
struct, but in general that seems prone to errors (e.g., adding a
256th value to an enum, but having specified an 8-bit field width on
the enum field) that using packed wouldn't have. Since we aren't
likely to hit that, would you rather me just set a field width?

[0] http://gcc.gnu.org/onlinedocs/gcc/Non-bugs.html#index-fshort-enums-3868


More information about the mesa-dev mailing list