fenv.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (c) 2017 SiFive Inc. All rights reserved.
  2. This copyrighted material is made available to anyone wishing to use,
  3. modify, copy, or redistribute it subject to the terms and conditions
  4. of the FreeBSD License. This program is distributed in the hope that
  5. it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
  6. including the implied warranties of MERCHANTABILITY or FITNESS FOR
  7. A PARTICULAR PURPOSE. A copy of this license is available at
  8. http://www.opensource.org/licenses.
  9. */
  10. #ifndef _FENV_H_
  11. #define _FENV_H_
  12. #include <stddef.h>
  13. /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA:
  14. * Version 2.1", Section 8.2, "Floating-Point Control and Status
  15. * Register":
  16. *
  17. * Flag Mnemonic Flag Meaning
  18. * ------------- -----------------
  19. * NV Invalid Operation
  20. * DZ Divide by Zero
  21. * OF Overflow
  22. * UF Underflow
  23. * NX Inexact
  24. */
  25. #define FE_INVALID 0x00000010
  26. #define FE_DIVBYZERO 0x00000008
  27. #define FE_OVERFLOW 0x00000004
  28. #define FE_UNDERFLOW 0x00000002
  29. #define FE_INEXACT 0x00000001
  30. #define FE_ALL_EXCEPT (FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT)
  31. /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA:
  32. * Version 2.1", Section 8.2, "Floating-Point Control and Status
  33. * Register":
  34. *
  35. * Rounding Mode Mnemonic Meaning Meaning
  36. * ------------- ---------------- -------
  37. * 000 RNE Round to Nearest, ties to Even
  38. * 001 RTZ Round towards Zero
  39. * 010 RDN Round Down (towards −∞)
  40. * 011 RUP Round Up (towards +∞)
  41. * 100 RMM Round to Nearest, ties to Max Magnitude
  42. * 101 Invalid. Reserved for future use.
  43. * 110 Invalid. Reserved for future use.
  44. * 111 In instruction’s rm field, selects dynamic rounding mode;
  45. * In Rounding Mode register, Invalid
  46. */
  47. #define FE_TONEAREST_MM 0x00000004
  48. #define FE_UPWARD 0x00000003
  49. #define FE_DOWNWARD 0x00000002
  50. #define FE_TOWARDZERO 0x00000001
  51. #define FE_TONEAREST 0x00000000
  52. #define FE_RMODE_MASK 0x7
  53. /* Per "The RISC-V Instruction Set Manual: Volume I: User-Level ISA:
  54. * Version 2.1":
  55. *
  56. * "The F extension adds 32 floating-point registers, f0–f31, each 32
  57. * bits wide, and a floating-point control and status register fcsr,
  58. * which contains the operating mode and exception status of the
  59. * floating-point unit."
  60. */
  61. typedef size_t fenv_t;
  62. typedef size_t fexcept_t;
  63. extern const fenv_t fe_dfl_env;
  64. #define FE_DFL_ENV fe_dfl_env_p
  65. #endif /* _FENV_H_ */