1 /* FPU control word bits.  RISC-V version.
2    Copyright (C) 1996-2021 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
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.
9 
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.
14 
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/>.  */
18 
19 #ifndef _FPU_CONTROL_H
20 #define _FPU_CONTROL_H
21 
22 #include <features.h>
23 
24 #ifndef __riscv_flen
25 
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;
32 
33 #else /* __riscv_flen */
34 
35 # define _FPU_RESERVED 0
36 # define _FPU_DEFAULT  0
37 # define _FPU_IEEE     _FPU_DEFAULT
38 
39 /* Type of the control word.  */
40 typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__SI__)));
41 
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))
45 
46 /* Default control word set at startup.  */
47 extern fpu_control_t __fpu_control;
48 
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 (); \
54   __res; }))
55 
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)
71 
72 #endif /* __riscv_flen */
73 
74 #endif	/* fpu_control.h */