1 /* FPU control word bits. RISC-V version.
2 Copyright (C) 1996-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _FPU_CONTROL_H
20 #define _FPU_CONTROL_H
26 # define _FPU_RESERVED 0xffffffff
27 # define _FPU_DEFAULT 0x00000000
28 typedef unsigned int fpu_control_t
;
29 # define _FPU_GETCW(cw) (cw) = 0
30 # define _FPU_SETCW(cw) do { } while (0)
31 extern fpu_control_t __fpu_control
;
33 #else /* __riscv_flen */
35 # define _FPU_RESERVED 0
36 # define _FPU_DEFAULT 0
37 # define _FPU_IEEE _FPU_DEFAULT
39 /* Type of the control word. */
40 typedef unsigned int fpu_control_t
__attribute__ ((__mode__ (__SI__
)));
42 /* Macros for accessing the hardware control word. */
43 # define _FPU_GETCW(cw) __asm__ volatile ("frsr %0" : "=r" (cw))
44 # define _FPU_SETCW(cw) __asm__ volatile ("fssr %z0" : : "rJ" (cw))
46 /* Default control word set at startup. */
47 extern fpu_control_t __fpu_control
;
49 # define _FCLASS(x) (__extension__ ({ int __res; \
50 if (sizeof (x) * 8 > __riscv_flen) __builtin_trap (); \
51 if (sizeof (x) == 4) asm ("fclass.s %0, %1" : "=r" (__res) : "f" (x)); \
52 else if (sizeof (x) == 8) asm ("fclass.d %0, %1" : "=r" (__res) : "f" (x)); \
53 else __builtin_trap (); \
56 # define _FCLASS_MINF (1 << 0)
57 # define _FCLASS_MNORM (1 << 1)
58 # define _FCLASS_MSUBNORM (1 << 2)
59 # define _FCLASS_MZERO (1 << 3)
60 # define _FCLASS_PZERO (1 << 4)
61 # define _FCLASS_PSUBNORM (1 << 5)
62 # define _FCLASS_PNORM (1 << 6)
63 # define _FCLASS_PINF (1 << 7)
64 # define _FCLASS_SNAN (1 << 8)
65 # define _FCLASS_QNAN (1 << 9)
66 # define _FCLASS_ZERO (_FCLASS_MZERO | _FCLASS_PZERO)
67 # define _FCLASS_SUBNORM (_FCLASS_MSUBNORM | _FCLASS_PSUBNORM)
68 # define _FCLASS_NORM (_FCLASS_MNORM | _FCLASS_PNORM)
69 # define _FCLASS_INF (_FCLASS_MINF | _FCLASS_PINF)
70 # define _FCLASS_NAN (_FCLASS_SNAN | _FCLASS_QNAN)
72 #endif /* __riscv_flen */
74 #endif /* fpu_control.h */