RAD Studio (Common)
ContentsIndex
PreviousUpNext
Pentium-safe FDIV operations (Delphi)
Type  
Switch  
Syntax  
{$U+} or {$U-} {$SAFEDIVIDE ON} or {$SAFEDIVIDE OFF}  
Default  
{$U-}  
Scope  
Local  

The $U directive controls generation of floating-point code that guards against the flawed FDIV instruction exhibited by certain early Pentium processors. Windows 95, Windows NT 3.51, and later contain code which corrects the Pentium FDIV bug system-wide. 

In the {$U+} state, all floating-point divisions are performed using a runtime library routine. The first time the floating-point division routine is invoked, it checks whether the processor's FDIV instruction works correctly, and updates the TestFDIV variable (declared in the System unit) accordingly. For subsequent floating-point divide operations, the value stored in TestFDIV is used to determine what action to take. 

Value Meaning 

-1 FDIV instruction has been tested and found to be flawed. 

0 FDIV instruction has not yet been tested. 

1 FDIV instruction has been tested and found to be correct. 

For processors that do not exhibit the FDIV flaw, {$U+} results in only a slight performance degradation. For a flawed Pentium processor, floating-point divide operations may take up to three times longer in the {$U+} state, but they will always produce correct results. 

In the {$U-} state, floating-point divide operations are performed using in-line FDIV instructions. This results in optimum speed and code size, but may produce incorrect results on flawed Pentium processors. You should use the {$U-} state only in cases where you are certain that the code is not running on a flawed Pentium processor.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!