frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Pop Goes the Population Count?

https://xania.org/202512/11-pop-goes-the-weasel-er-count
59•hasheddan•1d ago

Comments

bombcar•1d ago
Isn't this the instruction that apparently the NSA asked for?
adgjlsfhk1•1d ago
yeah. They understood how useful computing on bits can be before anyone else.
pklausler•1d ago
It goes back to the CDC 6600 at least, and is most often seen as part of Hamming distance computation (pop(xor(x,y))). But it turns out to be really useful for other things (trailing zero count), and worth having in hardware since the software sequence is a ~dozen instructions for 64 bits.
kens•1d ago
I did a lot of research on this [1]. I got confirmation from Robert Garner (architect of the SPARC processor) that the NSA did indeed ask for the population count instruction. His story of meeting with the NSA is pretty amusing [2].

[1] https://retrocomputing.stackexchange.com/a/8666/4158

[2] https://archive.computerhistory.org/resources/access/text/20...

majke•1d ago
Hey! Popcount used to be my favorite instruction. Now I think I prefer LOP3 though :)
azinman2•13h ago
Could you explain more please?
wat10000•1d ago
There's a fun approach where do the computation as a tree in parallel. You do a little masking and shifting to add all the even-numbered bits to all the odd-numbered bits, and come up with a set of (assuming we're working on a 64-bit value) 32 partial sums of 2 bits each. Then you add pairs of those to get 16 partial sums of 4 bits each, and so forth until you get to the top. This requires six sums, plus shifts and masks for each one.

I don't know if compilers are able to detect this and compile it down to a single instruction, though.

mattgodbolt•1d ago
All that and more: https://graphics.stanford.edu/~seander/bithacks.html#CountBi... :)
taeric•1d ago
Somewhat related, "Gosper's hack" is a fun way to loop through all of the values that have the same number of 1s.
dhosek•1d ago
I still find it wild that Godbolt is his actual name and not some cool term used for the tool to see what compiler output looks like.
silisili•1d ago
Same! I always assumed it was the name of the tool until I found out it was a person not long ago.

Maybe a bit of a stretch, but I could see it fitting - https://en.wikipedia.org/wiki/Aptronym

burnt-resistor•1d ago
I <3 [AT]BM and BMI[12], and functional-equivalency matching with cost minimization optimization compiler passes.

I wish GCC and LLVM had compiler passes to semi/automagically "vectorize" hot sections using SIMD, i.e., magic transformation of UTF-8 conversion, regex matching, and string functions.

thefaux•1d ago
As impressive as this analysis is by the compiler, I shudder to think how much time the compiler spends doing these kinds of optimizations. In my opinion, a better architecture would be for the compiler to provide a separate analysis tool that suggests source level changes for these kinds of optimizations. It could alert you that the loop could be replaced with a popcount (and optionally make the textual replacement in the source code for you). Then you pay the cost of the optimization once and have the benefit of clarity about what your code _actually_ runs at runtime instead of the compiler transparently pulling the rug out from underneath you when run with optimizations.

Side note: many years ago I wrote the backend for a private global surveillance system that has almost surely tracked the physical location of anyone reading this. We could efficiently track how often a device had been seen at a location in the prior 64 (days|weeks|months) in just 192 bytes and use popcount to compute the value. I am not proud that I built this.

adgjlsfhk1•1d ago
Especially in languages that allow generic programming, the right thing to do will be context dependent.
Quekid5•22h ago
The issue is that many optimization opportunities only appear after monomorphization, inlining, de-virtualization, etc. etc.

Not that you couldn't do source level analysis as you suggest... it just wouldn't be effective in many cases.

It would also be 'unstable' in the sense that it might depend on architecture, etc.

Covid Origins. Debunking the Politics and Pseudoscience of Lab Leak Claims

https://www.youtube.com/watch?v=ra0WKNhQZ0U
1•vo2maxer•1m ago•0 comments

Interactive Visualization of the Standard Model of Particle Physics

https://llsourcell.github.io/physics/standard_model.html
1•llSourcell•2m ago•1 comments

5 Jobs 4 years and the mindspace leading to it

https://ritavdas.substack.com/p/the-things-i-said-id-never-do
1•fandango1•6m ago•0 comments

What happens when the coding becomes the least interesting part of the work

https://obie.medium.com/what-happens-when-the-coding-becomes-the-least-interesting-part-of-the-wo...
1•obiefernandez•7m ago•0 comments

Ask HN: How do you give a local AI model long-term memory?

