Subject: Re: gcc de-optimisations
To: None <tech-toolchain@NetBSD.org>
From: Alan Barrett <apb@cequrux.com>
List: tech-toolchain
Date: 10/24/2005 10:36:48
On Sun, 23 Oct 2005, Ian Lance Taylor wrote:
> > > How do we stop gcc (i386) converting:
> > >     if (memcmp(a, b, 16))
> > > into:
> > >     movl  %ecx, #16
> > >     repeq cmpsb
> > 
> > CFLAGS += -fno-builtin-memcmp
> 
> That isn't an ideal solution, as it will prevent gcc from expanding
> memcmp in any other way.

If you want to let gcc do whatever it likes most of the time, but really
call memcmp() just this once, then try this nasty hack:

	typedef int (*memcmp_t)(const void *, const void *, size_t);
	memcmp_t real_memcmp = memcmp;
	if (real_memcmp(a, b, 16) { ... }

(I verified that gcc-3.3.3/i386 with "-O2" optimises away the indirection
through the function pointer, and really does call memcmp).

--apb (Alan Barrett)