2 * S/390 FPU helper routines
4 * Copyright (c) 2009 Ulrich Hecht
5 * Copyright (c) 2009 Alexander Graf
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/>.
21 #include "qemu/osdep.h"
24 #include "exec/exec-all.h"
25 #include "exec/cpu_ldst.h"
26 #include "exec/helper-proto.h"
28 /* #define DEBUG_HELPER */
30 #define HELPER_LOG(x...) qemu_log(x)
32 #define HELPER_LOG(x...)
35 #define RET128(F) (env->retxl = F.low, F.high)
37 #define convert_bit(mask, from, to) \
39 ? (mask / (from / to)) & to \
40 : (mask & from) * (to / from))
42 static void ieee_exception(CPUS390XState
*env
, uint32_t dxc
, uintptr_t retaddr
)
44 /* Install the DXC code. */
45 env
->fpc
= (env
->fpc
& ~0xff00) | (dxc
<< 8);
47 s390_program_interrupt(env
, PGM_DATA
, ILEN_AUTO
, retaddr
);
50 /* Should be called after any operation that may raise IEEE exceptions. */
51 static void handle_exceptions(CPUS390XState
*env
, uintptr_t retaddr
)
53 unsigned s390_exc
, qemu_exc
;
55 /* Get the exceptions raised by the current operation. Reset the
56 fpu_status contents so that the next operation has a clean slate. */
57 qemu_exc
= env
->fpu_status
.float_exception_flags
;
61 env
->fpu_status
.float_exception_flags
= 0;
63 /* Convert softfloat exception bits to s390 exception bits. */
65 s390_exc
|= convert_bit(qemu_exc
, float_flag_invalid
, 0x80);
66 s390_exc
|= convert_bit(qemu_exc
, float_flag_divbyzero
, 0x40);
67 s390_exc
|= convert_bit(qemu_exc
, float_flag_overflow
, 0x20);
68 s390_exc
|= convert_bit(qemu_exc
, float_flag_underflow
, 0x10);
69 s390_exc
|= convert_bit(qemu_exc
, float_flag_inexact
, 0x08);
71 /* Install the exceptions that we raised. */
72 env
->fpc
|= s390_exc
<< 16;
74 /* Send signals for enabled exceptions. */
75 s390_exc
&= env
->fpc
>> 24;
77 ieee_exception(env
, s390_exc
, retaddr
);
81 static inline int float_comp_to_cc(CPUS390XState
*env
, int float_compare
)
83 S390CPU
*cpu
= s390_env_get_cpu(env
);
85 switch (float_compare
) {
86 case float_relation_equal
:
88 case float_relation_less
:
90 case float_relation_greater
:
92 case float_relation_unordered
:
95 cpu_abort(CPU(cpu
), "unknown return value for float compare\n");
99 /* condition codes for unary FP ops */
100 uint32_t set_cc_nz_f32(float32 v
)
102 if (float32_is_any_nan(v
)) {
104 } else if (float32_is_zero(v
)) {
106 } else if (float32_is_neg(v
)) {
113 uint32_t set_cc_nz_f64(float64 v
)
115 if (float64_is_any_nan(v
)) {
117 } else if (float64_is_zero(v
)) {
119 } else if (float64_is_neg(v
)) {
126 uint32_t set_cc_nz_f128(float128 v
)
128 if (float128_is_any_nan(v
)) {
130 } else if (float128_is_zero(v
)) {
132 } else if (float128_is_neg(v
)) {
139 /* 32-bit FP addition */
140 uint64_t HELPER(aeb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
142 float32 ret
= float32_add(f1
, f2
, &env
->fpu_status
);
143 handle_exceptions(env
, GETPC());
147 /* 64-bit FP addition */
148 uint64_t HELPER(adb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
150 float64 ret
= float64_add(f1
, f2
, &env
->fpu_status
);
151 handle_exceptions(env
, GETPC());
155 /* 128-bit FP addition */
156 uint64_t HELPER(axb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
157 uint64_t bh
, uint64_t bl
)
159 float128 ret
= float128_add(make_float128(ah
, al
),
160 make_float128(bh
, bl
),
162 handle_exceptions(env
, GETPC());
166 /* 32-bit FP subtraction */
167 uint64_t HELPER(seb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
169 float32 ret
= float32_sub(f1
, f2
, &env
->fpu_status
);
170 handle_exceptions(env
, GETPC());
174 /* 64-bit FP subtraction */
175 uint64_t HELPER(sdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
177 float64 ret
= float64_sub(f1
, f2
, &env
->fpu_status
);
178 handle_exceptions(env
, GETPC());
182 /* 128-bit FP subtraction */
183 uint64_t HELPER(sxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
184 uint64_t bh
, uint64_t bl
)
186 float128 ret
= float128_sub(make_float128(ah
, al
),
187 make_float128(bh
, bl
),
189 handle_exceptions(env
, GETPC());
193 /* 32-bit FP division */
194 uint64_t HELPER(deb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
196 float32 ret
= float32_div(f1
, f2
, &env
->fpu_status
);
197 handle_exceptions(env
, GETPC());
201 /* 64-bit FP division */
202 uint64_t HELPER(ddb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
204 float64 ret
= float64_div(f1
, f2
, &env
->fpu_status
);
205 handle_exceptions(env
, GETPC());
209 /* 128-bit FP division */
210 uint64_t HELPER(dxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
211 uint64_t bh
, uint64_t bl
)
213 float128 ret
= float128_div(make_float128(ah
, al
),
214 make_float128(bh
, bl
),
216 handle_exceptions(env
, GETPC());
220 /* 32-bit FP multiplication */
221 uint64_t HELPER(meeb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
223 float32 ret
= float32_mul(f1
, f2
, &env
->fpu_status
);
224 handle_exceptions(env
, GETPC());
228 /* 64-bit FP multiplication */
229 uint64_t HELPER(mdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
231 float64 ret
= float64_mul(f1
, f2
, &env
->fpu_status
);
232 handle_exceptions(env
, GETPC());
236 /* 64/32-bit FP multiplication */
237 uint64_t HELPER(mdeb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
239 float64 ret
= float32_to_float64(f2
, &env
->fpu_status
);
240 ret
= float64_mul(f1
, ret
, &env
->fpu_status
);
241 handle_exceptions(env
, GETPC());
245 /* 128-bit FP multiplication */
246 uint64_t HELPER(mxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
247 uint64_t bh
, uint64_t bl
)
249 float128 ret
= float128_mul(make_float128(ah
, al
),
250 make_float128(bh
, bl
),
252 handle_exceptions(env
, GETPC());
256 /* 128/64-bit FP multiplication */
257 uint64_t HELPER(mxdb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
260 float128 ret
= float64_to_float128(f2
, &env
->fpu_status
);
261 ret
= float128_mul(make_float128(ah
, al
), ret
, &env
->fpu_status
);
262 handle_exceptions(env
, GETPC());
266 /* convert 32-bit float to 64-bit float */
267 uint64_t HELPER(ldeb
)(CPUS390XState
*env
, uint64_t f2
)
269 float64 ret
= float32_to_float64(f2
, &env
->fpu_status
);
270 handle_exceptions(env
, GETPC());
271 return float64_maybe_silence_nan(ret
, &env
->fpu_status
);
274 /* convert 128-bit float to 64-bit float */
275 uint64_t HELPER(ldxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
)
277 float64 ret
= float128_to_float64(make_float128(ah
, al
), &env
->fpu_status
);
278 handle_exceptions(env
, GETPC());
279 return float64_maybe_silence_nan(ret
, &env
->fpu_status
);
282 /* convert 64-bit float to 128-bit float */
283 uint64_t HELPER(lxdb
)(CPUS390XState
*env
, uint64_t f2
)
285 float128 ret
= float64_to_float128(f2
, &env
->fpu_status
);
286 handle_exceptions(env
, GETPC());
287 return RET128(float128_maybe_silence_nan(ret
, &env
->fpu_status
));
290 /* convert 32-bit float to 128-bit float */
291 uint64_t HELPER(lxeb
)(CPUS390XState
*env
, uint64_t f2
)
293 float128 ret
= float32_to_float128(f2
, &env
->fpu_status
);
294 handle_exceptions(env
, GETPC());
295 return RET128(float128_maybe_silence_nan(ret
, &env
->fpu_status
));
298 /* convert 64-bit float to 32-bit float */
299 uint64_t HELPER(ledb
)(CPUS390XState
*env
, uint64_t f2
)
301 float32 ret
= float64_to_float32(f2
, &env
->fpu_status
);
302 handle_exceptions(env
, GETPC());
303 return float32_maybe_silence_nan(ret
, &env
->fpu_status
);
306 /* convert 128-bit float to 32-bit float */
307 uint64_t HELPER(lexb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
)
309 float32 ret
= float128_to_float32(make_float128(ah
, al
), &env
->fpu_status
);
310 handle_exceptions(env
, GETPC());
311 return float32_maybe_silence_nan(ret
, &env
->fpu_status
);
314 /* 32-bit FP compare */
315 uint32_t HELPER(ceb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
317 int cmp
= float32_compare_quiet(f1
, f2
, &env
->fpu_status
);
318 handle_exceptions(env
, GETPC());
319 return float_comp_to_cc(env
, cmp
);
322 /* 64-bit FP compare */
323 uint32_t HELPER(cdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
325 int cmp
= float64_compare_quiet(f1
, f2
, &env
->fpu_status
);
326 handle_exceptions(env
, GETPC());
327 return float_comp_to_cc(env
, cmp
);
330 /* 128-bit FP compare */
331 uint32_t HELPER(cxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
332 uint64_t bh
, uint64_t bl
)
334 int cmp
= float128_compare_quiet(make_float128(ah
, al
),
335 make_float128(bh
, bl
),
337 handle_exceptions(env
, GETPC());
338 return float_comp_to_cc(env
, cmp
);
341 static int swap_round_mode(CPUS390XState
*env
, int m3
)
343 int ret
= env
->fpu_status
.float_rounding_mode
;
349 /* biased round no nearest */
351 /* round to nearest */
352 set_float_rounding_mode(float_round_nearest_even
, &env
->fpu_status
);
356 set_float_rounding_mode(float_round_to_zero
, &env
->fpu_status
);
360 set_float_rounding_mode(float_round_up
, &env
->fpu_status
);
364 set_float_rounding_mode(float_round_down
, &env
->fpu_status
);
370 /* convert 64-bit int to 32-bit float */
371 uint64_t HELPER(cegb
)(CPUS390XState
*env
, int64_t v2
, uint32_t m3
)
373 int hold
= swap_round_mode(env
, m3
);
374 float32 ret
= int64_to_float32(v2
, &env
->fpu_status
);
375 set_float_rounding_mode(hold
, &env
->fpu_status
);
376 handle_exceptions(env
, GETPC());
380 /* convert 64-bit int to 64-bit float */
381 uint64_t HELPER(cdgb
)(CPUS390XState
*env
, int64_t v2
, uint32_t m3
)
383 int hold
= swap_round_mode(env
, m3
);
384 float64 ret
= int64_to_float64(v2
, &env
->fpu_status
);
385 set_float_rounding_mode(hold
, &env
->fpu_status
);
386 handle_exceptions(env
, GETPC());
390 /* convert 64-bit int to 128-bit float */
391 uint64_t HELPER(cxgb
)(CPUS390XState
*env
, int64_t v2
, uint32_t m3
)
393 int hold
= swap_round_mode(env
, m3
);
394 float128 ret
= int64_to_float128(v2
, &env
->fpu_status
);
395 set_float_rounding_mode(hold
, &env
->fpu_status
);
396 handle_exceptions(env
, GETPC());
400 /* convert 64-bit uint to 32-bit float */
401 uint64_t HELPER(celgb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
403 int hold
= swap_round_mode(env
, m3
);
404 float32 ret
= uint64_to_float32(v2
, &env
->fpu_status
);
405 set_float_rounding_mode(hold
, &env
->fpu_status
);
406 handle_exceptions(env
, GETPC());
410 /* convert 64-bit uint to 64-bit float */
411 uint64_t HELPER(cdlgb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
413 int hold
= swap_round_mode(env
, m3
);
414 float64 ret
= uint64_to_float64(v2
, &env
->fpu_status
);
415 set_float_rounding_mode(hold
, &env
->fpu_status
);
416 handle_exceptions(env
, GETPC());
420 /* convert 64-bit uint to 128-bit float */
421 uint64_t HELPER(cxlgb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
423 int hold
= swap_round_mode(env
, m3
);
424 float128 ret
= uint64_to_float128(v2
, &env
->fpu_status
);
425 set_float_rounding_mode(hold
, &env
->fpu_status
);
426 handle_exceptions(env
, GETPC());
430 /* convert 32-bit float to 64-bit int */
431 uint64_t HELPER(cgeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
433 int hold
= swap_round_mode(env
, m3
);
434 int64_t ret
= float32_to_int64(v2
, &env
->fpu_status
);
435 set_float_rounding_mode(hold
, &env
->fpu_status
);
436 handle_exceptions(env
, GETPC());
440 /* convert 64-bit float to 64-bit int */
441 uint64_t HELPER(cgdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
443 int hold
= swap_round_mode(env
, m3
);
444 int64_t ret
= float64_to_int64(v2
, &env
->fpu_status
);
445 set_float_rounding_mode(hold
, &env
->fpu_status
);
446 handle_exceptions(env
, GETPC());
450 /* convert 128-bit float to 64-bit int */
451 uint64_t HELPER(cgxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
453 int hold
= swap_round_mode(env
, m3
);
454 float128 v2
= make_float128(h
, l
);
455 int64_t ret
= float128_to_int64(v2
, &env
->fpu_status
);
456 set_float_rounding_mode(hold
, &env
->fpu_status
);
457 handle_exceptions(env
, GETPC());
461 /* convert 32-bit float to 32-bit int */
462 uint64_t HELPER(cfeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
464 int hold
= swap_round_mode(env
, m3
);
465 int32_t ret
= float32_to_int32(v2
, &env
->fpu_status
);
466 set_float_rounding_mode(hold
, &env
->fpu_status
);
467 handle_exceptions(env
, GETPC());
471 /* convert 64-bit float to 32-bit int */
472 uint64_t HELPER(cfdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
474 int hold
= swap_round_mode(env
, m3
);
475 int32_t ret
= float64_to_int32(v2
, &env
->fpu_status
);
476 set_float_rounding_mode(hold
, &env
->fpu_status
);
477 handle_exceptions(env
, GETPC());
481 /* convert 128-bit float to 32-bit int */
482 uint64_t HELPER(cfxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
484 int hold
= swap_round_mode(env
, m3
);
485 float128 v2
= make_float128(h
, l
);
486 int32_t ret
= float128_to_int32(v2
, &env
->fpu_status
);
487 set_float_rounding_mode(hold
, &env
->fpu_status
);
488 handle_exceptions(env
, GETPC());
492 /* convert 32-bit float to 64-bit uint */
493 uint64_t HELPER(clgeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
495 int hold
= swap_round_mode(env
, m3
);
497 v2
= float32_to_float64(v2
, &env
->fpu_status
);
498 ret
= float64_to_uint64(v2
, &env
->fpu_status
);
499 set_float_rounding_mode(hold
, &env
->fpu_status
);
500 handle_exceptions(env
, GETPC());
504 /* convert 64-bit float to 64-bit uint */
505 uint64_t HELPER(clgdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
507 int hold
= swap_round_mode(env
, m3
);
508 uint64_t ret
= float64_to_uint64(v2
, &env
->fpu_status
);
509 set_float_rounding_mode(hold
, &env
->fpu_status
);
510 handle_exceptions(env
, GETPC());
514 /* convert 128-bit float to 64-bit uint */
515 uint64_t HELPER(clgxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
517 int hold
= swap_round_mode(env
, m3
);
518 float128 v2
= make_float128(h
, l
);
519 /* ??? Not 100% correct. */
520 uint64_t ret
= float128_to_int64(v2
, &env
->fpu_status
);
521 set_float_rounding_mode(hold
, &env
->fpu_status
);
522 handle_exceptions(env
, GETPC());
526 /* convert 32-bit float to 32-bit uint */
527 uint64_t HELPER(clfeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
529 int hold
= swap_round_mode(env
, m3
);
530 uint32_t ret
= float32_to_uint32(v2
, &env
->fpu_status
);
531 set_float_rounding_mode(hold
, &env
->fpu_status
);
532 handle_exceptions(env
, GETPC());
536 /* convert 64-bit float to 32-bit uint */
537 uint64_t HELPER(clfdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
539 int hold
= swap_round_mode(env
, m3
);
540 uint32_t ret
= float64_to_uint32(v2
, &env
->fpu_status
);
541 set_float_rounding_mode(hold
, &env
->fpu_status
);
542 handle_exceptions(env
, GETPC());
546 /* convert 128-bit float to 32-bit uint */
547 uint64_t HELPER(clfxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
549 int hold
= swap_round_mode(env
, m3
);
550 float128 v2
= make_float128(h
, l
);
551 /* Not 100% correct. */
552 uint32_t ret
= float128_to_int64(v2
, &env
->fpu_status
);
553 set_float_rounding_mode(hold
, &env
->fpu_status
);
554 handle_exceptions(env
, GETPC());
558 /* round to integer 32-bit */
559 uint64_t HELPER(fieb
)(CPUS390XState
*env
, uint64_t f2
, uint32_t m3
)
561 int hold
= swap_round_mode(env
, m3
);
562 float32 ret
= float32_round_to_int(f2
, &env
->fpu_status
);
563 set_float_rounding_mode(hold
, &env
->fpu_status
);
564 handle_exceptions(env
, GETPC());
568 /* round to integer 64-bit */
569 uint64_t HELPER(fidb
)(CPUS390XState
*env
, uint64_t f2
, uint32_t m3
)
571 int hold
= swap_round_mode(env
, m3
);
572 float64 ret
= float64_round_to_int(f2
, &env
->fpu_status
);
573 set_float_rounding_mode(hold
, &env
->fpu_status
);
574 handle_exceptions(env
, GETPC());
578 /* round to integer 128-bit */
579 uint64_t HELPER(fixb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
, uint32_t m3
)
581 int hold
= swap_round_mode(env
, m3
);
582 float128 ret
= float128_round_to_int(make_float128(ah
, al
),
584 set_float_rounding_mode(hold
, &env
->fpu_status
);
585 handle_exceptions(env
, GETPC());
589 /* 32-bit FP compare and signal */
590 uint32_t HELPER(keb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
592 int cmp
= float32_compare(f1
, f2
, &env
->fpu_status
);
593 handle_exceptions(env
, GETPC());
594 return float_comp_to_cc(env
, cmp
);
597 /* 64-bit FP compare and signal */
598 uint32_t HELPER(kdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
600 int cmp
= float64_compare(f1
, f2
, &env
->fpu_status
);
601 handle_exceptions(env
, GETPC());
602 return float_comp_to_cc(env
, cmp
);
605 /* 128-bit FP compare and signal */
606 uint32_t HELPER(kxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
607 uint64_t bh
, uint64_t bl
)
609 int cmp
= float128_compare(make_float128(ah
, al
),
610 make_float128(bh
, bl
),
612 handle_exceptions(env
, GETPC());
613 return float_comp_to_cc(env
, cmp
);
616 /* 32-bit FP multiply and add */
617 uint64_t HELPER(maeb
)(CPUS390XState
*env
, uint64_t f1
,
618 uint64_t f2
, uint64_t f3
)
620 float32 ret
= float32_muladd(f2
, f3
, f1
, 0, &env
->fpu_status
);
621 handle_exceptions(env
, GETPC());
625 /* 64-bit FP multiply and add */
626 uint64_t HELPER(madb
)(CPUS390XState
*env
, uint64_t f1
,
627 uint64_t f2
, uint64_t f3
)
629 float64 ret
= float64_muladd(f2
, f3
, f1
, 0, &env
->fpu_status
);
630 handle_exceptions(env
, GETPC());
634 /* 32-bit FP multiply and subtract */
635 uint64_t HELPER(mseb
)(CPUS390XState
*env
, uint64_t f1
,
636 uint64_t f2
, uint64_t f3
)
638 float32 ret
= float32_muladd(f2
, f3
, f1
, float_muladd_negate_c
,
640 handle_exceptions(env
, GETPC());
644 /* 64-bit FP multiply and subtract */
645 uint64_t HELPER(msdb
)(CPUS390XState
*env
, uint64_t f1
,
646 uint64_t f2
, uint64_t f3
)
648 float64 ret
= float64_muladd(f2
, f3
, f1
, float_muladd_negate_c
,
650 handle_exceptions(env
, GETPC());
654 /* test data class 32-bit */
655 uint32_t HELPER(tceb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t m2
)
658 int neg
= float32_is_neg(v1
);
661 if ((float32_is_zero(v1
) && (m2
& (1 << (11-neg
)))) ||
662 (float32_is_infinity(v1
) && (m2
& (1 << (5-neg
)))) ||
663 (float32_is_any_nan(v1
) && (m2
& (1 << (3-neg
)))) ||
664 (float32_is_signaling_nan(v1
, &env
->fpu_status
) &&
665 (m2
& (1 << (1-neg
))))) {
667 } else if (m2
& (1 << (9-neg
))) {
668 /* assume normalized number */
671 /* FIXME: denormalized? */
675 /* test data class 64-bit */
676 uint32_t HELPER(tcdb
)(CPUS390XState
*env
, uint64_t v1
, uint64_t m2
)
678 int neg
= float64_is_neg(v1
);
681 if ((float64_is_zero(v1
) && (m2
& (1 << (11-neg
)))) ||
682 (float64_is_infinity(v1
) && (m2
& (1 << (5-neg
)))) ||
683 (float64_is_any_nan(v1
) && (m2
& (1 << (3-neg
)))) ||
684 (float64_is_signaling_nan(v1
, &env
->fpu_status
) &&
685 (m2
& (1 << (1-neg
))))) {
687 } else if (m2
& (1 << (9-neg
))) {
688 /* assume normalized number */
691 /* FIXME: denormalized? */
695 /* test data class 128-bit */
696 uint32_t HELPER(tcxb
)(CPUS390XState
*env
, uint64_t ah
,
697 uint64_t al
, uint64_t m2
)
699 float128 v1
= make_float128(ah
, al
);
700 int neg
= float128_is_neg(v1
);
703 if ((float128_is_zero(v1
) && (m2
& (1 << (11-neg
)))) ||
704 (float128_is_infinity(v1
) && (m2
& (1 << (5-neg
)))) ||
705 (float128_is_any_nan(v1
) && (m2
& (1 << (3-neg
)))) ||
706 (float128_is_signaling_nan(v1
, &env
->fpu_status
) &&
707 (m2
& (1 << (1-neg
))))) {
709 } else if (m2
& (1 << (9-neg
))) {
710 /* assume normalized number */
713 /* FIXME: denormalized? */
717 /* square root 32-bit */
718 uint64_t HELPER(sqeb
)(CPUS390XState
*env
, uint64_t f2
)
720 float32 ret
= float32_sqrt(f2
, &env
->fpu_status
);
721 handle_exceptions(env
, GETPC());
725 /* square root 64-bit */
726 uint64_t HELPER(sqdb
)(CPUS390XState
*env
, uint64_t f2
)
728 float64 ret
= float64_sqrt(f2
, &env
->fpu_status
);
729 handle_exceptions(env
, GETPC());
733 /* square root 128-bit */
734 uint64_t HELPER(sqxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
)
736 float128 ret
= float128_sqrt(make_float128(ah
, al
), &env
->fpu_status
);
737 handle_exceptions(env
, GETPC());
741 static const int fpc_to_rnd
[4] = {
742 float_round_nearest_even
,
749 void HELPER(sfpc
)(CPUS390XState
*env
, uint64_t fpc
)
751 /* Install everything in the main FPC. */
754 /* Install the rounding mode in the shadow fpu_status. */
755 set_float_rounding_mode(fpc_to_rnd
[fpc
& 3], &env
->fpu_status
);
758 /* set fpc and signal */
759 void HELPER(sfas
)(CPUS390XState
*env
, uint64_t val
)
761 uint32_t signalling
= env
->fpc
;
762 uint32_t source
= val
;
765 /* The contents of the source operand are placed in the FPC register;
766 then the flags in the FPC register are set to the logical OR of the
767 signalling flags and the source flags. */
768 env
->fpc
= source
| (signalling
& 0x00ff0000);
769 set_float_rounding_mode(fpc_to_rnd
[source
& 3], &env
->fpu_status
);
771 /* If any signalling flag is 1 and the corresponding source mask
772 is also 1, a simulated-iee-exception trap occurs. */
773 s390_exc
= (signalling
>> 16) & (source
>> 24);
775 ieee_exception(env
, s390_exc
| 3, GETPC());