During an exchange of war stories, a colleague of mine told one from back in the days when Windows included a processor emulator for x86-32 on systems that natively ran some other processor. (This has happened many times. And no, I don’t know which processor this particular story applied to.)
This particular emulator employed binary translation, generating native code to perform the equivalent operations of the original x86-32 code. This offered a significant performance improvement over emulation via interpreter. You can imagine that x86-32 is just a bytecode, and the emulator is a JIT compiler.
Anyway, my colleague found that there was one program that needed to allocate around 64KB of memory on the stack and initialize it. The standard way of doing this is to perform a stack probe to ensure that 64KB of memory is available, then subtracting 65536 from the stack pointer, and then initializing the memory in a small, tight loop.
But using a loop to initialize the memory was too mundane for whatever compiler was used to compile this code. Instead of generating a loop to initialize each byte of the buffer, the compiler “optimized” the code by unrolling the loop into 65,536 individual “write byte to memory” instructions, each 4 bytes long.
All in all, it took this program 256 kilobytes of code to initialize 64 kilobytes of data.
This offended the team so much that they added special code to the translator to detect this horrible function and replace it with the equivalent tight loop.
Speed, size, pick one… sounds like that code was optimized for speed?
In Z80, we’d use runs of LDI rather than a spacially-concise LDIR when speed was of the esscance, as often the case in early 1980s.
At the other extreme, I spent 3 weeks shrinking a 1027-byte program to fit the ZX Spectrum print buffer. Instead of an if-then logic, I modified code before execute.
Prolly not an approved approach in the 21st…
@Raymond Chen
Come on Raymond, don’t leave us hanging, shame that compiler which did infinite loop unrolling?
Thanks?
.. is it just me, or does *EVERY SINGLE ONE* or the comments – other than mine – absolutely scream “I was written by a shitty AI comment bot” or no??
Says the guy using em-dashes in his writing.
In all seriousness, though, I didn’t see anything that screams “AI” to me.
There’s a bunch of technical stuff, but that’s to be expected on a post explicitly talking about technical details.
Microsoft’s blog software coverts normal dashes to emdashes. Take a guess why Microsoft would make that change.
I wanted to write that I am surprised people in 2026 don’t understand how replies work… not that the comments seem somewhat AI-ish.
Blame the commenting website software for that one.
There’s been tons of reports of people’s comments getting added to the wrong thread, or not added to a thread at all, or being shown out-of-order.