public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/15184] New: Direct access to byte inside word not working with -march=pentiumpro
@ 2004-04-27 23:52 cesarb at nitnet dot com dot br
  2004-04-28  0:33 ` [Bug target/15184] [3.3/3.4/3.5 Regression] " pinskia at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: cesarb at nitnet dot com dot br @ 2004-04-27 23:52 UTC (permalink / raw)
  To: gcc-bugs

When compiling:

// gcc -Wall -std=c99 -O3 -ffast-math -fomit-frame-pointer -march=pentiumpro
// Works: gcc -Wall -std=c99 -O3 -ffast-math -fomit-frame-pointer -march=i486

#define regparm __attribute__((__regparm__(3)))

extern unsigned int x;
extern unsigned short y;

void regparm fl(unsigned char c)
{
        x = (x & 0xFFFFFF00) | (unsigned int)c;
}

void regparm fu(unsigned char c)
{
        x = (x & 0xFFFF00FF) | ((unsigned int)c << 8);
}

void regparm gl(unsigned char c)
{
        y = (y & 0xFF00) | (unsigned short)c;
}

void regparm gu(unsigned char c)
{
        y = (y & 0x00FF) | ((unsigned short)c << 8);
}

With:
gcc -Wall -std=c99 -O3 -ffast-math -fomit-frame-pointer -march=pentiumpro

The result is:

        .file   "testcase.c"
        .text
        .align 4
        .p2align 4,,15
.globl fl
        .type   fl, @function
fl:
        movb    %al, x
        ret
        .size   fl, .-fl
        .p2align 4,,15
.globl fu
        .type   fu, @function
fu:
        movb    %al, x+1
        ret
        .size   fu, .-fu
        .p2align 4,,15
.globl gl
        .type   gl, @function
gl:
        movb    %al, %dl
        movzwl  y, %eax
        movzbw  %dl, %dx
        andl    $-256, %eax
        orl     %edx, %eax
        movw    %ax, y
        ret
        .size   gl, .-gl
        .p2align 4,,15
.globl gu
        .type   gu, @function
gu:
        movzbl  y, %edx
        sall    $8, %eax
        orl     %eax, %edx
        movw    %dx, y
        ret
        .size   gu, .-gu
        .ident  "GCC: (GNU) 3.5.0 20040425 (experimental)"
        .section        .note.GNU-stack,"",@progbits

Notice that the optimization to directly change the byte inside the word
does not work with unsigned short (it uses a lot of instructions instead
of a simple "movb %al, y+1". Is it just me or some of them are
redundant? Like moving from al to dl and then zero extending to dx
instead of doing it at once?).

The problem seems to happen only with -march=pentiumpro. Here is the
result with i486 or athlon:

        .file   "testcase.c"
        .text
        .align 4
        .p2align 4,,15
.globl fl
        .type   fl, @function
fl:
        movb    %al, x
        ret
        .size   fl, .-fl
        .p2align 4,,15
.globl fu
        .type   fu, @function
fu:
        movb    %al, x+1
        ret
        .size   fu, .-fu
        .p2align 4,,15
.globl gl
        .type   gl, @function
gl:
        movb    %al, y
        ret
        .size   gl, .-gl
        .p2align 4,,15
.globl gu
        .type   gu, @function
gu:
        movb    %al, y+1
        ret
        .size   gu, .-gu
        .ident  "GCC: (GNU) 3.5.0 20040425 (experimental)"
        .section        .note.GNU-stack,"",@progbits

Which is exactly the expected result.

Even if a Pentium PRO is slower with words, the optimization uses byte
accesses (exactly the same thing it did with longs, even on pentiumpro),
so it should be used even on pentiumpro.


Reading specs from /usr/lib/gcc-snapshot/lib/gcc/i486-linux/3.5.0/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,objc,treelang --prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --enable-nls --enable-threads=posix --without-included-gettext --disable-werror --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk i486-linux
Thread model: posix
gcc version 3.5.0 20040425 (experimental)

-- 
           Summary: Direct access to byte inside word not working with -
                    march=pentiumpro
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: cesarb at nitnet dot com dot br
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-09-27 16:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-27 23:52 [Bug optimization/15184] New: Direct access to byte inside word not working with -march=pentiumpro cesarb at nitnet dot com dot br
2004-04-28  0:33 ` [Bug target/15184] [3.3/3.4/3.5 Regression] " pinskia at gcc dot gnu dot org
2004-04-28  0:42 ` cesarb at nitnet dot com dot br
2004-05-17 10:47 ` [Bug target/15184] [3.4/3.5 " gdr at gcc dot gnu dot org
2004-06-12 22:53 ` mmitchel at gcc dot gnu dot org
2004-06-21 21:20 ` mmitchel at gcc dot gnu dot org
2004-08-29 18:58 ` mmitchel at gcc dot gnu dot org
2004-11-01  0:46 ` [Bug target/15184] [3.4/4.0 " mmitchel at gcc dot gnu dot org
2005-02-25  2:06 ` rth at gcc dot gnu dot org
2005-05-19 17:30 ` [Bug target/15184] [3.4/4.0/4.1 " mmitchel at gcc dot gnu dot org
2005-07-22 21:18 ` pinskia at gcc dot gnu dot org
2005-09-27 16:13 ` mmitchel at gcc dot gnu dot org

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).