1  /* Copyright (C) 1997-2023 Free Software Foundation, Inc.
       2     This file is part of the GNU C Library.
       3  
       4     The GNU C Library is free software; you can redistribute it and/or
       5     modify it under the terms of the GNU Lesser General Public
       6     License as published by the Free Software Foundation; either
       7     version 2.1 of the License, or (at your option) any later version.
       8  
       9     The GNU C Library is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12     Lesser General Public License for more details.
      13  
      14     You should have received a copy of the GNU Lesser General Public
      15     License along with the GNU C Library.  If not, see
      16     <https://www.gnu.org/licenses/>.  */
      17  
      18  #ifndef _FENV_H
      19  # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
      20  #endif
      21  
      22  
      23  /* Define the bits representing the exception.
      24  
      25     Note that these are the bit positions as defined by the OSF/1
      26     ieee_{get,set}_control_word interface and not by the hardware fpcr.
      27  
      28     See the Alpha Architecture Handbook section 4.7.7.3 for details,
      29     but in summary, trap shadows mean the hardware register can acquire
      30     extra exception bits so for proper IEEE support the tracking has to
      31     be done in software -- in this case with kernel support.
      32  
      33     As to why the system call interface isn't in the same format as
      34     the hardware register, only those crazy folks at DEC can tell you.  */
      35  
      36  enum
      37    {
      38  #ifdef __USE_GNU
      39      FE_DENORMAL =
      40  #define FE_DENORMAL	(1 << 22)
      41        FE_DENORMAL,
      42  #endif
      43  
      44      FE_INEXACT =
      45  #define FE_INEXACT	(1 << 21)
      46        FE_INEXACT,
      47  
      48      FE_UNDERFLOW =
      49  #define FE_UNDERFLOW	(1 << 20)
      50        FE_UNDERFLOW,
      51  
      52      FE_OVERFLOW =
      53  #define FE_OVERFLOW	(1 << 19)
      54        FE_OVERFLOW,
      55  
      56      FE_DIVBYZERO =
      57  #define FE_DIVBYZERO	(1 << 18)
      58        FE_DIVBYZERO,
      59  
      60      FE_INVALID =
      61  #define FE_INVALID	(1 << 17)
      62        FE_INVALID,
      63  
      64      FE_ALL_EXCEPT =
      65  #define FE_ALL_EXCEPT	(0x3f << 17)
      66        FE_ALL_EXCEPT
      67    };
      68  
      69  /* Alpha chips support all four defined rounding modes.
      70  
      71     Note that code must be compiled to use dynamic rounding (/d) instructions
      72     to see these changes.  For gcc this is -mfp-rounding-mode=d; for DEC cc
      73     this is -fprm d.  The default for both is static rounding to nearest.
      74  
      75     These are shifted down 58 bits from the hardware fpcr because the
      76     functions are declared to take integers.  */
      77  
      78  enum
      79    {
      80      FE_TOWARDZERO =
      81  #define FE_TOWARDZERO	0
      82        FE_TOWARDZERO,
      83  
      84      FE_DOWNWARD =
      85  #define FE_DOWNWARD	1
      86        FE_DOWNWARD,
      87  
      88      FE_TONEAREST =
      89  #define FE_TONEAREST	2
      90        FE_TONEAREST,
      91  
      92      FE_UPWARD =
      93  #define FE_UPWARD	3
      94        FE_UPWARD,
      95    };
      96  
      97  #ifdef __USE_GNU
      98  /* On later hardware, and later kernels for earlier hardware, we can forcibly
      99     underflow denormal inputs and outputs.  This can speed up certain programs
     100     significantly, usually without affecting accuracy.  */
     101  enum
     102    {
     103      FE_MAP_DMZ =	1UL << 12,	/* Map denorm inputs to zero */
     104  #define FE_MAP_DMZ	FE_MAP_DMZ
     105  
     106      FE_MAP_UMZ =	1UL << 13,	/* Map underflowed outputs to zero */
     107  #define FE_MAP_UMZ	FE_MAP_UMZ
     108    };
     109  #endif
     110  
     111  /* Type representing exception flags.  */
     112  typedef unsigned long int fexcept_t;
     113  
     114  /* Type representing floating-point environment.  */
     115  typedef unsigned long int fenv_t;
     116  
     117  /* If the default argument is used we use this value.  Note that due to
     118     architecture-specified page mappings, no user-space pointer will ever
     119     have its two high bits set.  Co-opt one.  */
     120  #define FE_DFL_ENV	((const fenv_t *) 0x8800000000000000UL)
     121  
     122  #ifdef __USE_GNU
     123  /* Floating-point environment where none of the exceptions are masked.  */
     124  # define FE_NOMASK_ENV	((const fenv_t *) 0x880000000000003eUL)
     125  
     126  /* Floating-point environment with (processor-dependent) non-IEEE floating
     127     point.  In this case, mapping denormals to zero.  */
     128  # define FE_NONIEEE_ENV ((const fenv_t *) 0x8800000000003000UL)
     129  #endif
     130  
     131  /* The system calls to talk to the kernel's FP code.  */
     132  extern unsigned long int __ieee_get_fp_control (void) __THROW;
     133  extern void __ieee_set_fp_control (unsigned long int __value) __THROW;
     134  
     135  #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
     136  /* Type representing floating-point control modes.  */
     137  typedef unsigned long int femode_t;
     138  
     139  /* Default floating-point control modes.  */
     140  # define FE_DFL_MODE	((const femode_t *) 0x8800000000000000UL)
     141  #endif