This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
No Subject
> 2) number of bits set
Can be done using gcc inline assembly (on most CPUs that implement
the "NSA instruction" with a single opcode)
> 3) bit rotation
Dito.
e.g. on the x86:
extern inline unsigned int rotate_left(int i, unsigned int word)
{
asm("roll %%cl,%0"
:"=r" (word)
:"0" (word),"c" (i));
return word;
}
> this could be done in the optimizer but would be hard to identify afaik...
gcc tries to spot some of the constructs used to simulate rotation
in C ((x<<i) | (x>>(wordsize-i))) and output it as a single rotate
instruction, but this seems to only work for constant rotate counts.
-Andi
--
This is like TV. I don't like TV.