XL Fortran provides several procedures that allow you to query and control the floating-point status and control register of the processor directly. These procedures are more efficient than the fpgets and fpsets subroutines because they are mapped into inlined machine instructions that manipulate the floating-point status and control register (fpscr) directly.
XL Fortran supplies the module xlf_fp_util, which contains the interfaces and data type definitions for these procedures and the definitions for the named constants that are needed by the procedures. This module enables type checking of these procedures at compile time rather than at link time. You can use the argument names listed in the examples as the names for keyword arguments when calling a procedure. The following files are supplied for the xlf_fp_util module:
File names | File type | Locations |
---|---|---|
xlf_fp_util.mod | module symbol file |
|
To use these procedures, you must add a USE XLF_FP_UTIL statement to your source file. For more information on USE, see USE.
If there are name conflicts (for example if the accessing subprogram has an entity with the same name as a module entity), use the ONLY clause or the renaming features of the USE statement. For example,
USE XLF_FP_UTIL, NULL1 => get_fpscr, NULL2 => set_fpscr
When compiling with the -U option, you must code the names of these procedures in all lowercase. We will show the names in lowercase here as a reminder.
The fpscr procedures are:
The following table lists the constants that are used with the fpscr procedures:
This section lists the efficient floating-point control and inquiry procedures in the XLF_FP_UTIL intrinsic module.
The clr_fpscr_flags subroutine clears the floating-point status and control register flags you specify in the MASK argument. Flags that you do not specify in MASK remain unaffected. MASK must be of type INTEGER(FPSCR_KIND). You can manipulate the MASK using the intrinsic procedures described in Integer bit model.
For more information on the FPSCR constants, see FPSCR constants.
USE, INTRINSIC :: XLF_FP_UTIL INTEGER(FPSCR_KIND) MASK ! Clear the overflow and underflow exception flags MASK=(IOR(FP_OVERFLOW,FP_UNDERFLOW)) CALL clr_fpscr_flags(MASK)
For another example of the clr_fpscr_flags subroutine, see get_fpscr_flags.
The get_fpscr function returns the current value of the floating-point status and control register (fpscr) of the processor.
INTEGER(FPSCR_KIND)
The current value of the floating-point status and control register (FPSCR) of the processor.
USE, INTRINSIC :: XLF_FP_UTIL INTEGER(FPSCR_KIND) FPSCR FPSCR=get_fpscr()
The get_fpscr_flags function returns the current state of the floating-point status and control register flags you specify in the MASK argument. MASK must be of type INTEGER(FPSCR_KIND). You can manipulate the MASK using the intrinsics described in Integer bit model.
For more information on the FPSCR constants, see FPSCR constants.
An INTEGER(FPSCR_KIND)
The status of the FPSCR flags specified by the MASK argument. If a flag specified in the MASK argument is on, the value for the flag will be returned in the return value. The following example requests the status of the FP_DIV_BY_ZERO and FP_INVALID flags.
USE, INTRINSIC :: XLF_FP_UTIL ! ... IF (get_fpscr_flags(IOR(FP_DIV_BY_ZERO,FP_INVALID)) .NE. 0) THEN ! Either Divide-by-zero or an invalid operation occurred. ! ... ! After processing the exception, the exception flags are ! cleared. CALL clr_fpscr_flags(IOR(FP_DIV_BY_ZERO,FP_INVALID)) END IF
The get_round_mode function returns the current floating-point rounding mode. The return value will be one of the constants FP_RND_RN, FP_RND_RZ, FP_RND_RP or FP_RND_RM. For more information on the rounding mode constants, see FPSCR constants.
An INTEGER(FPSCR_KIND)
One of the constants FP_RND_RN, FP_RND_RZ, FP_RND_RP or FP_RND_RM.
USE, INTRINSIC :: XLF_FP_UTIL INTEGER(FPSCR_KIND) MODE MODE=get_round_mode() IF (MODE .EQ. FP_RND_RZ) THEN ! ... END IF
The set_fpscr function sets the floating-point status and control register (fpscr) of the processor to the value provided in the FPSCR argument, and returns the value of the register before the change.
An INTEGER(FPSCR_KIND)
An INTEGER(FPSCR_KIND).
The value of the register before it was set with set_fpscr.
USE, INTRINSIC :: XLF_FP_UTIL INTEGER(FPSCR_KIND) FPSCR, OLD_FPSCR FPSCR=get_fpscr() ! ... Some changes are made to FPSCR ... OLD_FPSCR=set_fpscr(FPSCR) ! OLD_FPSCR is assigned the value of ! the register before it was ! set with set_fpscr
The set_fpscr_flags subroutine allows you to set the floating-point status and control register flags you specify in the MASK argument. Flags that you do not specify in MASK remain unaffected. MASK must be of type INTEGER(FPSCR_KIND). You can manipulate the MASK using the intrinsics described in Integer bit model.
For more information on the FPSCR constants, see FPSCR constants.
The set_round_mode function sets the current floating-point rounding mode, and returns the rounding mode before the change. You can set the mode to FP_RND_RN, FP_RND_RZ, FP_RND_RP or FP_RND_RM. For more information on the rounding mode constants, see FPSCR constants.
Integer of kind FPSCR_KIND
Integer of kind FPSCR_KIND
The rounding mode before the change.
USE XLF_FP_UTIL INTEGER(FPSCR_KIND) MODE MODE=set_round_mode(FP_RND_RZ) ! The rounding mode is set to ! round towards zero. MODE is ! ... ! assigned the previous rounding ! mode. MODE=set_round_mode(MODE) ! The rounding mode is restored.