When using the optimisation flag, MSVC created code that is functionally equivalent to multiplying it by 0.5. But knowing what we know about floats, there is another way. We could subtract that magic number!
In assembly, both of these methods use just 4 instructions, 3 moves and an arithmetic operation. The question is: Is it easier to subtract or multiply?
void myHalveASM(float& num)
{
_asm {
mov eax, DWORD PTR[ebp + 8]
mov ebx, DWORD PTR[eax]
sub ebx, 8388608
mov DWORD PTR[eax], ebx
}
}