Superoptimizing an FPU Emulator
purplesyringa.moe26 points by dverlaeckt80 2 days ago
26 points by dverlaeckt80 2 days ago
I shared a toy superoptimizer I made a few years ago: https://news.ycombinator.com/item?id=36117950
It was a really fun project!
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!