This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] use __builtin_ctzl in ggc-page
On Monday 17 January 2005 13:38, Richard Earnshaw wrote:
> > * ggc-page.c (ggc_alloc_stat): Use __builtin_ctzl instead of a
> > loop to look for a free slot in a page entry.
>
> I would expect this makes things worse for platforms that don't have the
> builtin, since we now end up with a library call overhead on top of the
> calculation cost.
Note that there are c[lt]zm2 and ffsm2 named patterns so in theory
it should be possible to avoid a libcall for all targets. There are
some quite efficient target specific versions of c[lt]z in libgcc2's
longlong.h and as a fall-back we could add some generic version like
the one in bitmap.c:
#if BITMAP_WORD_BITS > 32
if (!(word & 0xffffffff))
word >>= 32, bit_no += 32;
#endif
if (!(word & 0xffff))
word >>= 16, bit_no += 16;
if (!(word & 0xff))
word >>= 8, bit_no += 8;
if (!(word & 0xf))
word >>= 4, bit_no += 4;
if (!(word & 0x3))
word >>= 2, bit_no += 2;
if (!(word & 0x1))
word >>= 1, bit_no += 1;
gcc_assert (word & 1);
It should be possible to produce a similar code sequence in RTL from
builtins.c, right? I don't know how I'd have to do that, probably
something with optabs, but I don't know if it is possible somehow to
have an optab that generatez inline RTL for a builtin. Hints would
be appreciated ;-)
For GCC 3.4 and later as the build compiler bitmap.c always uses the
ctz builtin, and so does ggc-page now, but apparently the only target
descriptions with a czt pattern are alpha, arm, h3800, i386, ia64,
and rs6000. I suppose bootstrapping on other hosts would result in a
libcall for the __builtin_ctz calls. That would, in fact, be a gcc 4
regression...
Is there some way to detect if the host needs a libcall for a builtin?
You already said in another thread of this discussion that we should
call the builtins via macros. I suppose you're right. I'll try to
figure out something for this.
Gr.
Steven