fpu_control.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* FPU control word bits. RISC-V version.
  2. Copyright (C) 1996-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. #include <features.h>
  18. #ifndef __riscv_flen
  19. # define _FPU_RESERVED 0xffffffff
  20. # define _FPU_DEFAULT 0x00000000
  21. typedef unsigned int fpu_control_t;
  22. # define _FPU_GETCW(cw) (cw) = 0
  23. # define _FPU_SETCW(cw) (void) (cw)
  24. extern fpu_control_t __fpu_control;
  25. #else /* __riscv_flen */
  26. # define _FPU_RESERVED 0
  27. # define _FPU_DEFAULT 0
  28. # define _FPU_IEEE _FPU_DEFAULT
  29. /* Type of the control word. */
  30. typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
  31. /* Macros for accessing the hardware control word. */
  32. # define _FPU_GETCW(cw) __asm__ volatile ("frsr %0" : "=r" (cw))
  33. # define _FPU_SETCW(cw) __asm__ volatile ("fssr %z0" : : "rJ" (cw))
  34. /* Default control word set at startup. */
  35. extern fpu_control_t __fpu_control;
  36. # define _FCLASS(x) (__extension__ ({ int __res; \
  37. if (sizeof (x) * 8 > __riscv_flen) __builtin_trap (); \
  38. if (sizeof (x) == 4) asm ("fclass.s %0, %1" : "=r" (__res) : "f" (x)); \
  39. else if (sizeof (x) == 8) asm ("fclass.d %0, %1" : "=r" (__res) : "f" (x)); \
  40. else __builtin_trap (); \
  41. __res; }))
  42. # define _FCLASS_MINF (1 << 0)
  43. # define _FCLASS_MNORM (1 << 1)
  44. # define _FCLASS_MSUBNORM (1 << 2)
  45. # define _FCLASS_MZERO (1 << 3)
  46. # define _FCLASS_PZERO (1 << 4)
  47. # define _FCLASS_PSUBNORM (1 << 5)
  48. # define _FCLASS_PNORM (1 << 6)
  49. # define _FCLASS_PINF (1 << 7)
  50. # define _FCLASS_SNAN (1 << 8)
  51. # define _FCLASS_QNAN (1 << 9)
  52. # define _FCLASS_ZERO (_FCLASS_MZERO | _FCLASS_PZERO)
  53. # define _FCLASS_SUBNORM (_FCLASS_MSUBNORM | _FCLASS_PSUBNORM)
  54. # define _FCLASS_NORM (_FCLASS_MNORM | _FCLASS_PNORM)
  55. # define _FCLASS_INF (_FCLASS_MINF | _FCLASS_PINF)
  56. # define _FCLASS_NAN (_FCLASS_SNAN | _FCLASS_QNAN)
  57. #endif /* __riscv_flen */
  58. #endif /* fpu_control.h */