ChatGPTCoding & Dev▲ 439 on X2026-10-13

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

Time / cost: Not stated in the source

Steps

  1. Paste the routine with its comments and say which CPU or runtime it targets.
  2. Ask for a faster version and for the cost math (cycles, instructions or benchmarks) for both versions.
  3. Ask it to list the input sizes or cases where the new version is slower.
  4. 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.

Prompt written by AgentPlays from the source. Fill in the [brackets] and approve before anything is sent or bought.

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!

— @davepl1968 on X

Read the original source ↗

Added · Source link last checked · How we verify · Report an error

Related