5.3.2. The __fp_status function

Previous versions of the ARM libraries implemented a function called __fp_status, that manipulated a status word in the floating-point environment. ARM still supports this function, for backwards compatibility. It is defined in stdlib.h.

__fp_status has the following prototype:

unsigned int __fp_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 (Table 5.6).

Table 5.6. Status word bit modification

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

The layout of the status word as seen by __fp_status is shown in Figure 5.2.

Figure 5.2. Floating-point status word layout

The fields in Figure 5.2 are as follows:

The rounding mode cannot be changed with the __fp_status call.

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

#define __fpsr_IXE  0x100000
#define __fpsr_UFE  0x80000
#define __fpsr_OFE  0x40000
#define __fpsr_DZE  0x20000
#define __fpsr_IOE  0x10000
#define __fpsr_IXC  0x10
#define __fpsr_UFC  0x8
#define __fpsr_OFC  0x4
#define __fpsr_DZC  0x2
#define __fpsr_IOC  0x1

For example, to trap the Invalid Operation exception and untrap all other exceptions, you would do:

__fp_status(_fpsr_IXE | _fpsr_UFE | _fpsr_OFE |
            _fpsr_DZE | _fpsr_IOE, _fpsr_IOE);

To untrap the Inexact Result exception:

__fp_status(_fpsr_IXE, 0);

To clear the Underflow sticky flag:

__fp_status(_fpsr_UFC, 0);
Copyright © 1999-2001 ARM Limited. All rights reserved.ARM DUI 0067D