Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change of floating point control word in a DLL

8 views
Skip to first unread message

Lars Erdmann

unread,
Oct 21, 2008, 2:18:52 PM10/21/08
to
Hallo,

I have a DLL that changes the FPCW like this:

cw = _control87(MCW_EM,MCW_EM);
rc = IOProc_Entry2(pmmioStr, usMsg, lParam1, lParam2);


Questions:
1.) I guess the call to _control87 above just enables all floating point
exceptions, right ? Would that not be the default behaviour of any
thread anyway ?
2.) Do I need to reset the FPCW ?
cw = _control87(MCW_EM,MCW_EM);
rc = IOProc_Entry2(pmmioStr, usMsg, lParam1, lParam2);
cw = _control87(cw,MCW_EM);


Lars

Steven Levine

unread,
Oct 21, 2008, 3:39:38 PM10/21/08
to
In <48fe1d0c$0$17389$9b4e...@newsspool1.arcor-online.net>, on 10/21/2008
at 08:18 PM, Lars Erdmann <lars.e...@arcor.de> said:

Hi,

>Questions:
>1.) I guess the call to _control87 above just enables all floating point
>exceptions, right ?

That's how I read the call.

Would that not be the default behaviour of any
>thread anyway ?

No necessarily. This is highly runtime dependent. You might want to
google this group for the "fpcw trashing" and the "i hate fp math"
threads.

>2.) Do I need to reset the FPCW ?
> cw = _control87(MCW_EM,MCW_EM);
> rc = IOProc_Entry2(pmmioStr, usMsg, lParam1, lParam2);
> cw = _control87(cw,MCW_EM);

Only if the caller expects you to. Fun, huh?

What you can do in some (or maybe all) runtimes is capture the existing
control word with

old_cw = _control87(0,0);

and restore on exit with

_control87(old_cw,MCW_EM);

Steven

--
--------------------------------------------------------------------------------------------
Steven Levine <ste...@earthlink.bogus.net> MR2/ICE 3.00.11.18 BETA #10183
eCS/Warp/DIY/14.103a_W4 www.scoug.com irc.ca.webbnet.info #scoug (Wed 7pm PST)
--------------------------------------------------------------------------------------------

Peter Flass

unread,
Oct 21, 2008, 5:57:34 PM10/21/08
to
Steven Levine wrote:
> In <48fe1d0c$0$17389$9b4e...@newsspool1.arcor-online.net>, on 10/21/2008
> at 08:18 PM, Lars Erdmann <lars.e...@arcor.de> said:
>
> Hi,
>
>> Questions:
>> 1.) I guess the call to _control87 above just enables all floating point
>> exceptions, right ?
>
> That's how I read the call.
>
> Would that not be the default behaviour of any
>> thread anyway ?
>
> No necessarily. This is highly runtime dependent. You might want to
> google this group for the "fpcw trashing" and the "i hate fp math"
> threads.
>
>> 2.) Do I need to reset the FPCW ?
>> cw = _control87(MCW_EM,MCW_EM);
>> rc = IOProc_Entry2(pmmioStr, usMsg, lParam1, lParam2);
>> cw = _control87(cw,MCW_EM);
>
> Only if the caller expects you to. Fun, huh?
>
> What you can do in some (or maybe all) runtimes is capture the existing
> control word with
>
> old_cw = _control87(0,0);
>
> and restore on exit with
>
> _control87(old_cw,MCW_EM);
>
> Steven
>

This is an area where a glaring lack of a standard has caused no end of
problems. I do the save and restore, and so far haven't had any
problems, with a rather limited range of experience.

--
prf

Ilya Zakharevich

unread,
Oct 21, 2008, 8:31:07 PM10/21/08
to
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Steven Levine
<ste...@earthlink.bogus.net>], who wrote in article <48fe3261$1$fgrir53$mr2...@news.west.earthlink.net>:

> >2.) Do I need to reset the FPCW ?
> > cw = _control87(MCW_EM,MCW_EM);
> > rc = IOProc_Entry2(pmmioStr, usMsg, lParam1, lParam2);
> > cw = _control87(cw,MCW_EM);
>
> Only if the caller expects you to. Fun, huh?
>
> What you can do in some (or maybe all) runtimes is capture the existing
> control word with
>
> old_cw = _control87(0,0);
>
> and restore on exit with
>
> _control87(old_cw,MCW_EM);

Let me remind what (is my understanding about what) Scott said about
USING fp exceptions under OS/2:

starting from about v2.11, the support for "handling" FP exception
is removed from the kernel.

Which basically means that there is little reason to do anything with
the exception, but ignore it. Thus the value of save/restore over
"just reset" is minimal...

E.g., EMX CRT sets FP exception flags to "ignore". However, since
there is a lot of buggy DLLs around (mostly by IBM), they may change
the flags during THEIR loading - ruining all application using FP
math...

Therefore the need to reset FP exception flags to "ignore" afer any
call which has a chance to load IBM-written DLLs. MMPROCs are such...

Yours,
Ilya

Peter Flass

unread,
Oct 22, 2008, 6:59:02 AM10/22/08
to

Maybe this is true for the stuff you do, but for PL/I I need all the FP
exceptions except Inexact Result.

--
prf

Ilya Zakharevich

unread,
Oct 22, 2008, 4:30:03 PM10/22/08
to
[A complimentary Cc of this posting was sent to
Peter Flass
<Peter...@Yahoo.com>], who wrote in article <gdn0u2$pa1$1...@registered.motzarella.org>:

> Maybe this is true for the stuff you do, but for PL/I I need all the FP
> exceptions except Inexact Result.

That's very interesting! Can you share your exception handlers?

Thanks,
Ilya

0 new messages