]>
Commit | Line | Data |
---|---|---|
1bccec25 BS |
1 | /* |
2 | * FPU op helpers | |
3 | * | |
4 | * Copyright (c) 2003-2005 Fabrice Bellard | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
5650b549 | 9 | * version 2.1 of the License, or (at your option) any later version. |
1bccec25 BS |
10 | * |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
db5ebe5f | 20 | #include "qemu/osdep.h" |
1bccec25 | 21 | #include "cpu.h" |
02c79d78 | 22 | #include "exec/exec-all.h" |
2ef6175a | 23 | #include "exec/helper-proto.h" |
24f91e81 | 24 | #include "fpu/softfloat.h" |
1bccec25 | 25 | |
1bccec25 BS |
26 | #define QT0 (env->qt0) |
27 | #define QT1 (env->qt1) | |
28 | ||
02c79d78 | 29 | static target_ulong do_check_ieee_exceptions(CPUSPARCState *env, uintptr_t ra) |
44516772 | 30 | { |
7385aed2 RH |
31 | target_ulong status = get_float_exception_flags(&env->fp_status); |
32 | target_ulong fsr = env->fsr; | |
33 | ||
34 | if (unlikely(status)) { | |
35 | /* Keep exception flags clear for next time. */ | |
36 | set_float_exception_flags(0, &env->fp_status); | |
44516772 | 37 | |
44516772 RH |
38 | /* Copy IEEE 754 flags into FSR */ |
39 | if (status & float_flag_invalid) { | |
7385aed2 | 40 | fsr |= FSR_NVC; |
44516772 RH |
41 | } |
42 | if (status & float_flag_overflow) { | |
7385aed2 | 43 | fsr |= FSR_OFC; |
44516772 RH |
44 | } |
45 | if (status & float_flag_underflow) { | |
7385aed2 | 46 | fsr |= FSR_UFC; |
44516772 RH |
47 | } |
48 | if (status & float_flag_divbyzero) { | |
7385aed2 | 49 | fsr |= FSR_DZC; |
44516772 RH |
50 | } |
51 | if (status & float_flag_inexact) { | |
7385aed2 | 52 | fsr |= FSR_NXC; |
44516772 RH |
53 | } |
54 | ||
7385aed2 | 55 | if ((fsr & FSR_CEXC_MASK) & ((fsr & FSR_TEM_MASK) >> 23)) { |
5a59fbce | 56 | CPUState *cs = env_cpu(env); |
02c79d78 | 57 | |
7385aed2 RH |
58 | /* Unmasked exception, generate a trap. Note that while |
59 | the helper is marked as NO_WG, we can get away with | |
60 | writing to cpu state along the exception path, since | |
61 | TCG generated code will never see the write. */ | |
62 | env->fsr = fsr | FSR_FTT_IEEE_EXCP; | |
02c79d78 RH |
63 | cs->exception_index = TT_FP_EXCP; |
64 | cpu_loop_exit_restore(cs, ra); | |
44516772 RH |
65 | } else { |
66 | /* Accumulate exceptions */ | |
7385aed2 | 67 | fsr |= (fsr & FSR_CEXC_MASK) << 5; |
44516772 RH |
68 | } |
69 | } | |
44516772 | 70 | |
7385aed2 | 71 | return fsr; |
44516772 RH |
72 | } |
73 | ||
02c79d78 RH |
74 | target_ulong helper_check_ieee_exceptions(CPUSPARCState *env) |
75 | { | |
76 | return do_check_ieee_exceptions(env, GETPC()); | |
77 | } | |
78 | ||
c5f9864e | 79 | #define F_HELPER(name, p) void helper_f##name##p(CPUSPARCState *env) |
1bccec25 BS |
80 | |
81 | #define F_BINOP(name) \ | |
c5f9864e | 82 | float32 helper_f ## name ## s (CPUSPARCState *env, float32 src1, \ |
2e2f4ade | 83 | float32 src2) \ |
1bccec25 | 84 | { \ |
7385aed2 | 85 | return float32_ ## name (src1, src2, &env->fp_status); \ |
1bccec25 | 86 | } \ |
c5f9864e | 87 | float64 helper_f ## name ## d (CPUSPARCState * env, float64 src1,\ |
03fb8cfc | 88 | float64 src2) \ |
1bccec25 | 89 | { \ |
7385aed2 | 90 | return float64_ ## name (src1, src2, &env->fp_status); \ |
1bccec25 BS |
91 | } \ |
92 | F_HELPER(name, q) \ | |
93 | { \ | |
94 | QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \ | |
95 | } | |
96 | ||
97 | F_BINOP(add); | |
98 | F_BINOP(sub); | |
99 | F_BINOP(mul); | |
100 | F_BINOP(div); | |
101 | #undef F_BINOP | |
102 | ||
c5f9864e | 103 | float64 helper_fsmuld(CPUSPARCState *env, float32 src1, float32 src2) |
1bccec25 | 104 | { |
7385aed2 RH |
105 | return float64_mul(float32_to_float64(src1, &env->fp_status), |
106 | float32_to_float64(src2, &env->fp_status), | |
107 | &env->fp_status); | |
1bccec25 BS |
108 | } |
109 | ||
c5f9864e | 110 | void helper_fdmulq(CPUSPARCState *env, float64 src1, float64 src2) |
1bccec25 | 111 | { |
03fb8cfc RH |
112 | QT0 = float128_mul(float64_to_float128(src1, &env->fp_status), |
113 | float64_to_float128(src2, &env->fp_status), | |
1bccec25 BS |
114 | &env->fp_status); |
115 | } | |
116 | ||
117 | float32 helper_fnegs(float32 src) | |
118 | { | |
119 | return float32_chs(src); | |
120 | } | |
121 | ||
122 | #ifdef TARGET_SPARC64 | |
03fb8cfc | 123 | float64 helper_fnegd(float64 src) |
1bccec25 | 124 | { |
03fb8cfc | 125 | return float64_chs(src); |
1bccec25 BS |
126 | } |
127 | ||
128 | F_HELPER(neg, q) | |
129 | { | |
130 | QT0 = float128_chs(QT1); | |
131 | } | |
132 | #endif | |
133 | ||
134 | /* Integer to float conversion. */ | |
c5f9864e | 135 | float32 helper_fitos(CPUSPARCState *env, int32_t src) |
1bccec25 | 136 | { |
7385aed2 | 137 | return int32_to_float32(src, &env->fp_status); |
1bccec25 BS |
138 | } |
139 | ||
c5f9864e | 140 | float64 helper_fitod(CPUSPARCState *env, int32_t src) |
1bccec25 | 141 | { |
03fb8cfc | 142 | return int32_to_float64(src, &env->fp_status); |
1bccec25 BS |
143 | } |
144 | ||
c5f9864e | 145 | void helper_fitoq(CPUSPARCState *env, int32_t src) |
1bccec25 BS |
146 | { |
147 | QT0 = int32_to_float128(src, &env->fp_status); | |
148 | } | |
149 | ||
150 | #ifdef TARGET_SPARC64 | |
c5f9864e | 151 | float32 helper_fxtos(CPUSPARCState *env, int64_t src) |
1bccec25 | 152 | { |
7385aed2 | 153 | return int64_to_float32(src, &env->fp_status); |
1bccec25 BS |
154 | } |
155 | ||
c5f9864e | 156 | float64 helper_fxtod(CPUSPARCState *env, int64_t src) |
1bccec25 | 157 | { |
7385aed2 | 158 | return int64_to_float64(src, &env->fp_status); |
1bccec25 BS |
159 | } |
160 | ||
c5f9864e | 161 | void helper_fxtoq(CPUSPARCState *env, int64_t src) |
1bccec25 | 162 | { |
03fb8cfc | 163 | QT0 = int64_to_float128(src, &env->fp_status); |
1bccec25 BS |
164 | } |
165 | #endif | |
166 | #undef F_HELPER | |
167 | ||
168 | /* floating point conversion */ | |
c5f9864e | 169 | float32 helper_fdtos(CPUSPARCState *env, float64 src) |
1bccec25 | 170 | { |
7385aed2 | 171 | return float64_to_float32(src, &env->fp_status); |
1bccec25 BS |
172 | } |
173 | ||
c5f9864e | 174 | float64 helper_fstod(CPUSPARCState *env, float32 src) |
1bccec25 | 175 | { |
7385aed2 | 176 | return float32_to_float64(src, &env->fp_status); |
1bccec25 BS |
177 | } |
178 | ||
c5f9864e | 179 | float32 helper_fqtos(CPUSPARCState *env) |
1bccec25 | 180 | { |
7385aed2 | 181 | return float128_to_float32(QT1, &env->fp_status); |
1bccec25 BS |
182 | } |
183 | ||
c5f9864e | 184 | void helper_fstoq(CPUSPARCState *env, float32 src) |
1bccec25 BS |
185 | { |
186 | QT0 = float32_to_float128(src, &env->fp_status); | |
187 | } | |
188 | ||
c5f9864e | 189 | float64 helper_fqtod(CPUSPARCState *env) |
1bccec25 | 190 | { |
7385aed2 | 191 | return float128_to_float64(QT1, &env->fp_status); |
1bccec25 BS |
192 | } |
193 | ||
c5f9864e | 194 | void helper_fdtoq(CPUSPARCState *env, float64 src) |
1bccec25 | 195 | { |
03fb8cfc | 196 | QT0 = float64_to_float128(src, &env->fp_status); |
1bccec25 BS |
197 | } |
198 | ||
199 | /* Float to integer conversion. */ | |
c5f9864e | 200 | int32_t helper_fstoi(CPUSPARCState *env, float32 src) |
1bccec25 | 201 | { |
7385aed2 | 202 | return float32_to_int32_round_to_zero(src, &env->fp_status); |
1bccec25 BS |
203 | } |
204 | ||
c5f9864e | 205 | int32_t helper_fdtoi(CPUSPARCState *env, float64 src) |
1bccec25 | 206 | { |
7385aed2 | 207 | return float64_to_int32_round_to_zero(src, &env->fp_status); |
1bccec25 BS |
208 | } |
209 | ||
c5f9864e | 210 | int32_t helper_fqtoi(CPUSPARCState *env) |
1bccec25 | 211 | { |
7385aed2 | 212 | return float128_to_int32_round_to_zero(QT1, &env->fp_status); |
1bccec25 BS |
213 | } |
214 | ||
215 | #ifdef TARGET_SPARC64 | |
c5f9864e | 216 | int64_t helper_fstox(CPUSPARCState *env, float32 src) |
1bccec25 | 217 | { |
7385aed2 | 218 | return float32_to_int64_round_to_zero(src, &env->fp_status); |
1bccec25 BS |
219 | } |
220 | ||
c5f9864e | 221 | int64_t helper_fdtox(CPUSPARCState *env, float64 src) |
1bccec25 | 222 | { |
7385aed2 | 223 | return float64_to_int64_round_to_zero(src, &env->fp_status); |
1bccec25 BS |
224 | } |
225 | ||
c5f9864e | 226 | int64_t helper_fqtox(CPUSPARCState *env) |
1bccec25 | 227 | { |
7385aed2 | 228 | return float128_to_int64_round_to_zero(QT1, &env->fp_status); |
1bccec25 BS |
229 | } |
230 | #endif | |
231 | ||
232 | float32 helper_fabss(float32 src) | |
233 | { | |
234 | return float32_abs(src); | |
235 | } | |
236 | ||
237 | #ifdef TARGET_SPARC64 | |
f027c3b1 | 238 | float64 helper_fabsd(float64 src) |
1bccec25 | 239 | { |
03fb8cfc | 240 | return float64_abs(src); |
1bccec25 BS |
241 | } |
242 | ||
c5f9864e | 243 | void helper_fabsq(CPUSPARCState *env) |
1bccec25 BS |
244 | { |
245 | QT0 = float128_abs(QT1); | |
246 | } | |
247 | #endif | |
248 | ||
c5f9864e | 249 | float32 helper_fsqrts(CPUSPARCState *env, float32 src) |
1bccec25 | 250 | { |
7385aed2 | 251 | return float32_sqrt(src, &env->fp_status); |
1bccec25 BS |
252 | } |
253 | ||
c5f9864e | 254 | float64 helper_fsqrtd(CPUSPARCState *env, float64 src) |
1bccec25 | 255 | { |
7385aed2 | 256 | return float64_sqrt(src, &env->fp_status); |
1bccec25 BS |
257 | } |
258 | ||
c5f9864e | 259 | void helper_fsqrtq(CPUSPARCState *env) |
1bccec25 BS |
260 | { |
261 | QT0 = float128_sqrt(QT1, &env->fp_status); | |
262 | } | |
263 | ||
264 | #define GEN_FCMP(name, size, reg1, reg2, FS, E) \ | |
7385aed2 | 265 | target_ulong glue(helper_, name) (CPUSPARCState *env) \ |
1bccec25 | 266 | { \ |
71bfd65c | 267 | FloatRelation ret; \ |
7385aed2 | 268 | target_ulong fsr; \ |
5acfc832 AJ |
269 | if (E) { \ |
270 | ret = glue(size, _compare)(reg1, reg2, &env->fp_status); \ | |
271 | } else { \ | |
272 | ret = glue(size, _compare_quiet)(reg1, reg2, \ | |
273 | &env->fp_status); \ | |
1bccec25 | 274 | } \ |
02c79d78 | 275 | fsr = do_check_ieee_exceptions(env, GETPC()); \ |
5acfc832 | 276 | switch (ret) { \ |
1bccec25 | 277 | case float_relation_unordered: \ |
7385aed2 RH |
278 | fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \ |
279 | fsr |= FSR_NVA; \ | |
1bccec25 BS |
280 | break; \ |
281 | case float_relation_less: \ | |
7385aed2 RH |
282 | fsr &= ~(FSR_FCC1) << FS; \ |
283 | fsr |= FSR_FCC0 << FS; \ | |
1bccec25 BS |
284 | break; \ |
285 | case float_relation_greater: \ | |
7385aed2 RH |
286 | fsr &= ~(FSR_FCC0) << FS; \ |
287 | fsr |= FSR_FCC1 << FS; \ | |
1bccec25 BS |
288 | break; \ |
289 | default: \ | |
7385aed2 | 290 | fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \ |
1bccec25 BS |
291 | break; \ |
292 | } \ | |
7385aed2 | 293 | return fsr; \ |
1bccec25 | 294 | } |
03fb8cfc | 295 | #define GEN_FCMP_T(name, size, FS, E) \ |
7385aed2 | 296 | target_ulong glue(helper_, name)(CPUSPARCState *env, size src1, size src2)\ |
1bccec25 | 297 | { \ |
71bfd65c | 298 | FloatRelation ret; \ |
7385aed2 | 299 | target_ulong fsr; \ |
5acfc832 AJ |
300 | if (E) { \ |
301 | ret = glue(size, _compare)(src1, src2, &env->fp_status); \ | |
302 | } else { \ | |
303 | ret = glue(size, _compare_quiet)(src1, src2, \ | |
304 | &env->fp_status); \ | |
1bccec25 | 305 | } \ |
02c79d78 | 306 | fsr = do_check_ieee_exceptions(env, GETPC()); \ |
5acfc832 | 307 | switch (ret) { \ |
1bccec25 | 308 | case float_relation_unordered: \ |
7385aed2 | 309 | fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \ |
1bccec25 BS |
310 | break; \ |
311 | case float_relation_less: \ | |
7385aed2 RH |
312 | fsr &= ~(FSR_FCC1 << FS); \ |
313 | fsr |= FSR_FCC0 << FS; \ | |
1bccec25 BS |
314 | break; \ |
315 | case float_relation_greater: \ | |
7385aed2 RH |
316 | fsr &= ~(FSR_FCC0 << FS); \ |
317 | fsr |= FSR_FCC1 << FS; \ | |
1bccec25 BS |
318 | break; \ |
319 | default: \ | |
7385aed2 | 320 | fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \ |
1bccec25 BS |
321 | break; \ |
322 | } \ | |
7385aed2 | 323 | return fsr; \ |
1bccec25 BS |
324 | } |
325 | ||
03fb8cfc RH |
326 | GEN_FCMP_T(fcmps, float32, 0, 0); |
327 | GEN_FCMP_T(fcmpd, float64, 0, 0); | |
1bccec25 | 328 | |
03fb8cfc RH |
329 | GEN_FCMP_T(fcmpes, float32, 0, 1); |
330 | GEN_FCMP_T(fcmped, float64, 0, 1); | |
1bccec25 BS |
331 | |
332 | GEN_FCMP(fcmpq, float128, QT0, QT1, 0, 0); | |
333 | GEN_FCMP(fcmpeq, float128, QT0, QT1, 0, 1); | |
334 | ||
335 | #ifdef TARGET_SPARC64 | |
03fb8cfc RH |
336 | GEN_FCMP_T(fcmps_fcc1, float32, 22, 0); |
337 | GEN_FCMP_T(fcmpd_fcc1, float64, 22, 0); | |
1bccec25 BS |
338 | GEN_FCMP(fcmpq_fcc1, float128, QT0, QT1, 22, 0); |
339 | ||
03fb8cfc RH |
340 | GEN_FCMP_T(fcmps_fcc2, float32, 24, 0); |
341 | GEN_FCMP_T(fcmpd_fcc2, float64, 24, 0); | |
1bccec25 BS |
342 | GEN_FCMP(fcmpq_fcc2, float128, QT0, QT1, 24, 0); |
343 | ||
03fb8cfc RH |
344 | GEN_FCMP_T(fcmps_fcc3, float32, 26, 0); |
345 | GEN_FCMP_T(fcmpd_fcc3, float64, 26, 0); | |
1bccec25 BS |
346 | GEN_FCMP(fcmpq_fcc3, float128, QT0, QT1, 26, 0); |
347 | ||
03fb8cfc RH |
348 | GEN_FCMP_T(fcmpes_fcc1, float32, 22, 1); |
349 | GEN_FCMP_T(fcmped_fcc1, float64, 22, 1); | |
1bccec25 BS |
350 | GEN_FCMP(fcmpeq_fcc1, float128, QT0, QT1, 22, 1); |
351 | ||
03fb8cfc RH |
352 | GEN_FCMP_T(fcmpes_fcc2, float32, 24, 1); |
353 | GEN_FCMP_T(fcmped_fcc2, float64, 24, 1); | |
1bccec25 BS |
354 | GEN_FCMP(fcmpeq_fcc2, float128, QT0, QT1, 24, 1); |
355 | ||
03fb8cfc RH |
356 | GEN_FCMP_T(fcmpes_fcc3, float32, 26, 1); |
357 | GEN_FCMP_T(fcmped_fcc3, float64, 26, 1); | |
1bccec25 BS |
358 | GEN_FCMP(fcmpeq_fcc3, float128, QT0, QT1, 26, 1); |
359 | #endif | |
03fb8cfc RH |
360 | #undef GEN_FCMP_T |
361 | #undef GEN_FCMP | |
1bccec25 | 362 | |
7385aed2 | 363 | static void set_fsr(CPUSPARCState *env, target_ulong fsr) |
1bccec25 BS |
364 | { |
365 | int rnd_mode; | |
366 | ||
7385aed2 | 367 | switch (fsr & FSR_RD_MASK) { |
1bccec25 BS |
368 | case FSR_RD_NEAREST: |
369 | rnd_mode = float_round_nearest_even; | |
370 | break; | |
371 | default: | |
372 | case FSR_RD_ZERO: | |
373 | rnd_mode = float_round_to_zero; | |
374 | break; | |
375 | case FSR_RD_POS: | |
376 | rnd_mode = float_round_up; | |
377 | break; | |
378 | case FSR_RD_NEG: | |
379 | rnd_mode = float_round_down; | |
380 | break; | |
381 | } | |
382 | set_float_rounding_mode(rnd_mode, &env->fp_status); | |
383 | } | |
384 | ||
7385aed2 RH |
385 | target_ulong helper_ldfsr(CPUSPARCState *env, target_ulong old_fsr, |
386 | uint32_t new_fsr) | |
1bccec25 | 387 | { |
7385aed2 RH |
388 | old_fsr = (new_fsr & FSR_LDFSR_MASK) | (old_fsr & FSR_LDFSR_OLDMASK); |
389 | set_fsr(env, old_fsr); | |
390 | return old_fsr; | |
1bccec25 BS |
391 | } |
392 | ||
393 | #ifdef TARGET_SPARC64 | |
7385aed2 RH |
394 | target_ulong helper_ldxfsr(CPUSPARCState *env, target_ulong old_fsr, |
395 | uint64_t new_fsr) | |
1bccec25 | 396 | { |
7385aed2 RH |
397 | old_fsr = (new_fsr & FSR_LDXFSR_MASK) | (old_fsr & FSR_LDXFSR_OLDMASK); |
398 | set_fsr(env, old_fsr); | |
399 | return old_fsr; | |
1bccec25 BS |
400 | } |
401 | #endif |