fenv.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _FENV_H
  15. # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
  16. #endif
  17. /* $cs register number for use in kvx builtins */
  18. #define KVX_SFR_CS 4
  19. /* Each core of the Coolidge processor has a coprocessor. They share
  20. the CS register but have distinct bit-fields for their
  21. floating-point environment. This implementation synchronizes them
  22. in such a way that they cannot be managed separately. */
  23. /* Compute Status ($cs) register contains the following bit-fields for
  24. floating-point execption flags.
  25. Bit-field Condition of the IEEE 754 binary floating-point standard
  26. --------- --------------------------------------------------------
  27. IO Invalid Operation
  28. DZ Divide by Zero
  29. OV Overflow
  30. UN Underflow
  31. IN Inexact
  32. XIO Invalid Operation (coprocessor)
  33. XDZ Divide by Zero (coprocessor)
  34. XOV Overflow (coprocessor)
  35. XUN Underflow (coprocessor)
  36. XIN Inexact (coprocessor) */
  37. #define _FE_INVALID 0x02
  38. #define _FE_DIVBYZERO 0x04
  39. #define _FE_OVERFLOW 0x08
  40. #define _FE_UNDERFLOW 0x10
  41. #define _FE_INEXACT 0x20
  42. #define _FE_X_INVALID 0x0200
  43. #define _FE_X_DIVBYZERO 0x0400
  44. #define _FE_X_OVERFLOW 0x0800
  45. #define _FE_X_UNDERFLOW 0x1000
  46. #define _FE_X_INEXACT 0x2000
  47. #define FE_INVALID (_FE_INVALID | _FE_X_INVALID)
  48. #define FE_DIVBYZERO (_FE_DIVBYZERO | _FE_X_DIVBYZERO)
  49. #define FE_OVERFLOW (_FE_OVERFLOW | _FE_X_OVERFLOW)
  50. #define FE_UNDERFLOW (_FE_UNDERFLOW | _FE_X_UNDERFLOW)
  51. #define FE_INEXACT (_FE_INEXACT | _FE_X_INEXACT)
  52. #define FE_ALL_EXCEPT (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT)
  53. /* Compute Status ($cs) register contains the following bit-fields for
  54. floating-point rounding modes.
  55. Following table describes both the RM and XRM (coproc) bit-fields.
  56. Value Rounding Mode of the IEEE 754 binary floating-point standard
  57. ----- ------------------------------------------------------------
  58. 0b00 to nearest even
  59. 0b01 toward +inf
  60. 0b10 toward -inf
  61. 0b11 toward zero */
  62. #define _FE_TONEAREST 0
  63. #define _FE_UPWARD 1
  64. #define _FE_DOWNWARD 2
  65. #define _FE_TOWARDZERO 3
  66. #define _FE_X_TONEAREST 0
  67. #define _FE_X_UPWARD 1
  68. #define _FE_X_DOWNWARD 2
  69. #define _FE_X_TOWARDZERO 3
  70. #define FE_TONEAREST ((_FE_TONEAREST << 16) | (_FE_X_TONEAREST << 20))
  71. #define FE_UPWARD ((_FE_UPWARD << 16) | (_FE_X_UPWARD << 20))
  72. #define FE_DOWNWARD ((_FE_DOWNWARD << 16) | (_FE_X_DOWNWARD << 20))
  73. #define FE_TOWARDZERO ((_FE_TOWARDZERO << 16) | (_FE_X_TOWARDZERO << 20))
  74. #define FE_RND_MASK FE_TOWARDZERO
  75. /* The type representing all floating-point status flags collectively.
  76. The environment is simply a copy from the FPU related bits in the
  77. CS register, but can be improved in the future. */
  78. typedef unsigned int fexcept_t;
  79. /* The type representing the entire floating-point environment. The
  80. environment is simply a copy from the FPU related bits in the CS
  81. register. */
  82. typedef unsigned int fenv_t;
  83. extern const fenv_t __fe_dfl_env;
  84. #define FE_DFL_ENV __fe_dfl_env