Skip to content
purplesyringapurplesyringa
ARTIFICIAL INTELLIGENCE
Superoptimizing an FPU emulator
Superoptimization is the process where a compiler automatically finds the optimal sequence for a loop-free sequence of instructions. – Wikipedia Compilers are good at making mechanical transformations that make code faster. Unfortunately, most of them are not as good at non-trivial reasoning, so they can’t invent a completely novel approach to solving your problem. When designing a library for floating-point calculations, I had to implement a function that takes a float f and produces a float corresponding to the lowest set bit in f . For example, if f = 1.01101 ⋅ 2 10 in binary, it would return 0.00001 ⋅ 2 10 = 2 5 . This can be implemented with bit twiddling, but the straightforward algorithm breaks for powers of two, so I had to insert an if: if f32::from_bits(x.to_bits() & !f32::MANTISSA_MASK) == x { // is x a power of two? return x; // x itself is the lowest bit } else { return x - f32::from_bits(x.to_bits() & (x.to_bits() - 1)); // x, minus x without lowest bit } This if really annoyed me. It’s slowed down for the common case, and branches could be mispredicted. I wanted to find a formula that automatically handled powers of two, but try as I might, I couldn’t find anything convincingly optimal. So I made a non-orthodox play.
purplesyringapurplesyringa
SOFTWARE AND DATA ENGINEERING

Superoptimizing an FPU emulator

> Superoptimization is the process where a compiler automatically finds the optimal sequence for a loop-free sequence of instructions. > > – Wikipedia Compilers are good at making mechanical transformations that make code faster. Unfortunately, most of them are not as good at non-trivial reasoning, so they can’t invent a completely novel approach to solving your problem. When designing a library for floating-point calculations, I had to implement a function that takes a float <!-- MathML: <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi></math> --> f and produces a float corresponding to the lowest set bit in <!-- MathML: <math xmlns="http://www.w3.org/1998/Math/MathML"><mi>f</mi></math> --> f. For example, if <!-- MathML: <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi>f</mi><mo>=</mo></mrow><mrow><mn>1.01101</mn><mo>⋅</mo></mrow><mrow><msup><mn>2</mn><mn>10</mn></msup></mrow></math> --> f=1.01101⋅210 in binary, it would return <!-- MathML: <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mn>0.00001</mn><mo>⋅</mo></mrow><mrow><msup><mn>2</mn><mn>10</mn></msup><mo>=</mo></mrow><mrow><msup><mn>2</mn><mn>5</mn></msup></mrow></math> --> 0.00001⋅210=25. This can be implemented with bit twiddling, but the straightforward algorithm breaks for powers of two, so I had to insert an if: rust if f32::from_bits(x.to_bits() & !f32::MANTISSA_MASK) == x { // is x a power of two? return x; // x itself is the lowest bit } else { return x - f32::from_bits(x.to_bits() & (x.to_bits() - 1)); // x, minus x without lowest bit } This if really annoyed me. It’s slowed down for the common case, and branches could be mispredicted. I wanted to find a formula that automatically handled powers of two, but try as I might, I couldn’t find anything convincingly optimal. So I made a non-orthodox play.
purplesyringapurplesyringa
ARTIFICIAL INTELLIGENCE
Things I wish I knew before starting speedrunning
I started speedrunning Minecraft a while ago. It’s an interesting niche with many tutorials and a helpful community, so all the information you need is freely available. But I used to struggle a lot, because it wasn’t clear to me how to learn to execute this stuff – partially because my hand-eye coordination and reaction time suck, but also because most of the advice on improving mechanics is literally “play more”, and for me personally familiarity doesn’t easily translate into improvements. I think I found an approach that works for me, and I want to share it here. Since it focuses on how to deal with stuff mentally rather than on MCSR specifically, I think it should be applicable elsewhere in case traditional approaches fail for you, so hopefully it’s going to be useful to more than one person.
MINECRAFT
purplesyringapurplesyringa
ARTIFICIAL INTELLIGENCE
Things I wish I knew before starting speedrunning
I started speedrunning Minecraft a while ago. It’s an interesting niche with many tutorials and a helpful community, so all the information you need is freely available. But I used to struggle a lot, because it wasn’t clear to me how to learn to execute this stuff – partially because my hand-eye coordination and reaction time suck, but also because most of the advice on improving mechanics is literally “play more”, and for me personally familiarity doesn’t easily translate into improvements. I think I found an approach that works for me, and I want to share it here. Since it focuses on how to deal with stuff mentally rather than on MCSR specifically, I think it should be applicable elsewhere in case traditional approaches fail for you, so hopefully it’s going to be useful to more than one person.
MINECRAFT