Pragma equivalent
#pragma
options [no]flttrap
Purpose
Determines the types of floating-point exception
conditions to be detected at run time
Syntax
.-noflttrap------------------------------.
>>- -q--+-flttrap--+---------------------------+-+-------------><
| .-:------------------. |
| | .-zero-------. | |
| | +-zerodivide-+ | |
| | +-und--------+ | |
| | +-underflow--+ | |
| | +-ov---------+ | |
| | +-overflow---+ | |
| | +-inv--------+ | |
| | +-invalid----+ | |
| | +-inex-------+ | |
| V +-inexact----+ | |
'-=------+-enable-----+---+-'
+-en---------+
+-imprecise--+
+-imp--------+
'-nanq-------'
Parameters
- enable, en
- Enables trapping when the specified exceptions (overflow, underflow, zerodivide, invalid,
or inexact) occur. You must specify this suboption if you want
to turn on exception trapping without modifying your source code.
If any of the specified exceptions occur, a SIGTRAP or SIGFPE signal
is sent to the process with the precise location of the exception. If imprecise is in effect, traps will not
report exactly where the exception occurred.
- imprecise, imp
- Enables imprecise detection of the specified exceptions. The compiler
generates instructions after a block of code and just before the main program
returns, to check if any of the specified exceptions (overflow, underflow, zerodivide, invalid,
or inexact) have occurred. If an exception has occurred, an
exception status flag is set in the Floating-Point Status and Control
Register, but the exact location of the exception is not determined.
Because instructions are not generated after each floating-point operation
and function call to check for exceptions, this suboption can result
in a slight performance improvement.
- inexact, inex
- Enables the detection of floating-point inexact operations. If imprecise is not also specified, the compiler
generates instructions after each floating-point operation and function
call to check if an inexact operation exception has occurred. If
a floating-point inexact operation occurs, an inexact operation exception
status flag is set in the Floating-Point Status and Control Register
(FPSCR).
- invalid, inv
- Enables the detection of floating-point invalid operations. If imprecise is not also specified, the compiler
generates instructions after each floating-point operation and function
call to check if an invalid operation exception has occurred. If
a floating-point invalid operation occurs, an invalid operation exception
status flag is set in the FPSCR.
- nanq
- Generates code to detect NaNQ (Not a Number Quiet) and NaNS (Not
a Number Signalling) exceptions before and after each floating point
operation, including assignment, and after each call to a function
returning a floating-point result to trap if the value is a NaN. Trapping
code is generated regardless of whether the enable suboption
is specified.
- overflow, ov
- Enables the detection of floating-point overflow.If imprecise is
not also specified, the compiler generates instructions after each
floating-point operation and function call to check if an overflow
exception has occurred. If a floating-point overflow occurs,
an overflow exception status flag is set in the FPSCR.
- underflow, und
- Enables the detection of floating-point underflow. If imprecise is not also specified, the compiler
generates instructions after each floating-point operation and function
call to check if an underflow exception has occurred. If a floating-point
underflow occurs, an underflow exception status flag is set in the
FPSCR.
- zerodivide, zero
- Enables the detection of floating-point division by zero. If imprecise is not also specified, the compiler
generates instructions after each floating-point operation and function
call to check if a zero-divide exception has occurred. If a floating-point
zero-divide occurs, a zero-divide exception status flag is set in
the FPSCR.
Specifying
-qflttrap option with no suboptions
is equivalent to
-qflttrap=overflow : underflow : zerodivide :
invalid : inexact. Exceptions will be detected by the hardware,
but trapping is not enabled. Because this default does not include
enable,
it is probably only useful if you already use
fpsets or
similar subroutines in your source.
Usage
It is recommended
that you use the enable suboption whenever compiling the main program
with -qflttrap. This ensures that the compiler will generate
the code to automatically enable floating-point exception trapping,
without requiring that you include calls to the appropriate floating-point
exception library functions in your code.
If you specify -qflttrap more
than once, both with and without suboptions, the -qflttrap without
suboptions is ignored.
This option is recognized during linking
with IPA. Specifying the option at the link step overrides the compile-time
setting.
If your program contains signalling NaNs, you should
use the -qfloat=nans option along with -qflttrap to
trap any exceptions.
The compiler exhibits behavior as illustrated
in the following examples when the -qflttrap option is specified
together with an optimization option:
- with -O2:
- 1/0 generates a div0 exception and has a result of infinity
- 0/0 generates an invalid operation
- with -O3 or greater:
- 1/0 generates a div0 exception and has a result of infinity
- 0/0 returns zero multiplied by the result of the previous division.
If you use
-qflttrap=inv:en to compile
a program containing an IEEE invalid SQRT operation and you specify
a
-qarch target that does not implement the
sqrt instruction
set, the expected SIGTRAP signal will not occur when you run the program.
You can fix this problem by specifying the following command before
running the program:
export SQRT_EXCEPTION=3.1
Note: Due to the transformations performed and the
exception handling support of some vector instructions, use of -qsimd=auto may
change the location where an exception is caught or even cause the
compiler to miss catching an exception.
Examples
When you compile this program:
#include <stdio.h>
int main()
{
float x, y, z;
x = 5.0;
y = 0.0;
z = x / y;
printf("%f", z);
}
with the command:
xlc -qflttrap=zerodivide:enable divide_by_zero.c
the
program stops when the division is performed.
The zerodivide suboption
identifies the type of exception to guard against. The enable suboption
causes a SIGTRAP or SIGFPE signal to be generated when the exception
occurs.