1 |
13 |
serginhofr |
/* Private floating point rounding and exceptions handling. RISC-V version.
|
2 |
|
|
Copyright (C) 2014-2015 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 |
|
|
<http://www.gnu.org/licenses/>. */
|
18 |
|
|
|
19 |
|
|
#ifndef RISCV_MATH_PRIVATE_H
|
20 |
|
|
#define RISCV_MATH_PRIVATE_H 1
|
21 |
|
|
|
22 |
|
|
#include <fenv.h>
|
23 |
|
|
#include <fpu_control.h>
|
24 |
|
|
|
25 |
|
|
static __always_inline void
|
26 |
|
|
libc_feholdexcept_riscv (fenv_t *envp)
|
27 |
|
|
{
|
28 |
|
|
_FPU_GETCW (*envp);
|
29 |
|
|
_FPU_SETFLAGS (0);
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
#define libc_feholdexcept libc_feholdexcept_riscv
|
33 |
|
|
#define libc_feholdexceptf libc_feholdexcept_riscv
|
34 |
|
|
#define libc_feholdexceptl libc_feholdexcept_riscv
|
35 |
|
|
|
36 |
|
|
static __always_inline void
|
37 |
|
|
libc_fesetround_riscv (int round)
|
38 |
|
|
{
|
39 |
|
|
_FPU_SETROUND (round);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
#define libc_fesetround libc_fesetround_riscv
|
43 |
|
|
#define libc_fesetroundf libc_fesetround_riscv
|
44 |
|
|
#define libc_fesetroundl libc_fesetround_riscv
|
45 |
|
|
|
46 |
|
|
static __always_inline void
|
47 |
|
|
libc_feholdexcept_setround_riscv (fenv_t *envp, int round)
|
48 |
|
|
{
|
49 |
|
|
libc_fesetround_riscv (round);
|
50 |
|
|
libc_feholdexcept_riscv (envp);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
#define libc_feholdexcept_setround libc_feholdexcept_setround_riscv
|
54 |
|
|
#define libc_feholdexcept_setroundf libc_feholdexcept_setround_riscv
|
55 |
|
|
#define libc_feholdexcept_setroundl libc_feholdexcept_setround_riscv
|
56 |
|
|
|
57 |
|
|
static __always_inline int
|
58 |
|
|
libc_fetestexcept_riscv (int ex)
|
59 |
|
|
{
|
60 |
|
|
int cw;
|
61 |
|
|
|
62 |
|
|
_FPU_GETFLAGS (cw);
|
63 |
|
|
|
64 |
|
|
return cw & ex;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
#define libc_fetestexcept libc_fetestexcept_riscv
|
68 |
|
|
#define libc_fetestexceptf libc_fetestexcept_riscv
|
69 |
|
|
#define libc_fetestexceptl libc_fetestexcept_riscv
|
70 |
|
|
|
71 |
|
|
static __always_inline void
|
72 |
|
|
libc_fesetenv_riscv (const fenv_t *envp)
|
73 |
|
|
{
|
74 |
|
|
long env = (long) envp - (long) FE_DFL_ENV;
|
75 |
|
|
if (env != 0)
|
76 |
|
|
env = *envp;
|
77 |
|
|
|
78 |
|
|
_FPU_SETCW (env);
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
#define libc_fesetenv libc_fesetenv_riscv
|
82 |
|
|
#define libc_fesetenvf libc_fesetenv_riscv
|
83 |
|
|
#define libc_fesetenvl libc_fesetenv_riscv
|
84 |
|
|
#define libc_feresetround_noex libc_fesetenv_riscv
|
85 |
|
|
#define libc_feresetround_noexf libc_fesetenv_riscv
|
86 |
|
|
#define libc_feresetround_noexl libc_fesetenv_riscv
|
87 |
|
|
|
88 |
|
|
static __always_inline int
|
89 |
|
|
libc_feupdateenv_test_riscv (const fenv_t *envp, int ex)
|
90 |
|
|
{
|
91 |
|
|
fenv_t env = *envp;
|
92 |
|
|
int excepts;
|
93 |
|
|
|
94 |
|
|
_FPU_SETROUND (0);
|
95 |
|
|
asm volatile ("csrrs %0, fcsr, %1" : "=r"(excepts) : "r"(env));
|
96 |
|
|
|
97 |
|
|
return excepts & ex;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
#define libc_feupdateenv_test libc_feupdateenv_test_riscv
|
101 |
|
|
#define libc_feupdateenv_testf libc_feupdateenv_test_riscv
|
102 |
|
|
#define libc_feupdateenv_testl libc_feupdateenv_test_riscv
|
103 |
|
|
|
104 |
|
|
static __always_inline void
|
105 |
|
|
libc_feupdateenv_riscv (const fenv_t *envp)
|
106 |
|
|
{
|
107 |
|
|
fenv_t env = *envp;
|
108 |
|
|
|
109 |
|
|
_FPU_SETROUND (0);
|
110 |
|
|
asm volatile ("csrs fcsr, %0" : : "r"(env));
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
#define libc_feupdateenv libc_feupdateenv_riscv
|
114 |
|
|
#define libc_feupdateenvf libc_feupdateenv_riscv
|
115 |
|
|
#define libc_feupdateenvl libc_feupdateenv_riscv
|
116 |
|
|
|
117 |
|
|
static __always_inline void
|
118 |
|
|
libc_feholdsetround_riscv (fenv_t *envp, int round)
|
119 |
|
|
{
|
120 |
|
|
/* Note this implementation makes an improperly-formatted fenv_t and
|
121 |
|
|
so should only be used in conjunction with libc_feresetround. */
|
122 |
|
|
int old_round;
|
123 |
|
|
asm volatile ("csrrw %0, frm, %1" : "=r"(old_round) : "r"(round));
|
124 |
|
|
*envp = old_round;
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
#define libc_feholdsetround libc_feholdsetround_riscv
|
128 |
|
|
#define libc_feholdsetroundf libc_feholdsetround_riscv
|
129 |
|
|
#define libc_feholdsetroundl libc_feholdsetround_riscv
|
130 |
|
|
|
131 |
|
|
static __always_inline void
|
132 |
|
|
libc_feresetround_riscv (fenv_t *envp)
|
133 |
|
|
{
|
134 |
|
|
/* Note this implementation takes an improperly-formatted fenv_t and
|
135 |
|
|
so should only be used in conjunction with libc_feholdsetround. */
|
136 |
|
|
_FPU_SETROUND (*envp);
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
#define libc_feresetround libc_feresetround_riscv
|
140 |
|
|
#define libc_feresetroundf libc_feresetround_riscv
|
141 |
|
|
#define libc_feresetroundl libc_feresetround_riscv
|
142 |
|
|
|
143 |
|
|
#include_next <math_private.h>
|
144 |
|
|
|
145 |
|
|
#endif
|