Re: bitfield structures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alex Deucher <alexdeucher@xxxxxxxxx> writes:

> As part of the amdgpu transition, we are moving to using database
> generated register and packet headers.  We have a number of options
> for formatting, some of which involve bitfields (don't worry there
> will also be shift/mask style headers as well which is mainly what we
> use in the code).  I think these formats are cleaner for a number of
> cases, however, as far as I know, C does not define the ordering of
> bits within bitfields.  That said, every compiler I've used seems to
> do what you would expect.  It makes coding a lot cleaner as less
> error-prone in certain cases.  Here are a couple of example of what
> I'm talking about:
>
> A register example:
>
> union GRPH_SWAP_CNTL {
>         struct {
> #if BIG_ENDIAN
>                 unsigned int                                 : 20;
>                 unsigned int             GRPH_ALPHA_CROSSBAR : 2;
>                 unsigned int              GRPH_BLUE_CROSSBAR : 2;
>                 unsigned int             GRPH_GREEN_CROSSBAR : 2;
>                 unsigned int               GRPH_RED_CROSSBAR : 2;
>                 unsigned int                                 : 2;
>                 unsigned int                GRPH_ENDIAN_SWAP : 2;
> #else
>                 unsigned int                GRPH_ENDIAN_SWAP : 2;
>                 unsigned int                                 : 2;
>                 unsigned int               GRPH_RED_CROSSBAR : 2;
>                 unsigned int             GRPH_GREEN_CROSSBAR : 2;
>                 unsigned int              GRPH_BLUE_CROSSBAR : 2;
>                 unsigned int             GRPH_ALPHA_CROSSBAR : 2;
>                 unsigned int                                 : 20;
> #endif
>         } bitfields, bits;
>         unsigned int u32All;
>         signed int i32All;
>         float f32All;
> };

> Are there any strong objections to these sorts of structures?

My experience with bitfields was that the code generated by gcc was
atrocious, and I wouldn't use them for any performance sensitive 32-bit
word setup.  As a result, publishing headers in the form of
bitfield-structs seems like a way to encourage people to generate bad
code for your hardware.

Attachment: pgpt4kINJfwQv.pgp
Description: PGP signature

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/dri-devel

[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux