Asking a bit-permutation what it does (and cloning it)
Given some black-box permutation that operates on an array of integers, it's easy to find out what the permutation does: feed it an array containing the number 0 .. n-1, apply the permutation to it,...
View ArticleFenwick trees for products mod 2ⁿ
After browsing some articles about Fenwick trees (aka Binary Indexed Trees) and seeing remarks such as "let f be some group operation" and "prefix operations such as sum, product, XOR and OR", I...
View ArticleWhat is abs(x - y)
What is abs(x - y), why do I even bother asking a question like that, much less answer it? Trust me, it's more interesting than it looks. To start with, here's something that it is not. Despite...
View ArticleComputing 264 mod N, where N is a u64
Before we go any further, the answer is (usually) -N % N."Usually", because for example MSVC with "SDL checks" enabled is offended by the negation of an unsigned integer and you may need to subtract...
View ArticleThe non-problem of unsigned integers in Java
div:has(> blockquote) { background-color: #ededed; margin: 10px auto; padding: 15px; border-radius: 5px; } blockquote p::before { content: "\201C"; } blockquote p::after { content: "\201D"; }...
View ArticleFrom Boolean logic to bitmath and SIMD: transitive closure of tiny graphs
Let's say that we have a graph of at most 8 nodes (you can also think of it as a relation between 8 things), represented as an 8 by 8 Boolean matrix, and we want to compute its transitive closure. A...
View ArticleSigned wrapping is meaningful and algebraically nice
Signed wrapping is not wrongSigned wrapping is meaningfulSigned wrapping is not inherentSigned wrapping is algebraically niceIn this post I defend wrapping, a bit more opinionated than my other posts....
View ArticleBit-permuting 16 u32s at once with AVX-512
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } The basic trick to apply the same bit-permutation to each of the u32s is...
View ArticleHistogramming bytes with positional popcount (GF2P8AFFINEQB edition)
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } A while ago, after some back and forth on twitter/X with @corsix, I...
View ArticleEnumerating identities, part 2
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } Part 2 of Enumerating all mathematical identities (in fixed-size bitvector...
View ArticleSorting the nibbles of a u64
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } I was reminded (on mastodon) of this nibble-sorting technique (it could be...
View ArticleSharpening a lower bound with KnownBits information
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } I have written about this before, but that was a long time ago, I've had a...
View ArticleMultiplying 64x64 bit-matrices with GF2P8AFFINEQB
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } This is a relatively simple use of GF2P8AFFINEQB. By itself GF2P8AFFINEQB...
View ArticleImplementing grevmul with GF2P8AFFINEQB
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } As a reminder, grev is generalized bit-reversal, and performs a...
View ArticleEnumerating all mathematical identities (in fixed-size bitvector arithmetic...
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } Once again a boring-but-specific title, I don't want to clickbait the...
View ArticleThe solutions to 𝚙𝚘𝚙𝚌𝚗𝚝(𝚡)
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } popcnt(x) < tzcnt(x) asks the question "does x have fewer set bits than...
View ArticlePartial sums of popcount
The partial sums of popcount, aka A000788: Total number of 1's in binary expansions of 0, ..., n can be computed fairly efficiently with some mysterious code found through its OEIS entry (see the link...
View ArticlePermuting bits with GF2P8AFFINEQB
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } It's no secret that GF2P8AFFINEQB can be tricky to think about, even in...
View ArticlePropagating bounds through bitwise operations
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } blockquote footer { background-color: #F5F5F5; clear: both; } blockquote:before { color: #ccc; content: open-quote;...
View ArticleSome ways to check whether an unsigned sum wraps
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } When computing x + y, does the sum wrap? There are various ways to find...
View Article