4 * Copyright (c) 2003-2005 Fabrice Bellard
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
9 * version 2 of the License, or (at your option) any later version.
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.
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/>.
20 #include "qemu/osdep.h"
22 #include "exec/helper-proto.h"
24 #define QT0 (env->qt0)
25 #define QT1 (env->qt1)
27 static void check_ieee_exceptions(CPUSPARCState
*env
)
31 status
= get_float_exception_flags(&env
->fp_status
);
33 /* Copy IEEE 754 flags into FSR */
34 if (status
& float_flag_invalid
) {
37 if (status
& float_flag_overflow
) {
40 if (status
& float_flag_underflow
) {
43 if (status
& float_flag_divbyzero
) {
46 if (status
& float_flag_inexact
) {
50 if ((env
->fsr
& FSR_CEXC_MASK
) & ((env
->fsr
& FSR_TEM_MASK
) >> 23)) {
51 /* Unmasked exception, generate a trap */
52 env
->fsr
|= FSR_FTT_IEEE_EXCP
;
53 helper_raise_exception(env
, TT_FP_EXCP
);
55 /* Accumulate exceptions */
56 env
->fsr
|= (env
->fsr
& FSR_CEXC_MASK
) << 5;
61 static inline void clear_float_exceptions(CPUSPARCState
*env
)
63 set_float_exception_flags(0, &env
->fp_status
);
66 #define F_HELPER(name, p) void helper_f##name##p(CPUSPARCState *env)
68 #define F_BINOP(name) \
69 float32 helper_f ## name ## s (CPUSPARCState *env, float32 src1, \
73 clear_float_exceptions(env); \
74 ret = float32_ ## name (src1, src2, &env->fp_status); \
75 check_ieee_exceptions(env); \
78 float64 helper_f ## name ## d (CPUSPARCState * env, float64 src1,\
82 clear_float_exceptions(env); \
83 ret = float64_ ## name (src1, src2, &env->fp_status); \
84 check_ieee_exceptions(env); \
89 clear_float_exceptions(env); \
90 QT0 = float128_ ## name (QT0, QT1, &env->fp_status); \
91 check_ieee_exceptions(env); \
100 float64
helper_fsmuld(CPUSPARCState
*env
, float32 src1
, float32 src2
)
103 clear_float_exceptions(env
);
104 ret
= float64_mul(float32_to_float64(src1
, &env
->fp_status
),
105 float32_to_float64(src2
, &env
->fp_status
),
107 check_ieee_exceptions(env
);
111 void helper_fdmulq(CPUSPARCState
*env
, float64 src1
, float64 src2
)
113 clear_float_exceptions(env
);
114 QT0
= float128_mul(float64_to_float128(src1
, &env
->fp_status
),
115 float64_to_float128(src2
, &env
->fp_status
),
117 check_ieee_exceptions(env
);
120 float32
helper_fnegs(float32 src
)
122 return float32_chs(src
);
125 #ifdef TARGET_SPARC64
126 float64
helper_fnegd(float64 src
)
128 return float64_chs(src
);
133 QT0
= float128_chs(QT1
);
137 /* Integer to float conversion. */
138 float32
helper_fitos(CPUSPARCState
*env
, int32_t src
)
140 /* Inexact error possible converting int to float. */
142 clear_float_exceptions(env
);
143 ret
= int32_to_float32(src
, &env
->fp_status
);
144 check_ieee_exceptions(env
);
148 float64
helper_fitod(CPUSPARCState
*env
, int32_t src
)
150 /* No possible exceptions converting int to double. */
151 return int32_to_float64(src
, &env
->fp_status
);
154 void helper_fitoq(CPUSPARCState
*env
, int32_t src
)
156 /* No possible exceptions converting int to long double. */
157 QT0
= int32_to_float128(src
, &env
->fp_status
);
160 #ifdef TARGET_SPARC64
161 float32
helper_fxtos(CPUSPARCState
*env
, int64_t src
)
164 clear_float_exceptions(env
);
165 ret
= int64_to_float32(src
, &env
->fp_status
);
166 check_ieee_exceptions(env
);
170 float64
helper_fxtod(CPUSPARCState
*env
, int64_t src
)
173 clear_float_exceptions(env
);
174 ret
= int64_to_float64(src
, &env
->fp_status
);
175 check_ieee_exceptions(env
);
179 void helper_fxtoq(CPUSPARCState
*env
, int64_t src
)
181 /* No possible exceptions converting long long to long double. */
182 QT0
= int64_to_float128(src
, &env
->fp_status
);
187 /* floating point conversion */
188 float32
helper_fdtos(CPUSPARCState
*env
, float64 src
)
191 clear_float_exceptions(env
);
192 ret
= float64_to_float32(src
, &env
->fp_status
);
193 check_ieee_exceptions(env
);
197 float64
helper_fstod(CPUSPARCState
*env
, float32 src
)
200 clear_float_exceptions(env
);
201 ret
= float32_to_float64(src
, &env
->fp_status
);
202 check_ieee_exceptions(env
);
206 float32
helper_fqtos(CPUSPARCState
*env
)
209 clear_float_exceptions(env
);
210 ret
= float128_to_float32(QT1
, &env
->fp_status
);
211 check_ieee_exceptions(env
);
215 void helper_fstoq(CPUSPARCState
*env
, float32 src
)
217 clear_float_exceptions(env
);
218 QT0
= float32_to_float128(src
, &env
->fp_status
);
219 check_ieee_exceptions(env
);
222 float64
helper_fqtod(CPUSPARCState
*env
)
225 clear_float_exceptions(env
);
226 ret
= float128_to_float64(QT1
, &env
->fp_status
);
227 check_ieee_exceptions(env
);
231 void helper_fdtoq(CPUSPARCState
*env
, float64 src
)
233 clear_float_exceptions(env
);
234 QT0
= float64_to_float128(src
, &env
->fp_status
);
235 check_ieee_exceptions(env
);
238 /* Float to integer conversion. */
239 int32_t helper_fstoi(CPUSPARCState
*env
, float32 src
)
242 clear_float_exceptions(env
);
243 ret
= float32_to_int32_round_to_zero(src
, &env
->fp_status
);
244 check_ieee_exceptions(env
);
248 int32_t helper_fdtoi(CPUSPARCState
*env
, float64 src
)
251 clear_float_exceptions(env
);
252 ret
= float64_to_int32_round_to_zero(src
, &env
->fp_status
);
253 check_ieee_exceptions(env
);
257 int32_t helper_fqtoi(CPUSPARCState
*env
)
260 clear_float_exceptions(env
);
261 ret
= float128_to_int32_round_to_zero(QT1
, &env
->fp_status
);
262 check_ieee_exceptions(env
);
266 #ifdef TARGET_SPARC64
267 int64_t helper_fstox(CPUSPARCState
*env
, float32 src
)
270 clear_float_exceptions(env
);
271 ret
= float32_to_int64_round_to_zero(src
, &env
->fp_status
);
272 check_ieee_exceptions(env
);
276 int64_t helper_fdtox(CPUSPARCState
*env
, float64 src
)
279 clear_float_exceptions(env
);
280 ret
= float64_to_int64_round_to_zero(src
, &env
->fp_status
);
281 check_ieee_exceptions(env
);
285 int64_t helper_fqtox(CPUSPARCState
*env
)
288 clear_float_exceptions(env
);
289 ret
= float128_to_int64_round_to_zero(QT1
, &env
->fp_status
);
290 check_ieee_exceptions(env
);
295 float32
helper_fabss(float32 src
)
297 return float32_abs(src
);
300 #ifdef TARGET_SPARC64
301 float64
helper_fabsd(float64 src
)
303 return float64_abs(src
);
306 void helper_fabsq(CPUSPARCState
*env
)
308 QT0
= float128_abs(QT1
);
312 float32
helper_fsqrts(CPUSPARCState
*env
, float32 src
)
315 clear_float_exceptions(env
);
316 ret
= float32_sqrt(src
, &env
->fp_status
);
317 check_ieee_exceptions(env
);
321 float64
helper_fsqrtd(CPUSPARCState
*env
, float64 src
)
324 clear_float_exceptions(env
);
325 ret
= float64_sqrt(src
, &env
->fp_status
);
326 check_ieee_exceptions(env
);
330 void helper_fsqrtq(CPUSPARCState
*env
)
332 clear_float_exceptions(env
);
333 QT0
= float128_sqrt(QT1
, &env
->fp_status
);
334 check_ieee_exceptions(env
);
337 #define GEN_FCMP(name, size, reg1, reg2, FS, E) \
338 void glue(helper_, name) (CPUSPARCState *env) \
341 clear_float_exceptions(env); \
343 ret = glue(size, _compare)(reg1, reg2, &env->fp_status); \
345 ret = glue(size, _compare_quiet)(reg1, reg2, \
348 check_ieee_exceptions(env); \
350 case float_relation_unordered: \
351 env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
352 env->fsr |= FSR_NVA; \
354 case float_relation_less: \
355 env->fsr &= ~(FSR_FCC1) << FS; \
356 env->fsr |= FSR_FCC0 << FS; \
358 case float_relation_greater: \
359 env->fsr &= ~(FSR_FCC0) << FS; \
360 env->fsr |= FSR_FCC1 << FS; \
363 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
367 #define GEN_FCMP_T(name, size, FS, E) \
368 void glue(helper_, name)(CPUSPARCState *env, size src1, size src2) \
371 clear_float_exceptions(env); \
373 ret = glue(size, _compare)(src1, src2, &env->fp_status); \
375 ret = glue(size, _compare_quiet)(src1, src2, \
378 check_ieee_exceptions(env); \
380 case float_relation_unordered: \
381 env->fsr |= (FSR_FCC1 | FSR_FCC0) << FS; \
383 case float_relation_less: \
384 env->fsr &= ~(FSR_FCC1 << FS); \
385 env->fsr |= FSR_FCC0 << FS; \
387 case float_relation_greater: \
388 env->fsr &= ~(FSR_FCC0 << FS); \
389 env->fsr |= FSR_FCC1 << FS; \
392 env->fsr &= ~((FSR_FCC1 | FSR_FCC0) << FS); \
397 GEN_FCMP_T(fcmps
, float32
, 0, 0);
398 GEN_FCMP_T(fcmpd
, float64
, 0, 0);
400 GEN_FCMP_T(fcmpes
, float32
, 0, 1);
401 GEN_FCMP_T(fcmped
, float64
, 0, 1);
403 GEN_FCMP(fcmpq
, float128
, QT0
, QT1
, 0, 0);
404 GEN_FCMP(fcmpeq
, float128
, QT0
, QT1
, 0, 1);
406 #ifdef TARGET_SPARC64
407 GEN_FCMP_T(fcmps_fcc1
, float32
, 22, 0);
408 GEN_FCMP_T(fcmpd_fcc1
, float64
, 22, 0);
409 GEN_FCMP(fcmpq_fcc1
, float128
, QT0
, QT1
, 22, 0);
411 GEN_FCMP_T(fcmps_fcc2
, float32
, 24, 0);
412 GEN_FCMP_T(fcmpd_fcc2
, float64
, 24, 0);
413 GEN_FCMP(fcmpq_fcc2
, float128
, QT0
, QT1
, 24, 0);
415 GEN_FCMP_T(fcmps_fcc3
, float32
, 26, 0);
416 GEN_FCMP_T(fcmpd_fcc3
, float64
, 26, 0);
417 GEN_FCMP(fcmpq_fcc3
, float128
, QT0
, QT1
, 26, 0);
419 GEN_FCMP_T(fcmpes_fcc1
, float32
, 22, 1);
420 GEN_FCMP_T(fcmped_fcc1
, float64
, 22, 1);
421 GEN_FCMP(fcmpeq_fcc1
, float128
, QT0
, QT1
, 22, 1);
423 GEN_FCMP_T(fcmpes_fcc2
, float32
, 24, 1);
424 GEN_FCMP_T(fcmped_fcc2
, float64
, 24, 1);
425 GEN_FCMP(fcmpeq_fcc2
, float128
, QT0
, QT1
, 24, 1);
427 GEN_FCMP_T(fcmpes_fcc3
, float32
, 26, 1);
428 GEN_FCMP_T(fcmped_fcc3
, float64
, 26, 1);
429 GEN_FCMP(fcmpeq_fcc3
, float128
, QT0
, QT1
, 26, 1);
434 static inline void set_fsr(CPUSPARCState
*env
)
438 switch (env
->fsr
& FSR_RD_MASK
) {
440 rnd_mode
= float_round_nearest_even
;
444 rnd_mode
= float_round_to_zero
;
447 rnd_mode
= float_round_up
;
450 rnd_mode
= float_round_down
;
453 set_float_rounding_mode(rnd_mode
, &env
->fp_status
);
456 void helper_ldfsr(CPUSPARCState
*env
, uint32_t new_fsr
)
458 env
->fsr
= (new_fsr
& FSR_LDFSR_MASK
) | (env
->fsr
& FSR_LDFSR_OLDMASK
);
462 #ifdef TARGET_SPARC64
463 void helper_ldxfsr(CPUSPARCState
*env
, uint64_t new_fsr
)
465 env
->fsr
= (new_fsr
& FSR_LDXFSR_MASK
) | (env
->fsr
& FSR_LDXFSR_OLDMASK
);