fpu_control.h 2.6 KB

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