Vaibhav Sagar writes about Haskell, functional programming, algorithms, and SAT solving, with some posts on low-level topics.
HN links his popcount post when people discuss the popcnt CPU instruction and its history, including its alleged use in cryptanalysis and by the NSA.
Not by an order of magnitude!
Surely you've heard of gamers who add special cooling devices so they can overclock the CPU. Increase the frequency and power consumption increases.
Decrease the frequency and power consumption decreases. You don't need as much cooling.
And those Crays needed special cooling. Quoting Wikipedia for the Cray-1:
> each circuit board was paired with a second, placed back to back with a sheet of copper between them. The copper sheet conducted heat to the edges of the cage, where liquid Freon running in stainless steel pipes drew it away to the cooling unit below the machine. The first Cray-1 was delayed six months due to problems in the cooling system
Any computer engineer working on a severely underclocked Cray is going to wonder why it has so much unused cooling.
From a business sense, think how many more sales you could have without including needlessly exotic Freon cooling that requires developing new welding techniques.
> declassified about Cray at some US government agency in the 60s/70s
Cray was close to the NSA, yes. That's no secret. The NSA and related agencies funded a lot of supercomputing research.
The popcount instruction, implemented in the Cray-1 and other machines, even has the nickname "The NSA Instruction". https://vaibhavsagar.com/blog/2019/09/08/popcount/ and https://news.ycombinator.com/item?id=27470529 .
> ... interesting is you both (you and another commenter) used ..
Don't assume independence between commenters. I…
to save you time, this is a summary of the links various people here are posting:
popcnt of a word counts the number of bits that are "1"
https://www.talkchess.com/forum3/viewtopic.php?t=38521
the NSA wanted to do cryptanalysis on intercepted messages, and since the CDC 6000 had 60-bit words, one word was enough to store most alphabets they were interested in. They were able to:
Split a message into lines Set a bit for each unique character they encountered per line Use popcount to count the distinct characters Use the count as a hash for further cryptanalysis Curiously, popcount seems to have disappeared from instruction sets between the mid-1970s and the mid-2000s.
(of course for all we know this could be NSA disinformation ;)
That's the answer to the NSA question. There are other uses described here https://vaibhavsagar.com/blog/2019/09/08/popcount/ including for Hamming codes and Neural nets and more.
Here is an article about the popcnt instruction:
https://vaibhavsagar.com/blog/2019/09/08/popcount/
The author of the article believes that while popcnt was indeed used for cryptographical analysis in the 60s, but the fact that popcnt disappeared from instruction sets is seen as evidence that this usage became a lot less important over time. So the author considers the reason for the reappearance of popcnt that there simply exist lots of other useful applications of popcnt that become evident over these decades.
A German article about the same topic:
https://nickyreinert.medium.com/ne-49-popcount-ea62aa304f88
There was a recent post about "imperative Haskell": http://vaibhavsagar.com/blog/2017/05/29/imperative-haskell/
The code in this other post about implementing string distance metrics is also quite imperative: https://markkarpov.com/post/migrating-text-metrics.html
It’s surprisingly useful, and shows up everywhere from chess to molecular biology—-but the CPU instruction probably exists because of its use in code-breaking.
This article has a lot of interesting examples.
https://vaibhavsagar.com/blog/2019/09/08/popcount/
Have a look at popcount[0]. It's even a single instruction on many platforms [1].
[0] https://en.cppreference.com/w/cpp/numeric/popcount
[1] https://vaibhavsagar.com/blog/2019/09/08/popcount/