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]

Re: streamline libgcc clz, ctz, parity


Richard Henderson <rth@redhat.com> writes:

> Finally, on most targets getting the (pic) address of __popcount_tab
> is more expensive than continuing to simplify the parity with
> shifts.

If we don't want to use a table, how about this cute trick:

unsigned par(unsigned x)
{
    unsigned long nx = x;
    nx ^= nx >> 16;
    nx ^= nx >> 8;
    nx ^= nx >> 4;
    nx &= 0xf;
    return (0x6996 >> nx) & 1;
}

(based on the same idea as Roger's recent switch improvement).

-- 
	Falk


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