Change of floating point control word in a DLL - OS2

This is a discussion on Change of floating point control word in a DLL - OS2 ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Change of floating point control word in a DLL

  1. Change of floating point control word in a DLL

    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

  2. Re: Change of floating point control word in a DLL

    In <48fe1d0c$0$17389$9b4e6d93@newsspool1.arcor-online.net>, on 10/21/2008
    at 08:18 PM, Lars Erdmann 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 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)
    --------------------------------------------------------------------------------------------


  3. Re: Change of floating point control word in a DLL

    Steven Levine wrote:
    > In <48fe1d0c$0$17389$9b4e6d93@newsspool1.arcor-online.net>, on 10/21/2008
    > at 08:18 PM, Lars Erdmann 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

  4. Re: Change of floating point control word in a DLL

    [A complimentary Cc of this posting was NOT [per weedlist] sent to
    Steven Levine
    ], who wrote in article <48fe3261$1$fgrir53$mr2ice@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

  5. Re: Change of floating point control word in a DLL

    Ilya Zakharevich wrote:
    > [A complimentary Cc of this posting was NOT [per weedlist] sent to
    > Steven Levine
    > ], who wrote in article <48fe3261$1$fgrir53$mr2ice@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


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

    --
    prf

  6. Re: Change of floating point control word in a DLL

    [A complimentary Cc of this posting was sent to
    Peter Flass
    ], who wrote in article :
    > 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

+ Reply to Thread