Index: clang/docs/UsersManual.rst =================================================================== --- clang/docs/UsersManual.rst +++ clang/docs/UsersManual.rst @@ -1128,6 +1128,128 @@ and the precompiled header cannot be generated after headers have been installed. +.. _controlling-fp-behavior: + +Controlling Floating Point Behavior +--------------------------- + +Clang provides a number of ways to control floating point behavior. The options +are listed below. + +.. option:: -ffast-math + + Enable fast-math mode. This defines the ``__FAST_MATH__`` preprocessor + macro, and lets the compiler make aggressive, potentially-lossy assumptions + about floating-point math. These include: + + * Floating-point math obeys regular algebraic rules for real numbers (e.g. + ``+`` and ``*`` are associative, ``x/y == x * (1/y)``, and + ``(a + b) * c == a * c + b * c``), + * operands to floating-point operations are not equal to ``NaN`` and + ``Inf``, and + * ``+0`` and ``-0`` are interchangeable. + + This option implies: + + * ``-fno-honor-inf`` + + * ``-fno-honor-nan`` + + * ``-fno-math-errno`` + + * ``-fassociative-math`` + + * ``-freciprocal-math`` + + * ``-fno-signed-zeros`` + + * ``-fno-trapping-math`` + + * ``-ffp-constract=fast`` + +.. option:: -fdenormal-fp-math= + + Select which denormal numbers the code is permitted to require. + + Valid values are: + + * ``ieee`` -IEEE 754 denormal numbers + * ``preserve-sign`` - the sign of a flushed-to-zero number is preserved in the sign of 0 + * ``positive-zero`` - denormals are flushed to positive zero + + Defaults to ``ieee``. + +.. option:: -f[no-]strict-float-cast-overflow + + When a floating-point value is not representable in a destination integer + type, the code has undefined behavior according to the language standard. + By default, Clang will not guarantee any particular result in that case. + With the 'no-strict' option, Clang attempts to match the overflowing behavior + of the target's native float-to-int conversion instructions. + +.. option:: -f[no-]math-errno + + Require math functions to indicate errors by setting errno. \ + The default varies by ToolChain. + +.. option:: -f[no-]trapping-math + + ``-fno-trapping-math`` allows optimizations that assume that + floating point operations cannot generate traps such as divide-by-zero, + overflow and underflow. Defaults to ``-ftrapping-math``. + +.. option:: -ffp-contract= + + Form fused floating point operations (e.g. FMAs). Valid values are: + + * ``fast`` (everywhere) + * ``on`` (according to FP_CONTRACT pragma, default) + * ``off`` (never fuse) + +.. option:: -f[no-]honor-infinities + + FIXME: This option appears to have no effect. + +.. option:: -f[no-]honor-nans + + FIXME: This option appears to have no effect. + +.. option:: -f[no-]signed-zeros + + Allow optimizations that ignore the sign of floating point zeros. + Defaults to ``-fno-signed-zeros``. + +.. option:: -f[no-]associative-math + + Allow floating point operations to be reassociated. + Defaults to ``-fno-associative-math``. + +.. option:: -f[no-]reciprocal-math + + Allow division operations to be reassociated. + Defaults to ``-fno-reciprocal-math``. + +.. option:: -f[no-]unsafe-math-optimizations + + Allow unsafe floating-point optimizations. Also implies: + + * ``-fassociative-math`` + * ``-freciprocal-math`` + * ``-fno-signed-zeroes`` + * ``-fno-trapping-math``. + + Defaults to ``-fno-unsafe-math-optimizations``. + +.. option:: -f[no-]finite-math + + Allow floating-point optimizations that assume arguments and results are + not NaNs or +-Inf. Also implies: + + * ``-fno-honor-infinities`` + * ``-fno-honor-nans`` + + Defaults to ``-fno-finite-math``. + .. _controlling-code-generation: Controlling Code Generation @@ -1266,36 +1388,6 @@ This enables better devirtualization. Turned off by default, because it is still experimental. -.. option:: -ffast-math - - Enable fast-math mode. This defines the ``__FAST_MATH__`` preprocessor - macro, and lets the compiler make aggressive, potentially-lossy assumptions - about floating-point math. These include: - - * Floating-point math obeys regular algebraic rules for real numbers (e.g. - ``+`` and ``*`` are associative, ``x/y == x * (1/y)``, and - ``(a + b) * c == a * c + b * c``), - * operands to floating-point operations are not equal to ``NaN`` and - ``Inf``, and - * ``+0`` and ``-0`` are interchangeable. - -.. option:: -fdenormal-fp-math=[values] - - Select which denormal numbers the code is permitted to require. - - Valid values are: ``ieee``, ``preserve-sign``, and ``positive-zero``, - which correspond to IEEE 754 denormal numbers, the sign of a - flushed-to-zero number is preserved in the sign of 0, denormals are - flushed to positive zero, respectively. - -.. option:: -f[no-]strict-float-cast-overflow - - When a floating-point value is not representable in a destination integer - type, the code has undefined behavior according to the language standard. - By default, Clang will not guarantee any particular result in that case. - With the 'no-strict' option, Clang attempts to match the overflowing behavior - of the target's native float-to-int conversion instructions. - .. option:: -fwhole-program-vtables Enable whole-program vtable optimizations, such as single-implementation