2 * OpenRISC float helper routines
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "exec/helper-proto.h"
23 #include "exception.h"
25 static inline uint32_t ieee_ex_to_openrisc(OpenRISCCPU *cpu, int fexcp)
29 if (fexcp & float_flag_invalid) {
30 cpu->env.fpcsr |= FPCSR_IVF;
33 if (fexcp & float_flag_overflow) {
34 cpu->env.fpcsr |= FPCSR_OVF;
37 if (fexcp & float_flag_underflow) {
38 cpu->env.fpcsr |= FPCSR_UNF;
41 if (fexcp & float_flag_divbyzero) {
42 cpu->env.fpcsr |= FPCSR_DZF;
45 if (fexcp & float_flag_inexact) {
46 cpu->env.fpcsr |= FPCSR_IXF;
54 static inline void update_fpcsr(OpenRISCCPU *cpu)
56 int tmp = ieee_ex_to_openrisc(cpu,
57 get_float_exception_flags(&cpu->env.fp_status));
59 SET_FP_CAUSE(cpu->env.fpcsr, tmp);
60 if ((GET_FP_ENABLE(cpu->env.fpcsr) & tmp) &&
61 (cpu->env.fpcsr & FPCSR_FPEE)) {
62 helper_exception(&cpu->env, EXCP_FPE);
64 UPDATE_FP_FLAGS(cpu->env.fpcsr, tmp);
68 uint64_t HELPER(itofd)(CPUOpenRISCState *env, uint64_t val)
71 OpenRISCCPU *cpu = openrisc_env_get_cpu(env);
73 set_float_exception_flags(0, &cpu->env.fp_status);
74 itofd = int32_to_float64(val, &cpu->env.fp_status);
80 uint32_t HELPER(itofs)(CPUOpenRISCState *env, uint32_t val)
83 OpenRISCCPU *cpu = openrisc_env_get_cpu(env);
85 set_float_exception_flags(0, &cpu->env.fp_status);
86 itofs = int32_to_float32(val, &cpu->env.fp_status);
92 uint64_t HELPER(ftoid)(CPUOpenRISCState *env, uint64_t val)
95 OpenRISCCPU *cpu = openrisc_env_get_cpu(env);
97 set_float_exception_flags(0, &cpu->env.fp_status);
98 ftoid = float32_to_int64(val, &cpu->env.fp_status);
104 uint32_t HELPER(ftois)(CPUOpenRISCState *env, uint32_t val)
107 OpenRISCCPU *cpu = openrisc_env_get_cpu(env);
109 set_float_exception_flags(0, &cpu->env.fp_status);
110 ftois = float32_to_int32(val, &cpu->env.fp_status);
116 #define FLOAT_OP(name, p) void helper_float_##_##p(void)
118 #define FLOAT_CALC(name) \
119 uint64_t helper_float_ ## name ## _d(CPUOpenRISCState *env, \
120 uint64_t fdt0, uint64_t fdt1) \
123 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
124 set_float_exception_flags(0, &cpu->env.fp_status); \
125 result = float64_ ## name(fdt0, fdt1, &cpu->env.fp_status); \
130 uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env, \
131 uint32_t fdt0, uint32_t fdt1) \
134 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
135 set_float_exception_flags(0, &cpu->env.fp_status); \
136 result = float32_ ## name(fdt0, fdt1, &cpu->env.fp_status); \
148 #define FLOAT_TERNOP(name1, name2) \
149 uint64_t helper_float_ ## name1 ## name2 ## _d(CPUOpenRISCState *env, \
153 uint64_t result, temp, hi, lo; \
154 uint32_t val1, val2; \
155 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
156 hi = env->fpmaddhi; \
157 lo = env->fpmaddlo; \
158 set_float_exception_flags(0, &cpu->env.fp_status); \
159 result = float64_ ## name1(fdt0, fdt1, &cpu->env.fp_status); \
162 temp = (hi << 32) | lo; \
163 result = float64_ ## name2(result, temp, &cpu->env.fp_status); \
164 val1 = result >> 32; \
165 val2 = (uint32_t) (result & 0xffffffff); \
167 cpu->env.fpmaddlo = val2; \
168 cpu->env.fpmaddhi = val1; \
172 uint32_t helper_float_ ## name1 ## name2 ## _s(CPUOpenRISCState *env, \
173 uint32_t fdt0, uint32_t fdt1) \
175 uint64_t result, temp, hi, lo; \
176 uint32_t val1, val2; \
177 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
178 hi = cpu->env.fpmaddhi; \
179 lo = cpu->env.fpmaddlo; \
180 set_float_exception_flags(0, &cpu->env.fp_status); \
181 result = float64_ ## name1(fdt0, fdt1, &cpu->env.fp_status); \
182 temp = (hi << 32) | lo; \
183 result = float64_ ## name2(result, temp, &cpu->env.fp_status); \
184 val1 = result >> 32; \
185 val2 = (uint32_t) (result & 0xffffffff); \
187 cpu->env.fpmaddlo = val2; \
188 cpu->env.fpmaddhi = val1; \
192 FLOAT_TERNOP(mul, add)
196 #define FLOAT_CMP(name) \
197 uint64_t helper_float_ ## name ## _d(CPUOpenRISCState *env, \
198 uint64_t fdt0, uint64_t fdt1) \
201 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
202 set_float_exception_flags(0, &cpu->env.fp_status); \
203 res = float64_ ## name(fdt0, fdt1, &cpu->env.fp_status); \
208 uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env, \
209 uint32_t fdt0, uint32_t fdt1)\
212 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
213 set_float_exception_flags(0, &cpu->env.fp_status); \
214 res = float32_ ## name(fdt0, fdt1, &cpu->env.fp_status); \
225 #define FLOAT_CMPNE(name) \
226 uint64_t helper_float_ ## name ## _d(CPUOpenRISCState *env, \
227 uint64_t fdt0, uint64_t fdt1) \
230 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
231 set_float_exception_flags(0, &cpu->env.fp_status); \
232 res = !float64_eq_quiet(fdt0, fdt1, &cpu->env.fp_status); \
237 uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env, \
238 uint32_t fdt0, uint32_t fdt1) \
241 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
242 set_float_exception_flags(0, &cpu->env.fp_status); \
243 res = !float32_eq_quiet(fdt0, fdt1, &cpu->env.fp_status); \
251 #define FLOAT_CMPGT(name) \
252 uint64_t helper_float_ ## name ## _d(CPUOpenRISCState *env, \
253 uint64_t fdt0, uint64_t fdt1) \
256 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
257 set_float_exception_flags(0, &cpu->env.fp_status); \
258 res = !float64_le(fdt0, fdt1, &cpu->env.fp_status); \
263 uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env, \
264 uint32_t fdt0, uint32_t fdt1) \
267 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
268 set_float_exception_flags(0, &cpu->env.fp_status); \
269 res = !float32_le(fdt0, fdt1, &cpu->env.fp_status); \
276 #define FLOAT_CMPGE(name) \
277 uint64_t helper_float_ ## name ## _d(CPUOpenRISCState *env, \
278 uint64_t fdt0, uint64_t fdt1) \
281 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
282 set_float_exception_flags(0, &cpu->env.fp_status); \
283 res = !float64_lt(fdt0, fdt1, &cpu->env.fp_status); \
288 uint32_t helper_float_ ## name ## _s(CPUOpenRISCState *env, \
289 uint32_t fdt0, uint32_t fdt1) \
292 OpenRISCCPU *cpu = openrisc_env_get_cpu(env); \
293 set_float_exception_flags(0, &cpu->env.fp_status); \
294 res = !float32_lt(fdt0, fdt1, &cpu->env.fp_status); \