V

Vaibhav Sagar

vaibhavsagar.com · Personal blog · on HN since 2017

Vaibhav Sagar writes about Haskell, functional programming, algorithms, and SAT solving, with some posts on low-level topics.

What HN saysHN links his popcount post when people discuss the popcnt CPU instruction and its history, including its alleged use in cryptanalysis and by the NSA.
30HN people shared it
15linked it in comments
17stories submitted
1.1Kstory points
1 year agolast shared
2017people per year2026

Most-shared posts

  1. 1
    Popcount CPU instruction
    17 people · 622 points · first shared 2019 · 162 comments on HN
  2. 2
    Imperative Haskell
    2 people · 149 points · first shared 2017 · 69 comments on HN
  3. 3
    IHaskell on CoCalc
    2 people · 8 points · first shared 2018 · discussion on HN
  4. 4
    Monad Anti-tutorial
    2 people · 4 points · first shared 2017 · discussion on HN
  5. 5
    Revisiting 'Monadic Parsing in Haskell'
    1 people · 116 points · first shared 2018 · 10 comments on HN
  6. 6
    SATisfying Solutions to Difficult Problems
    1 people · 112 points · first shared 2025 · 57 comments on HN
  7. 7
  8. 8
    Discovering Continuations with Typed Holes
    1 people · 2 points · first shared 2017 · discussion on HN
  9. 9
    Refactoring Haskell: A Case Study
    1 people · 2 points · first shared 2019 · discussion on HN
  10. 10
    I Haskell a Git
    1 people · 2 points · first shared 2017 · discussion on HN
  11. 11
    Binary Trees to Hash Array Mapped Tries, Step by Step
    1 people · 1 points · first shared 2023 · discussion on HN
  12. 12
    Building Static Haskell Binaries with Nix
    1 people · 1 points · first shared 2018 · discussion on HN
  13. 13
    Hamts from scratch
    1 people · first shared 2023

What HN people wrote when they linked it

aleph_minus_one · 2025-10-17
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
zellyn · 2025-03-06
Some of it is moving or has moved down to the instruction sets: https://vaibhavsagar.com/blog/2019/09/08/popcount/
immibis · 2024-06-27
Allegedly added to the instruction set by request of the NSA, who uses it for things. https://vaibhavsagar.com/blog/2019/09/08/popcount/
vaibhavsagar · 2023-08-25
I wrote about these too: https://vaibhavsagar.com/blog/2018/07/29/hamts-from-scratch/! Unfortunately it's in Haskell which probably makes it less approachable than it would be otherwise.
psychphysic · 2022-12-19
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/
mattkrause · 2022-05-21
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/
yourapostasy · 2020-09-27
Discussion of uses of POPCOUNT instruction. https://vaibhavsagar.com/blog/2019/09/08/popcount/
pantalaimon · 2020-07-19
Huh, TIL. I always assumed this to be a rather old instruction, but turns out it was only added fairly recently on x86 https://vaibhavsagar.com/blog/2019/09/08/popcount/
StringyBob · 2020-07-14
There’s a few potential uses these days - more than just the famous crypto folklore one! Some examples on https://vaibhavsagar.com/blog/2019/09/08/popcount/
danidiaz · 2017-06-14
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
fsckboy · 2024-09-23
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.
eesmith · 2022-03-21
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…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close