getfcr, setfcr, getfsr, setfsr – control floating point
void setfcr(ulong fcr)
void setfsr(ulong fsr)
These routines provide a fairly portable interface to control the
rounding and exception characteristics of IEEE 754 floating point units.
In effect, they define a pair of pseudo-registers, the floating
point control register,
which affects rounding, precision, and exceptions, and the
floating point status register,
which holds the accrued exception bits.
Each register has a
routine to retrieve its value, a
routine to modify it,
and macros that identify its contents.
contains bits that, when set, halt execution upon exceptions:
(enable inexact exceptions),
(enable overflow exceptions),
(enable underflow exceptions),
(enable zero divide exceptions), and
(enable invalid operation exceptions).
Rounding is controlled by installing in
one of the values
(round to nearest),
(round towards zero),
(round towards positive infinity), and
(round towards negative infinity).
Precision is controlled by installing in
one of the values
(single precision), and
holds the accrued exception bits
corresponding to the
bits without the
in the name.
Not all machines support all modes. If the corresponding mask
is zero, the machine does not support the rounding or precision modes.
On some machines it is not possible to clear selective accrued
exception bits; a
clears them all.
The exception bits defined here work on all architectures.
Where possible, the initial state is equivalent to
However, this may vary between architectures:
the default is to provide what the hardware does most efficiently.
Use these routines
if you need guaranteed behavior.
Also, gradual underflow is not available on some machines.
To enable overflow traps and make sure registers are rounded
to double precision (for example on the MC68020, where the
internal registers are 80 bits long):
setfcr((getfcr() & ~FPPMASK) | FPPDBL | FPOVFL);