Notes on negation
The well known formulasMost readers will be familiar with -x = ~x + 1 = ~(x - 1). These are often just stated without justification, or even an explanation for why they are equivalent. There are some...
View ArticleImplementing Euclidean division
While implementing various kinds of division in haroldbot, I had to look up/work out how to implement different kinds of signed division in terms of unsigned division. The common truncated division...
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 Articleabs and its "extra" result
The abs function has, in its usual (most useful) formulation, one extra value in its codomain than just "all non-negative values". That extra value is the most negative integer, which satisfies abs(x)...
View ArticleSquare root of bitwise NOT
The square root of bitwise NOT, if it exists, would be some function f such that f(f(x)) = not x, or in other words, f²(x) = not x. It is similar in concept to the √NOT gate in Quantum Computing, but...
View ArticleInformation on incrementation
Defining incrementJust to avoid any confusion, the operation that this post is about is adding 1 (one) to a value: $$\text{increment}(x) = x + 1$$ Specifically, performing that operation in the domain...
View ArticleWhy does AND distribute over XOR
blockquote { background: #f9f9f9; border-left: 10px solid #ccc; margin: 1.5em 10px; padding: 0.5em 10px; quotes: "\201C""\201D""\2018""\2019"; } blockquote:before { color: #ccc; content: open-quote;...
View ArticleThe range a sum cannot fall within
.nobr { white-space: nowrap; } Throughout this post, the variables A, B, and R are used, with R defined as R = A + B, and A ≤ B. Arithmetic in this post is unsigned and modulo 2k. Note that A ≤ B is...
View ArticlePartial sums of blsi and blsmsk
blsi is an x86 operation which extracts the rightmost set bit from a number, it can be implemented efficiently in terms of more familiar operations as i&-i. blsmsk is a closely related operation...
View ArticleInteger promotion does not help performance
There is a rule in the C language which roughly says that arithmetic operations on short integer types implicitly convert their operands to normal-sized integers, and also give their result as a...
View ArticleBit-level commutativity and "sum gap" revisited
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } In an earlier post, bit-level commutativity, it was shown that addition is...
View ArticleWeighted popcnt
.nobr { white-space: nowrap; } blockquote { background-color: #EEE; clear: both; } img { max-width: 100%; max-height: 100%; } Since I showed the code below on Twitter, and some people understood it...
View ArticleColumn-oriented row reduction
.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 Article(Not) transposing a 16x16 bitmatrix
.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 Articlegrevmul
.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 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 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 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 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 Article