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

builtin memcmp() could be optimised



>Submitter-Id:	net
>Originator:	herbert@gondor.apana.org.au
>Organization:	The Debian project
>Confidential:	no
>Synopsis:	builtin memcmp() could be optimised
>Severity:       non-critical
>Priority:       low
>Category:	optimization
>Class:		sw-bug
>Release:	3.0 (Debian GNU/Linux) and HEAD 20010701
>Environment:
System: Debian GNU/Linux (testing/unstable)
Architecture: i686
	
host: i386-linux
build: i386-linux
target: i386-linux
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux
>Description:
[ Reported to the Debian BTS as report #85535.
  Please CC 85535-quiet@bugs.debian.org on replies.
  Log of report can be found at http://bugs.debian.org/85535 ]
 	

int main() {
	return !memcmp("abcd", "efgh", 4);
}

produces the assembly (-S -g -O2),

        movl    $.LC1, %edi
        movl    $.LC0, %esi
        movl    $4, %ecx
        cld
        repz
        cmpsb
        seta    %cl
        setb    %dl
        popl    %esi
        xorl    %eax, %eax
        popl    %edi
        cmpb    %dl, %cl
        sete    %al

which is a waste because it could've simply loaded the two objects into
registers and compared them.  The same is true on other architectures as
well.

>How-To-Repeat:
	
>Fix:
	



Reply to: