cvs commit: src/sys/i386/i386 mp_machdep.c

Nate Lawson nate at root.org
Wed Nov 5 22:46:45 PST 2003


On Wed, 5 Nov 2003, Peter Wemm wrote:
>   Modified files:
>     sys/i386/i386        mp_machdep.c
>   Log:
>   OK, this might be a bit silly, but add another popcnt() candidate.
>
>   Revision  Changes    Path
>   1.221     +6 -0      src/sys/i386/i386/mp_machdep.c
>
> @@ -915,6 +915,12 @@
>   * -mcpu=pentiumpro and -march=pentiumpro then gcc-3.1 will use
>   * an imull, and in that case it is faster.  In most other cases
>   * it appears slightly slower.
> + *
> + * Another variant (also from fortune):
> + * #define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255)
> + * #define  BX_(x)     ((x) - (((x)>>1)&0x77777777)            \
> + *                          - (((x)>>2)&0x33333333)            \
> + *                          - (((x)>>3)&0x11111111))
>   */
>  static __inline u_int32_t
>  popcnt(u_int32_t m)

Ah, the O(1) bit count, a MSFT interview question.  :)

-Nate


More information about the cvs-src mailing list