This is the mail archive of the gcc@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: rs6000 and ffs


Mon Dec 02 2002, David Edelsohn wrote:
> 	I have committed the patch with the additional change that the
> DImode patterns should have TARGET_POWERPC64 in the final condition.  The
> cntlzd instruction only is available in 64-bit mode and the condition was
> present in the original ffsdi2 pattern.
> 
Not directly related to this but I thought I'd ask.

For rs6000 the cntlz instruction is used to calculate ffs(), this is
nice and all but what's really hard to do is fls() i.e. exaclty what
cntlz is doing.  Count _leading_ zeros or finding the most significant
bit set.  There doesn't seem to be any standardized function for this,
and writing it in plain C is really slow. I guess that there might be
more architectures than rs6000/ppc that has some assembler instruction
suited for this?  I know that 68k has bfffo, alpha also has ctlz
(and ctpop / cttz), ia32 has bsf (and bsr), ...

Is fls to non standard to support?  What about some other builtin for
this?

/*
 * fls: find last bit set.
 */
int generic_fls(int x)
{
        int r = 32;

        if (!x)
                return 0;
        if (!(x & 0xffff0000)) {
                x <<= 16;
                r -= 16;
        }
        if (!(x & 0xff000000)) {
                x <<= 8;
                r -= 8;
        }
        if (!(x & 0xf0000000)) {
                x <<= 4;
                r -= 4;
        }
        if (!(x & 0xc0000000)) {
                x <<= 2;
                r -= 2;
        }
        if (!(x & 0x80000000)) {
                x <<= 1;
                r -= 1;
        }
        return r;
 }

-- 
/Håkan


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