Always false float comparisons

Ethan Watson via Digitalmars-d digitalmars-d at puremagic.com
Thu May 12 08:03:26 PDT 2016


On Thursday, 12 May 2016 at 14:29:01 UTC, Steven Schveighoffer 
wrote:
> There was a question on the forums a while back about 
> equivalent C++ code that didn't work in D. The answer turned 
> out to be, you had to shoehorn everything into doubles in order 
> to get the same answer.

I can certainly see that being the case, especially when dealing 
with SSE-based code. floats and doubles in XMM registers don't 
get calculated at 80-bit precision internally, their storage size 
dictates their calculation precision. Which has led MSVC to 
promoting floats to doubles for CRT functions when it thinks it 
can get away with it (and one instance where the compiler forgot 
to convert back to float afterwards and thus the lower 32 bits of 
a double were being treated as a float...)

It's fun comparing assembly too. There's one particular function 
we have here that collapsed to something like 20-30 lines of 
SSE-based code (half after I hand optimised it with branchless 
SSE intrinsics and without a call to fmod). The same function in 
D resulted in a significantly larger amount of x87 code.

I don't miss x87 at all. But this is getting OT.


More information about the Digitalmars-d mailing list