Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Nov 2003 22:47:00 -0800 (PST)
From:      Nate Lawson <nate@root.org>
To:        Peter Wemm <peter@FreeBSD.org>
Cc:        cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/i386/i386 mp_machdep.c
Message-ID:  <20031105224619.Q17086@root.org>
In-Reply-To: <20031106012459.0094816A542@hub.freebsd.org>
References:  <20031106012459.0094816A542@hub.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031105224619.Q17086>