fpu_control.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* FPU control word bits. OpenRISC version.
  2. Copyright (C) 2024-2025 Free Software Foundation, Inc.
  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. <https://www.gnu.org/licenses/>. */
  14. #ifndef _FPU_CONTROL_H
  15. #define _FPU_CONTROL_H
  16. #ifndef __or1k_hard_float__
  17. # define _FPU_RESERVED 0xffffffff
  18. # define _FPU_DEFAULT 0x00000000
  19. # define _FPU_GETCW(cw) (cw) = 0
  20. # define _FPU_SETCW(cw) (void) (cw)
  21. #else /* __or1k_hard_float__ */
  22. /* Layout of FPCSR:
  23. The bits of the FPCSR are defined as follows, this should help
  24. explain how the masks below have come to be.
  25. +-----------+----------------------------+-----+----+
  26. | 32 - 12 | 11 10 9 8 7 6 5 4 3 | 2-1 | 0 |
  27. +-----------+----------------------------+-----+----+
  28. | Reserved | DZ IN IV IX Z QN SN UN OV | RM | EE |
  29. +-----------+----------------------------+-----+----+
  30. Exception flags:
  31. DZ - divide by zero flag.
  32. IN - infinite flag.
  33. IV - invalid flag.
  34. IX - inexact flag.
  35. Z - zero flag.
  36. QN - qnan flag.
  37. SN - snan flag.
  38. UN - underflow flag.
  39. OV - overflow flag.
  40. Rounding modes:
  41. The FPCSR bits 2-1 labeled above as RM specify the rounding mode.
  42. 00 - round to nearest
  43. 01 - round to zero
  44. 10 - round to positive infinity
  45. 11 - round to negative infinity
  46. Enabling exceptions:
  47. EE - set to enable FPU exceptions.
  48. */
  49. # define _FPU_RESERVED 0xfffff000
  50. /* Default: rounding to nearest with exceptions disabled. */
  51. # define _FPU_DEFAULT 0
  52. /* IEEE: Same as above with exceptions enabled. */
  53. # define _FPU_IEEE (_FPU_DEFAULT | 1)
  54. # define _FPU_FPCSR_RM_MASK (0x3 << 1)
  55. /* Macros for accessing the hardware control word. */
  56. # define _FPU_GETCW(cw) __asm__ volatile ("l.mfspr %0,r0,20" : "=r" (cw))
  57. # define _FPU_SETCW(cw) __asm__ volatile ("l.mtspr r0,%0,20" : : "r" (cw))
  58. #endif /* __or1k_hard_float__ */
  59. /* Type of the control word. */
  60. typedef unsigned int fpu_control_t;
  61. /* Default control word set at startup. */
  62. extern fpu_control_t __fpu_control;
  63. #endif /* fpu_control.h */