[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Counting bits



Since people are playing "my processor is better than your processor"...

This case (counting number of bits set in n-bit word) takes 2n+1
instructions on the HP PA-RISC processor.  (HP's compiler generates
2n+2 instructions, GCC takes 2n+1).  No branch instructions are
generated in either case.

HP's compiler uses the conditional skip feature of the PA
architecture, while GCC converts

	if (x&(1<<n)) y++;

into the equivalent branchless form:

	y += ((x>>n)&1);

( (x>>n)&1 being a single-instruction bitfield extract on the PA).

						- Bill