4.2.1. __ieee_status()

RVCT supports an interface to the status word in the floating-point environment. This is called __ieee_status and it is generally the most efficient function to use for modifying the status word for VFP. __ieee_status is defined in fenv.h.

__ieee_status has the prototype:

unsigned int __ieee_status(unsigned int mask,
                           unsigned int flags);

The function modifies the writable parts of the status word according to the parameters, and returns the previous value of the whole word.

The writable bits are modified by setting them to

new = (old & ~mask) ^ flags;

Four different operations can be performed on each bit of the status word, depending on the corresponding bits in mask and flags (see Table 4.6).

Table 4.6. Status word bit modification

Bit of maskBit of flagsEffect
00Leave alone
01Toggle
10Set to 0
11Set to 1

The layout of the status word as seen by __ieee_status is shown in Figure 4.1.

Figure 4.1. IEEE status word layout

IEEE status word layout

The fields in Figure 4.1 are as follows:

In addition to defining the __ieee_status call itself, fenv.h also defines some constants to be used for the arguments:

#define FE_IEEE_FLUSHZERO          (0x01000000)
#define FE_IEEE_ROUND_TONEAREST    (0x00000000)
#define FE_IEEE_ROUND_UPWARD       (0x00400000)
#define FE_IEEE_ROUND_DOWNWARD     (0x00800000)
#define FE_IEEE_ROUND_TOWARDZERO   (0x00C00000)
#define FE_IEEE_ROUND_MASK         (0x00C00000)
#define FE_IEEE_MASK_INVALID       (0x00000100)
#define FE_IEEE_MASK_DIVBYZERO     (0x00000200)
#define FE_IEEE_MASK_OVERFLOW      (0x00000400)
#define FE_IEEE_MASK_UNDERFLOW     (0x00000800)
#define FE_IEEE_MASK_INEXACT       (0x00001000)
#define FE_IEEE_MASK_ALL_EXCEPT    (0x00001F00)
#define FE_IEEE_INVALID            (0x00000001)
#define FE_IEEE_DIVBYZERO          (0x00000002)
#define FE_IEEE_OVERFLOW           (0x00000004)
#define FE_IEEE_UNDERFLOW          (0x00000008)
#define FE_IEEE_INEXACT            (0x00000010)
#define FE_IEEE_ALL_EXCEPT         (0x0000001F)

For example, to set the rounding mode to round down, you would do:

__ieee_status(FE_IEEE_ROUND_MASK, FE_IEEE_ROUND_DOWNWARD);

To trap the Invalid Operation exception and untrap all other exceptions:

__ieee_status(FE_IEEE_MASK_ALL_EXCEPT, FE_IEEE_MASK_INVALID);

To untrap the Inexact Result exception:

__ieee_status(FE_IEEE_MASK_INEXACT, 0);

To clear the Underflow sticky flag:

__ieee_status(FE_IEEE_UNDERFLOW, 0);
Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0349A
Non-Confidential