rs6000 and ffs
Falk Hueffner
falk.hueffner@student.uni-tuebingen.de
Wed Jan 22 06:05:00 GMT 2003
HÃ¥kan Hjort <d95hjort@dtek.chalmers.se> writes:
> 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?
I would really like to see builtins for this, and for some other
things, like population count. Even if CPUs don't have explicit
support for these operations, sometimes you can take advantage of
funny instructions (for example, cmpbge and perr on Alpha). I have a
program which spends about 60% of its time in std::bitset::count,
which could greatly profit from a builtin...
So how about these 8 builtins:
int __builtin_popcntsi() (population count)
int __builtin_popparsi() (population parity)
int __builtin_leadzsi() (count leading zeros)
int __builtin_trailzsi() (count trailing zeros)
int __builtin_popcntdi() (64 bit variations)
int __builtin_poppardi()
int __builtin_leadzdi()
int __builtin_trailzdi()
? I could try to make a patch that implements them from libgcc,
analogous to __builtin_ffs, and architecture specific optimizations
could be added later...
--
Falk
More information about the Gcc
mailing list