This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] partial register update for a bit mask operation on x86


gcc was generating a partial register update on x86, due to an xorb % dl, %dl followed by using %edx shortly thereafter.
Partial register update is an x86 performance hazard on certain prominent x86 implementations.


unsigned char lut[256];

void foo( int count )
{
  int j;

  unsigned int *srcptr, *dstptr;
  for (j = 0; j < count; j++) {
    unsigned int tmp = *srcptr;
    unsigned int alpha = (tmp&255);
    tmp &= 0xffffff00;
    alpha =lut[alpha];
    tmp |= alpha<<0;
    *dstptr = tmp;
  }
}

0000005b movl %eax,%edx
0000005d xorb %dl,%dl <--- modifies %dl to clear the byte.
0000005f andl $0x000000ff,%eax
00000064 movzbl (%ecx,%eax,1),%eax
00000068 orl %eax,%edx <--- uses % edx after having modified %dl.


Instead of a better implementation:

000000ef        movl    %eax,%edx
000000f1        andl    $0xffffff00,%edx
000000f7        andl    $0x000000ff,%eax
000000fc        movzbl  (%ecx,%eax,1),%eax
00000100       orl     %eax,%edx

The patch has been tested on x86 MacOS with "make all", "--enable- languages=c,c++,objc,obj-c++", and regression tested with a top-level "make check-gcc" with no regression.

ChangeLog:

2007-05-08  Hui-May Chang    <hm.chang@apple.com>
                       Stuart Hastings     <stuart@apple.com>

* config/i386/i386.md (movstrictqi_and): New. Update the whole register
for a byte operand.


        * gcc.target/i386/bitmask-1.c : New.
        * gcc.target/i386/bitmask-2.c : New.

Attachment: radar-patch.bitmask.txt
Description: Text document

OK for mainline?

Hui-May Chang


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]