Keil Logo

__fp_status()

5.3 __fp_status()

The ARM® Compiler toolchain supports an interface to the status word in the floating-point environment. Some older versions of the ARM libraries implemented a function called __fp_status() to provide this interface.

__fp_status() is the same as __ieee_status() but it uses an older style of status word layout. The compiler still supports the __fp_status() function for backwards compatibility. __fp_status() is defined in stdlib.h.
The function prototype for __fp_status() is:
unsigned int __fp_status(unsigned int mask, unsigned int flags);

Note

This function requires you to select a floating-point model that supports exceptions. For example, --fpmode=ieee_full or --fpmode=ieee_fixed.
The layout of the status word as seen by __fp_status() is as follows:
Figure 5-1 Floating-point status word layout
Floating-point status word layout

The fields in the status word are as follows:
  • Bits 0 to 4 (values 0x1 to 0x10, respectively) are the sticky flags, or cumulative flags, for each exception. The sticky flag for an exception is set to 1 whenever that exception happens and is not trapped. Sticky flags are never cleared by the system, only by the user. The mapping of exceptions to bits is:
    • Bit 0 (0x01) is for the Invalid Operation exception
    • Bit 1 (0x02) is for the Divide by Zero exception.
    • Bit 2 (0x04) is for the Overflow exception.
    • Bit 3 (0x08) is for the Underflow exception.
    • Bit 4 (0x10) is for the Inexact Result exception.
  • Bits 8 to 12 (values 0x100 to 0x1000) control various aspects of the Floating-Point Architecture (FPA). The FPA is obsolete and the ARM compilation tools do not support it. Any attempt to write to these bits is ignored.
  • Bits 16 to 20 (values 0x10000 to 0x100000) are the exception masks. These control whether each exception is trapped or not. If a bit is set to 1, the corresponding exception is trapped. If a bit is set to 0, the corresponding exception sets its sticky flag and returns a plausible result.
  • Bits 24 to 31 contain the system ID that cannot be changed. It is set to 0x40 for software floating-point, to 0x80 or above for hardware floating-point, and to 0 or 1 if a hardware floating-point environment is being faked by an emulator.
  • Bits marked R are reserved. They cannot be written to by the __fp_status() call, and you must ignore anything you find in them.
The rounding mode cannot be changed with the __fp_status() call.
In addition to defining the __fp_status() call itself, stdlib.h also defines the following 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 call __fp_status() with the following input parameters:
__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);
Related reference
Related information
Non-ConfidentialPDF file icon PDF versionARM DUI0378H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.