In short, when passing a bitfield as parameter, each bit is converted to bytes
before being tested instead of a simple mask and test.
 Is there a way to disable bit to bytes conversion by a compilation switch,
I have never seen that producing better code up to now?

$ cat tmp2.c
struct mouse_button_str {
        unsigned char left      : 1;
        unsigned char right     : 1;
        unsigned char middle    : 1;
        } button;

char fct (struct mouse_button_str newbutton)
{
        return (newbutton.left && newbutton.right && newbutton.middle);
}
$ ./toolchain/bin/gcc --version
gcc (GCC) 4.3.2 20080819 (prerelease)
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ./toolchain/bin/gcc -Os tmp2.c -S -o tmp2.s
$ cat tmp2.s
        .file   "tmp2.c"
        .text
.globl fct
        .type   fct, @function
fct:
        pushl   %ebp
        movl    %esp, %ebp
        movb    8(%ebp), %al
        movb    %al, %cl
        movb    %al, %dl
        shrb    %cl
        shrb    $2, %dl
        andl    $1, %ecx
        andl    $1, %edx
        testb   $1, %al
        je      .L2
        testb   %cl, %cl
        je      .L2
        movl    %edx, %eax
        andl    $1, %eax
        jmp     .L3
.L2:
        xorl    %eax, %eax
.L3:
        popl    %ebp
        ret
        .size   fct, .-fct
        .comm   button,1,1
        .ident  "GCC: (GNU) 4.3.2 20080819 (prerelease)"
        .section        .note.GNU-stack,"",@progbits
$ ./toolchain-4.3.1/bin/gcc --version
gcc (GCC) 4.3.1
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ./toolchain-4.3.1/bin/gcc -Os tmp2.c -S -o tmp2.s
$ cat tmp2.s
        .file   "tmp2.c"
        .text
.globl fct
        .type   fct, @function
fct:
        pushl   %ebp
        movl    %esp, %ebp
        movb    8(%ebp), %al
        popl    %ebp
        andl    $7, %eax
        cmpb    $7, %al
        sete    %al
        ret
        .size   fct, .-fct
        .comm   button,1,1
        .ident  "GCC: (GNU) 4.3.1"
        .section        .note.GNU-stack,"",@progbits


-- 
           Summary: regression 4.3.1 -> 4.3.2-rc transformation bitfield to
                    individual bytes
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: etienne_lorrain at yahoo dot fr
 GCC build triplet: i386-linux-fedora
  GCC host triplet: i386-linux-fedora
GCC target triplet: i386-linux-fedora


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37248

Reply via email to