[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 16:00:55 PST 2014


On Fri, Feb 21, 2014 at 3:48 PM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> 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.

Sure, will do.


More information about the mesa-dev mailing list