C
C
CPPJunior2015-07-29 16:39:39
Qt
CPPJunior, 2015-07-29 16:39:39

How to disable extended precision mode for FPU from DLL?

Hello.
I am maintaining a dll (msvc 2008 + qt4) which is being used by another application. Apparently this application switches the FPU to extended precision mode, so QLocale::toString starts to work incorrectly.
Example (see bugreport https://bugreports.qt.io/browse/QTBUG-13509):

// QLocale::toString is used inside QString::number
qDebug() << QString::number(1951.0); // 1951
// switch FPU to extended precision mode
 __asm
{
     FNINIT
     sub esp,2
     mov word ptr [esp],037Fh ; ensure precision control is extended, and exception masks set.
     fldcw [esp]
     add esp,2
}
qDebug() << QString::number(1951.0); // 1950.:

To fix this, I decided to try disabling this mode in the DllMain function, but for some reason this does not work. Please tell me:
1. How to disable/switch precision mode for FPU from dll?
2. Is it worth doing this at all? I understand that this is a global setting that can affect the results of calculations of other programs.
3. Is it possible to bypass the bug using compiler settings? Those. do not use FPU (generate code for SSE for example).

Thanks in advance.
UPDATE
After some thought and googling, I came to the following conclusions.
2. The setting is set for each process (because I tried to run my dll under different programs at the same time, while in one case the bug appeared, but not in the other).
3. Probably possible in the general case ( stackoverflow.com/questions/2565693/floating-point... but specifically to solve my problem, I will need to rebuild QtCore (because the code with the bug is most likely in this dll).
1. The question remains open.It would be logical to do this in DllMain, but it doesn’t work that way (in my case), it’s probably important how the client dll/

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question