|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63773 Improve BitSet::cardinality() performance
Submitted: 2012-12-14 20:18 UTC Modified: 2017-10-24 08:00 UTC
From: harroyo at hangar18 dot cc Assigned:
Status: Open Package: Bitset (PECL)
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: harroyo at hangar18 dot cc
New email:
PHP Version: OS:


 [2012-12-14 20:18 UTC] harroyo at hangar18 dot cc
Current implementation of BitSet::cardinality() counts bits one at a time. This 
can be done a lot better using known fast methods for computing the "hamming 
weight". The easiest way (for Linux) would be to check if the compiler is GCC and 
use the __builtin_popcount() it provides, or use one of the implementations shown 

Probably it would also need to change the type of bitset_val on from unsigned 
char* to unsigned long* (or unsigned long long * etc, so 32/64 bits are handled 
at a time).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-14 20:28 UTC]
-Assigned To: +Assigned To: willfitch
 [2017-10-24 08:00 UTC]
-Status: Assigned +Status: Open -Assigned To: willfitch +Assigned To:
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jan 28 08:05:53 2023 UTC