Proposal: Add Data.Bits.popCount

Maciej Marcin Piechotka uzytkownik2 at gmail.com
Wed Aug 17 19:44:17 CEST 2011


On Wed, 2011-08-17 at 18:37 +0200, Johan Tibell wrote:
> Hi!
> 
> Now when we have a fast popCnt# primop* it would be nice to expose it
> to the world through an official API. I propose we add this method to
> the Bits class in Data.Bits:
> 
>     -- | Return the number of set bits in the argument, know as the
>     -- population count or the Hamming weight.
>     popCount :: a -> Int
> 
> I will provide a default implementation, which means that this change
> won't break any existing user defined instances. All the instances for
> the basic types (Ints, Words, etc) will use the primops.
> 
> * These primops compile to a single POPCNT instruction if the user
> compile using -msse4.2 and a fast lookup table based implementation
> otherwise.
> 
> Discussion period: 2 weeks
> 
> Cheers,
> Johan

I posted bug for various similar instructions some time ago:

http://hackage.haskell.org/trac/ghc/ticket/4102

Probably the update should be done in batch (i.e. popCount,
trailing/leading zeros etc.)

Regards



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110817/cd76c39f/attachment.pgp>


More information about the Libraries mailing list