|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 14:01:33 2024 UTC