Brute force beats LLMs: a compiler search finds a 4-op float trick no human spotted

Superoptimizing an FPU Emulator

Frustrated by a branch in a floating-point routine that extracts the lowest set bit, the author brute-forced every formula up to five operations instead of asking an LLM. Deduplicating equivalent expressions let the search finish in four minutes. It found a five-op solution, and manual inspection revealed one could be rewritten to reuse a subexpression, yielding a branchless four-op formula that flips the sign bit only for powers of two.

I was flabbergasted when I realized it found such a clever rewrite. You don't need an LLM to be amazed by what computers can invent!
  1. likoya

    to optimize such small piece of code you need micro benchmarks, and running one micro benchmark for each combination is not realistic

  2. azhenley

    I shared a toy superoptimizer I made a few years ago: https://news.ycombinator.com/item?id=36117950

    It was a really fun project!

  3. neerajsi

    I was curious about whether one of the count bits instructions can help. Of course I'm lazy now and asked an llm to check... The llm noticed that the articles solution includes a floating point subtract in the end. This is fine since the target is wasm which has fsub/fadd, but was initially odd to see in a floating point emulator.

    Apparently a ctz solution is a bit longer, but doesn't cross from the floating to integer domain at all, so might be better in the overall algorithm. There are hidden implicit floating to int convert instructions.

    This was a really cool little problem!

More from this day

2026-10-18