FPU
Control
See Also: Error Handling
The FPU -- Floating Point Unit -- has configurable settings that allow you to control the precision of calculations, the rounding mode, and exception handling. These settings are defined as part of the IEEE 754 standard, and are implemented in today's computers at the hardware level by various PC chipmakers. This help file topic is mainly concerned with explaining how to implement these settings from uCalc FMP, and not so much with why or when to use them. For a detailed explanation of the FPU, see the IA-32 Intel Architecture Software Developer’s Manual, which is available at www.intel.com. Also consult documentation for the IEEE 754 standard. Visit www.ieee.org to find out more.
uCalc FMP keeps two separate FPU words, which are insulated one from the other. One is for uCalc FMP, and the other is for the host program. If you have another DLL component that uses a different FPU setting, this will not affect uCalc FMP or vice-versa. However, things run most efficiently if uCalc's FPU word is the same as that of your host program.
If you mask a particular exception, then instead of raising an error when this exception is encountered, a special value will be used. For instance, if the division by 0 exception is masked (with uc_FPU_Mask_ZeroDivide), then 1/0 would return Inf, instead of raising a Divison by 0 error.
Here is the list of uCalc FPU commands:
uc_SetFPU
uc_SetFPU_HostProg
uc_GetFPU
uc_GetFPU_HostProg
uc_ToggleFPU
uc_ToggleFPU_HostProg
Here is the list of FPU Control word settings:
uc_FPU_Mask_InvalidOp
uc_FPU_Mask_DenormalOp
uc_FPU_Mask_ZeroDivide
uc_FPU_Mask_Overflow
uc_FPU_Mask_Underflow
uc_FPU_Mask_PrecisionLoss
uc_FPU_Precision_Single
uc_FPU_Precision_Double
uc_FPU_Precision_Extended
uc_FPU_Round_Even
uc_FPU_Round_Down
uc_FPU_Round_Up
uc_FPU_Round_Toward
If you wanted to toggle the Division by 0 bit for instance, you'd do it like this:
uCalc(uc_ToggleFPU, 0, uc_FPU_Mask_ZeroDivide)
where the first argument is a command, the second argument is always 0, and the third argument is the particular setting you want to toggle. If you wanted to set multiple bits instead of toggling just one, then you would add them together, like this (using uc_SetFPU instead of uc_ToggleFPU):
uCalc(ucSetFPU, 0, uc_FPU_Mask_PrecisionLoss +
uc_FPU_Precision_Extended + uc_FPU_Round_Even)
The default start-up FPU setting is arbitrarily configured as follows:
uc_FPU_Mask_InvalidOp
+ uc_FPU_Mask_DenormalOp
+ uc_FPU_Mask_ZeroDivide
+ uc_FPU_Mask_Overflow
+ uc_FPU_Mask_Underflow
+ uc_FPU_Mask_PrecisionLoss
+ uc_FPU_Precision_Extended