News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FPU Rounding mode preservation ?

Started by Ficko, January 21, 2011, 08:10:44 AM

Previous topic - Next topic

Ficko

Does someone knows something about windows preservation of FPU rounding mode after returning from a API call ?

Does it or doesn't ? ::)

MichaelW

Per Agner Fog's calling_conventions.pdf (available here), under Register Usage:

"The floating point control word and bit 6-15 of the MXCSR register must be saved and restored before any call or return by any procedure that needs to modify them, except for procedures that have the purpose of changing these."

So by convention, the RC field should be preserved around an API call. I do, however, know that unless you tell it not to Direct3D will set the PC field for a 24-bit precision, and in my test the change appeared to occur in a call to ShowWindow. So apparently not the entire API follows the convention.
eschew obfuscation

BogdanOntanu

You need to save your rounding mode when making  any kind of API call if your code must use a certain rounding mode.
In other words the API is free to change the rounding mode in anyway it wants. Rounding mode is not saved by API.

The only guarantee is that during a context switch Windows will save and restore the current FPU registers and rounding mode  but this is standard / expected or else big errors would occur.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Ficko


raymond

And, do NOT rely on Windows preserving any of the FPU data registers during API calls requiring mathematical computations (such as sizing a window). It seems that ALL their math operations (even adding 3+3) are done with the use of MMX instructions which trash the FPU registers.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com