PDA

View Full Version : Set8087CW... Huh? :shock:



TheLion
15-02-2003, 09:41 AM
{ Save the current FPU state and then disable FPU exceptions }
Saved8087CW := Default8087CW;
Set8087CW($133f); { Disable all fpu exceptions }

I have seen this line in a few 3D Engines, both Delphi & C++, however I have no clue what it does exactly... It disables FPU exceptions and FPU seems to be some sort of instruction set for the i386, but since I'm quite an ASM n00b I have no clue what it does! :oops:

Can anyone explain it (generally) to me ? Thanks in advance! ;)

Clootie
15-02-2003, 05:42 PM
Straight from Borland docs:
Default8087CW is the value to which the Floating Point Unit (FPU) control register is set. The FPU control word includes bits that control the FPU's precision, rounding mode, and whether exceptions generate signals if they occur.
So this:Set8087CW($133f); { Disable all fpu exceptions }Disables all FP-coprocessor exceptions. By default in Delphi/C++Builder: InvalidOp, ZeroDivide, Overflow exceptions are enabled and RAISED in BAD CODE!!!

TheLion
15-02-2003, 06:39 PM
Thanks! ;)

I read the help file on it, but could never quite figure out what errors it suppressed! :) Thanks again!

Sly
16-02-2003, 11:21 PM
Microsoft Visual C++ masks (disables) FPU exceptions by default. Direct3D and OpenGL raise quite a few FPU exceptions during normal operation, usually divide by zero. Borland does not normally mask these FPU exceptions, so any Direct3D or OpenGL code you see for Delphi or C++ Builder will usually include that call to Set8087CW to set this exception mask.

Clootie
17-02-2003, 12:44 PM
Borland does not normally mask these FPU exceptionsEven worse - some (old) versions of Delphi change Floating Point Control Word during normal operations. Most notable examples are Int, Frac, Round functions. So normal situations in Delphi was: you call some OpenGL/DirectX functions, later call one of the above mentioned functions - and got EXCEPTION! Becase inside these functions Delphi sets FP control word to another state and not clearing exception flags before it!

About Delphi versions:
Delphi2 - has this bag
Delphi7 - contain correct version.

I'm lazy to look at RTL source on other Delphi versions, but IIRC till Delphi 3-5 have this bug too.

Alimonster
18-02-2003, 09:22 PM
I'll piggy-back a question.

I sometimes get problems w/ Delphi 5 and OpenGL - it says that my project "raised too many consecutive exceptions." I think it only appears (intermittently) when running from the IDE, and I can continue without any problems by hitting Run again. I'm pretty sure that my code is fine - could this issue be related to the Set8087CW or does my code suck :?:

Useless Hacker
18-02-2003, 09:47 PM
... does my code suck :?:Surely a contradiction in terms? :wink: