SSE Floating point exceptions not masked
Original Reporter info from Mantis: lennert
-
Reporter name:
Original Reporter info from Mantis: lennert
- Reporter name:
Description:
When working with SSE instructions the MXCSR control/status word is not properly initialized. The default MXCSR value at reset should be $1f80, whereas it is set to $1900 by the Lazarus runtime. The default value is a.o. specified at ftp://download.intel.com/design/PentiumII/manuals/24319102.PDF, page 3-345.
As a result the exception "External exception C00002B5." can be raised, also known as "Multiple floating point traps".
The relevant code can be found in i386.inc/x86_64.inc:
mxcsr : dword = MM_MaskUnderflow or MM_MaskPrecision or MM_MaskDenorm;
By default, all floating point exceptions should be masked by initializing mxcsr as follows:
mxcsr : dword = MM_MaskInvalidOp or MM_MaskDenorm or MM_MaskDivZero or MM_MaskOverflow or MM_MaskUnderflow or MM_MaskPrecision;
Steps to reproduce:
Create an empty project
Load a DLL that utilizes SSE instructions and branch prediction
Call a function that is exported by this DLL
Additional information:
This exception showed up when I was working with a DLL compiled by the Intel C++ compiler. My assumption is that the compiler uses branch prediction to improve speed. As a result of a misprediction a division by zero occurred and the result of the division by zero was discarded later. When the "division by zero" exception is not masked, the exception specified above shows up and execution of the program stops.
Mantis conversion info:
- Mantis ID: 16263
- Build: 22279
- Version: 2.2.4
- Fixed in version: 2.6.0
- Fixed in revision: 16347 (#c14574bb)