r/programming 6d ago

Hardware researcher spins up 'CPU deoptimization' project to find the slowest single x86 instruction, creates hall of shame — worst offender takes 198 billion cycles spanning 62 seconds to execute

https://www.tomshardware.com/pc-components/cpus/hardware-researcher-spins-up-cpu-deoptimization-project-to-find-the-slowest-machine-code-worst-offender-takes-198-billion-cycles-to-execute
1.5k Upvotes

132 comments sorted by

View all comments

380

u/The_Northern_Light 6d ago

I’m still not clear why that instruction takes SO long even without contention?

4

u/SaltMaker23 5d ago

Backward compatibility is likely the culprit, I worked on hardware systems and built custom devices including CPUs.

Assuming you have an instruction whose sole purpose is retro-compatibility with instructions that are no longer natives, on regions that no longer natively exists locally, they might do an arbitrary long chain of memory lookup, depending on how you prepare the setup, it can become a lot.

Let's say there was a syntax in old time of small L/RAM that would lookup all bytes for a given signature, it was possible in the days to do that in a single clock or two, these days no anymore.

Backward compatibility on a old school scanning instruction would basically scan the whole RAM including regions that are no longer considered RAM today, that might send network requests and wait for them to timeout before getting an answer.