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]

Add __builtin_clrsb, similar to clz/ctz


Several processors have a "count redundant sign bits" instruction:

* SIGNBITS on Blackfin
* NORM on C6X
* SBC, apparently, on picochip

and probably others. For example, for a value of 0 or -1, it returns 31,
while e.g. an input 0xc0000000 produces 1.

Other compilers tend to define builtin functions called "norm" for this,
and the operation is used in some DSP benchmarks. The patch below adds a
__builtin_clrsb family of functions, similar to __builtin_clz. I'm open
to suggestions about the name; I don't particularly like "norm" but
maybe that's what users expect.

Bootstrapped and tested on i686-linux (libmudflap.cth/pass39-frag.c
apparently fails randomly); also regression tested with a 4.5 c6x-elf
toolchain and the C6X port modified to provide clrsbsi2.  Also tested on
bfin-elf, where the modified builtins tests pass (test results are noisy
otherwise; I should do another run to get a baseline).

Ok?


Bernd

Attachment: clrsb.diff
Description: Text document


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