-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static BitArray #412
Comments
Sure... this should be fine. I'll also note that such a type could be developed outside of |
Also, for 8x8 in particular I'd note a less generic approach that takes advantage of the fact that byes are 8 bits would probably be optimal (e.g. faster 2D indexing?) |
Regarding static BitVectors, I'd like to see them "effectively" big-endian, in the sense that
instead of shifting 1 to the left. The reason is that we really want to use the integer comparison operations in order to compare bitvectors, i.e. the logical fist bit needs to be the MSB of the first UInt64. Base BitVector uses a very weird mixed endian format that makes lexicographic comparisons on 64bit chunks bad, no need to replicate that. |
I recently needed this, and made an implementation. So, the question would be: Comments? Should I make a PR? Design Facts: Convenience container: Open question: Unfixed problem: |
@chethega This would be most useful if there were a mutable version as there is for the general static arrays. (I noticed the gists you put up above didn't have setters when I tried to use them, and am having a brief look at adding those now, but will probably just fall back to regular bit arrays for now.) |
Sure, tell me what you need. My current working variant is completely divorced from StaticArrays (I duplicate the I currently don't think that the But if you tell me what you need, then I can make you a small gist with the relevant parts of my current implementation. |
@chethega |
Look at #647 The pop-count sum is implemented as
This one basically scales in the number of entries in
That code is of course terrible, and we would need a faster way of compressing into I suspect that the first approach will be faster, but has the disadvantage of data-dependent branching. This is very bad in some contexts (e.g. security side-channels). I have no intention of implementing any bitpacked matmul in the near future; but feel free to propose some code. |
Sorry I'm thinking out loud. This is all obvious to everyone else. It's possible to make static BitArrays by just by using StaticArray{size,Bool}, but the size of a UInt64 is 8 and SVector{64,Bool} is 64. A factor of 8 could be quite bad for cache efficiency. You could implement something like a struct of Uints and then do bit manipulations on them directly using I'm wondering, is it possible to simply replace Vector with SVector in the implemetation of Base.BitArray, to create SBitArray and then subtype everything to work? Here's how base defines BitArrays:
Update well as everyone knows you can't subtype concrete types, okay I'm still learning here. sorry to use github to think outloud. :( |
Since this hasn't really been brought up before, I would like to suggest the possibility of Static BitArrays. In particular, since the performance of static arrays relative to regular arrays are so closely tied to their size, the space optimization afforded by BitArrays may allow much larger arrays to reap performance gains.
For example, a bitboard for Chess would require only 64 bits, so it could fit in a single register, discounting overhead.
The text was updated successfully, but these errors were encountered: