Visual C++ floating-point incorrect code generation bug. - by Malysh Maxim

Status : 


Sign in
to vote
ID 794184 Comments
Status Active Workarounds
Type Bug Repros 0
Opened 7/16/2013 5:34:07 PM
Access Restriction Public



At first I thought that the following issue is actually not a bug, but a result of a discrepancy with an outdated information in the following MSDN article:
But then I have found that compiler generates incorrect code in some cases.

1). "By default, the compiler uses the coprocessor's 80-bit registers to hold the intermediate results of floating-point calculations. "
2). "Expression evaluation will follow the C99 FLT_EVAL_METHOD=2, with one exception. When programming for x86 processors, because the FPU is set to 53-bit precision, this will be considered long double precision."

Issue #1:
The first statement is not true. By default, the compiler uses the XMM registers instead of the 80-bit FPU registers. This doesn't correspond to the first statement. 

Issue #2:
Sometimes the compiler generates code that uses just 32-bit parts of the XMM registers to hold the intermediate results instead of the 64-bit ones (in the case of using float data type). This doesn't correspond to the first and the second statement. I have attached an example of such code. 

Excuse me for any inconvenience if this is not a real bug.
Best regards,
Sign in to post a comment.
Posted by Mike Danes on 7/22/2013 at 11:35 AM
@Microsoft: IMO, this should not be closed. The documentation needs updating, it's confusing.
Posted by Microsoft on 7/22/2013 at 5:46 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. According to your description, we will close this case. Should you find any bugs in the future, please feel free to let us know.

Microsoft Visual Studio Connect Support Team
Posted by Malysh Maxim on 7/17/2013 at 4:36 AM
Thank you for your attention!

Now everything is clear.

Posted by Mike Danes on 7/16/2013 at 9:19 PM
The MSDN documentation is bogus, not the compiler. The documentation was correct before VS2012 when IA32 was default. In VS2012 the default changed to SSE2 so all that talk about 80 bit register, x87 and so on no longer applies. FLT_EVAL_METHOD is actually 0 by default, not 2. It's 2 only IA32 mode is enabled.

Code snippet from 3) uses double precision because printf requires a double to be passed in and "sum" has been evaluated at compile time and stored as a double. If you disable optimization you'll see that 32 bit precision is used to evaluate the actual expressions. That's expected.

Posted by Microsoft on 7/16/2013 at 5:53 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(