1•javantanna•7m ago•0 comments

LibXML2, Used by Steam, Chromium, Others Is Now Abandoned

https://www.youtube.com/watch?v=GDr4fKXmUvc
1•rasengan0•10m ago•0 comments

OSS Friday Update – Fibers Are the Future of Ruby

https://noteflakes.com/articles/2025-12-12-friday-update
1•todsacerdoti•14m ago•0 comments

Show HN: Guftaguu – Anonymous Chat and Real-Time Games (No Login Required)

https://guftaguu.vercel.app
2•SeeYouInHelL•19m ago•1 comments

GitHub Is Down

https://github.com/
2•diek•21m ago•3 comments

ChatGPT 5.2 Tested: How Developers Rate the New Update (Another Marketing Hype?)

https://www.finalroundai.com/blog/chatgpt-5-2-developer-reactions
2•birdculture•24m ago•0 comments

Catland, the Louis Wain Archive

https://catland.distin.org/
1•graypegg•24m ago•0 comments

The state of the kernel Rust experiment

https://lwn.net/SubscriberLink/1050174/63aa7da43214c3ce/
1•dochtman•25m ago•0 comments

Pdf-sign – Adobe-compliant PDF signing with GPG Agent

https://github.com/0x77dev/pdf-sign
1•0x77dev•27m ago•0 comments

Shaping the future of AI from the history of Transformer [2024]

https://docs.google.com/presentation/d/1u05yQQaw4QXLVYGLI6o3YoFHv6eC3YN8GvWD8JMumpE/edit?slide=id...
1•qouteall•28m ago•1 comments

The state of the kernel Rust experiment

https://lwn.net/SubscriberLink/1050174/604164032b9a01cc/
2•howtofly•38m ago•0 comments

React Is Rainbow Colored

https://skyview.social/?url=https%3A%2F%2Fbsky.app%2Fprofile%2Fsh03.dev%2Fpost%2F3m7tz3zhl522f&vi...
2•Shoetp•39m ago•1 comments

Crowd-sourced comparison of USB security tokens

https://docs.google.com/spreadsheets/d/1XlwmreiBkt82F4HG965Yp9ncULkgnFpNyfe7WAAtYPk/edit?gid=0#gid=0
2•stv0g•44m ago•0 comments

AI Can Write Your Code. It Can't Do Your Job

https://terriblesoftware.org/2025/12/11/ai-can-write-your-code-it-cant-do-your-job/
1•thunderbong•44m ago•0 comments

Musk's Mars mission adds risk to red-hot SpaceX IPO

https://www.reuters.com/business/aerospace-defense/musks-mars-mission-adds-risk-red-hot-spacex-ip...
1•TMWNN•46m ago•0 comments

EZ File Changer – Private, client-side image converter

https://www.ezfilechanger.com
2•waqaar-ansari•54m ago•0 comments

Ozempic Turned a 1970s Hit into an Inescapable Jingle (2024)

https://www.nytimes.com/2024/04/09/arts/music/ozempic-jingle-oh-oh-oh-its-magic-pilot.html
1•nxobject•1h ago•0 comments

Firefox Version 146.0

https://www.firefox.com/en-US/firefox/146.0/releasenotes/
2•ksec•1h ago•1 comments

Can't take setting up another bucket for images

https://images.labnocturne.com/
3•jjenkins•1h ago•0 comments

Switzerland Engineered the Perfect Country [video]

https://www.youtube.com/watch?v=OMbV1rIPhCg
2•keepamovin•1h ago•0 comments

The New Allowance

https://www.theatlantic.com/family/2025/12/kids-allowance-investing-parenting/685214/
2•gmays•1h ago•0 comments

Show HN: Zootopia OC Maker – Create Zootopia-Style Original Characters with AI

https://aiocmaker.com/oc-maker/zootopia-oc-maker
1•qianjin1979•1h ago•0 comments

Is Prompt Engineering Dead? Only If You're Still Prompting Like It's 2023

https://news.ycombinator.com/macos-release-notes/macos-26-2-release-notes
1•ahmedkarem•1h ago•0 comments

Ask HN: How do you manage curl commands in your workflow?

1•subashn•1h ago•0 comments

Music Algorithms Failed Us

https://therectangle.substack.com/p/music-algorithms-failed-us
4•olyellybelly•1h ago•0 comments

Show HN: ADK-Rust: a Rust Implementation of Google Agent Dev Kit

https://adk-rust.com
1•Zavora•1h ago•0 comments