public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/8013: writing all bitfields in a word
@ 2002-09-23 15:36 jreiser
  0 siblings, 0 replies; only message in thread
From: jreiser @ 2002-09-23 15:36 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8013
>Category:       optimization
>Synopsis:       writing all bitfields in a word
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 23 15:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     John Reiser
>Release:        gcc version 3.2
>Organization:
>Environment:
Reading specs from /usr/local/gcc-3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
Configured with: ../gcc-3.2/configure --prefix=/usr/local/gcc-3.2
Thread model: posix
gcc version 3.2
>Description:
There is an opportunity for improved optimization when writing all the bitfields in a word ('int', 'unsigned', or 'long'): construct the entire word result in a register, then perform only one store to memory, instead of writing the fields to memory separately in turn.

The attached bitfield.i generates (with "-O" optimization)
        movl    (%ebx), %ecx
        andl    $16777215, %ecx
        movl    (%edx), %eax
        andl    $-16777216, %eax
        orl     %ecx, %eax
        movl    %eax, (%edx)
        movzbl  3(%ebx), %ecx
        andb    $127, %cl
        movzbl  3(%edx), %eax
        andb    $-128, %al
        orb     %cl, %al
        orb     $-128, %al
        movb    %al, 3(%edx)
which could be improved to
        movl    (%ebx), %eax
        orl     $1<<31, %eax
        movl    %eax, (%edx)
which is much shorter and faster.
>How-To-Repeat:
gcc -v -save-temps -O -S bitfield.c
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bitfield.i"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bitfield.i"

IyAxICJiaXRmaWVsZC5jIgojIDEgIjxidWlsdC1pbj4iCiMgMSAiPGNvbW1hbmQgbGluZT4iCiMg
MSAiYml0ZmllbGQuYyIKc3RydWN0IE0gewogICAgICAgIHVuc2lnbmVkIHg6MjQsIHk6Nywgejox
OwogICAgICAgIGludCB3Owp9OwoKdm9pZApmb28oc3RydWN0IE0gKnNyYywgc3RydWN0IE0gKmRz
dCkKewogICAgICAgIGRzdC0+eCA9IHNyYy0+eDsKICAgICAgICBkc3QtPnkgPSBzcmMtPnk7CiAg
ICAgICAgZHN0LT56ID0gMTsKICAgICAgICBkc3QtPncgPSA1Owp9Cg==


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-09-23 22:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-23 15:36 optimization/8013: writing all bitfields in a word jreiser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).