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

Kenneth Graunke kenneth at whitecape.org
Fri Feb 21 15:48:25 PST 2014


On 02/21/2014 02:43 PM, Matt Turner wrote:
> 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

Okay, that's bordering more on 'stupidity' than I thought.  These enums
are only ever used internally, so ABI compatibility is completely
irrelevant.  And they do get copied around a fair bit.

__attribute__((packed)) seems nicer than making every user of the value
specify a field width.

It would be nice to add your explanation here to the commit message.

Acked-by: Kenneth Graunke <kenneth at whitecape.org>

Alternatively, just compiling i965 with -fshort-enums might make sense.
 Perhaps other people have thoughts.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140221/0bf73016/attachment.pgp>


More information about the mesa-dev mailing list