Have ChatGPT find a faster version of a hand-tuned assembly routine, with the cycle math
Dave Plummer, the former Microsoft engineer behind Windows Task Manager, asked ChatGPT to optimize a memcpy he wrote for the Motorola 68000. It proposed moving 12 registers instead of 11, unrolling four transfers per loop and ending on a source-address compare, for a modeled 9.6% throughput gain on long aligned copies (about 5.2% for a full 512-byte copy). The numbers are calculated from MC68000 instruction timings; ChatGPT said it had not assembled or hardware-tested the code.
Try it yourself
What you get
A proposed rewrite of a performance-critical routine with cycle counts for old and new versions, where it's slower, and how it was checked.
Tools
Steps
- Paste the routine with its comments and say which CPU or runtime it targets.
- Ask for a faster version and for the cost math (cycles, instructions or benchmarks) for both versions.
- Ask it to list the input sizes or cases where the new version is slower.
- Ask how it checked correctness, then assemble, test and benchmark it yourself on real hardware.
Copy-ready prompt
Make this routine faster without changing its behavior. Target: [CPU or runtime, e.g. MC68000, x86-64, Node 22] Routine: [paste code with its comments] 1. Explain where the time goes now, with cycle counts or cost estimates per loop. 2. Propose a faster version and show the same math for it. 3. Give the speedup for small, medium and large inputs, and list any cases where the new version is slower or uses more memory or code space. 4. Write tests covering edge cases (empty input, odd alignment, boundaries) that I can run on both versions. 5. Say clearly what you calculated versus what would need real measurement.
Watch out: These are modeled cycle counts, not measurements; ChatGPT said it had not assembled or hardware-tested the code. Benchmark any rewrite on the real target before you ship it.
Proof / source
Self-reported The author's post on X with ChatGPT's full analysis: per-loop cycle counts, the rewritten loop and a table of modeled results by copy size.
In their words
I had ChatGPT optimize my "fastest code ever", a version of memcpy that I'd written for the 68000 (with unaligned support). TLDR: It found a 9.6% improvement 40 years later!
Related
Turn a $25 airline voucher into $4,760.36 in EU261 compensation
Panos Ipeirotis's Norse Atlantic flight from Oslo was delayed overnight, and the airline offered a $25 card. ChatGPT walked him through EU261, the Norwegian complaint bod…
Get a £60 parking charge dropped and win £462.15 in costs
Loren Cole fed Parkingeye's letters into ChatGPT, which pointed out gaps such as a floor plan sent instead of photos of the signs. Parkingeye withdrew its court claim, an…
Appeal a wrongly issued £60 council parking fine with a ChatGPT letter
Student Millie Houlton had a resident permit but got a £60 fine anyway. She gave ChatGPT the details and her fine reference, sent the letter it wrote to York council, and…
Win $1,180 in small claims after ChatGPT spotted an illegal security deposit
When their landlord kept about $1,000 of the deposit, Chris Maloney ran his lease through ChatGPT. It flagged that New York caps deposits at one month's rent, and they ha…