This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: floor_log2_wide speedup
- From: DJ Delorie <dj at redhat dot com>
- To: rth at redhat dot com
- Cc: jsm at polyomino dot org dot uk, gcc-patches at gcc dot gnu dot org
- Date: Tue, 1 Jun 2004 13:36:02 -0400
- Subject: Re: floor_log2_wide speedup
- References: <200405242134.i4OLYgia014267@greed.delorie.com> <Pine.LNX.4.58.0405242151470.1720@digraph.polyomino.org.uk> <200405290002.i4T02lCU013444@greed.delorie.com> <20040529054750.GA9659@redhat.com>
> > #if (__GNUC__ * 1000 + __GNUC_MINOR__) >= 3004
> > return (sizeof(HOST_WIDE_INT)*8-1) - __builtin_clz(x);
>
> You've got to choose the proper version of clz, clzl, clzll.
Something like this?
#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONGLONG
return (sizeof(HOST_WIDE_INT)*8-1) - __builtin_clzll(x);
#else
#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
return (sizeof(HOST_WIDE_INT)*8-1) - __builtin_clzl(x);
#else
return (sizeof(int)*8-1) - __builtin_clz(x);
#endif
#endif