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.1 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 "tcg_s390x.h"
25 #include "exec/exec-all.h"
26 #include "exec/cpu_ldst.h"
27 #include "exec/helper-proto.h"
28 #include "fpu/softfloat.h"
30 /* #define DEBUG_HELPER */
32 #define HELPER_LOG(x...) qemu_log(x)
34 #define HELPER_LOG(x...)
37 #define RET128(F) (env->retxl = F.low, F.high)
39 #define convert_bit(mask, from, to) \
41 ? (mask / (from / to)) & to \
42 : (mask & from) * (to / from))
44 /* Should be called after any operation that may raise IEEE exceptions. */
45 static void handle_exceptions(CPUS390XState
*env
, uintptr_t retaddr
)
47 unsigned s390_exc
, qemu_exc
;
49 /* Get the exceptions raised by the current operation. Reset the
50 fpu_status contents so that the next operation has a clean slate. */
51 qemu_exc
= env
->fpu_status
.float_exception_flags
;
55 env
->fpu_status
.float_exception_flags
= 0;
57 /* Convert softfloat exception bits to s390 exception bits. */
59 s390_exc
|= convert_bit(qemu_exc
, float_flag_invalid
, 0x80);
60 s390_exc
|= convert_bit(qemu_exc
, float_flag_divbyzero
, 0x40);
61 s390_exc
|= convert_bit(qemu_exc
, float_flag_overflow
, 0x20);
62 s390_exc
|= convert_bit(qemu_exc
, float_flag_underflow
, 0x10);
63 s390_exc
|= convert_bit(qemu_exc
, float_flag_inexact
, 0x08);
65 /* Install the exceptions that we raised. */
66 env
->fpc
|= s390_exc
<< 16;
68 /* Send signals for enabled exceptions. */
69 s390_exc
&= env
->fpc
>> 24;
71 tcg_s390_data_exception(env
, s390_exc
, retaddr
);
75 static inline int float_comp_to_cc(CPUS390XState
*env
, int float_compare
)
77 S390CPU
*cpu
= s390_env_get_cpu(env
);
79 switch (float_compare
) {
80 case float_relation_equal
:
82 case float_relation_less
:
84 case float_relation_greater
:
86 case float_relation_unordered
:
89 cpu_abort(CPU(cpu
), "unknown return value for float compare\n");
93 /* condition codes for unary FP ops */
94 uint32_t set_cc_nz_f32(float32 v
)
96 if (float32_is_any_nan(v
)) {
98 } else if (float32_is_zero(v
)) {
100 } else if (float32_is_neg(v
)) {
107 uint32_t set_cc_nz_f64(float64 v
)
109 if (float64_is_any_nan(v
)) {
111 } else if (float64_is_zero(v
)) {
113 } else if (float64_is_neg(v
)) {
120 uint32_t set_cc_nz_f128(float128 v
)
122 if (float128_is_any_nan(v
)) {
124 } else if (float128_is_zero(v
)) {
126 } else if (float128_is_neg(v
)) {
133 /* 32-bit FP addition */
134 uint64_t HELPER(aeb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
136 float32 ret
= float32_add(f1
, f2
, &env
->fpu_status
);
137 handle_exceptions(env
, GETPC());
141 /* 64-bit FP addition */
142 uint64_t HELPER(adb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
144 float64 ret
= float64_add(f1
, f2
, &env
->fpu_status
);
145 handle_exceptions(env
, GETPC());
149 /* 128-bit FP addition */
150 uint64_t HELPER(axb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
151 uint64_t bh
, uint64_t bl
)
153 float128 ret
= float128_add(make_float128(ah
, al
),
154 make_float128(bh
, bl
),
156 handle_exceptions(env
, GETPC());
160 /* 32-bit FP subtraction */
161 uint64_t HELPER(seb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
163 float32 ret
= float32_sub(f1
, f2
, &env
->fpu_status
);
164 handle_exceptions(env
, GETPC());
168 /* 64-bit FP subtraction */
169 uint64_t HELPER(sdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
171 float64 ret
= float64_sub(f1
, f2
, &env
->fpu_status
);
172 handle_exceptions(env
, GETPC());
176 /* 128-bit FP subtraction */
177 uint64_t HELPER(sxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
178 uint64_t bh
, uint64_t bl
)
180 float128 ret
= float128_sub(make_float128(ah
, al
),
181 make_float128(bh
, bl
),
183 handle_exceptions(env
, GETPC());
187 /* 32-bit FP division */
188 uint64_t HELPER(deb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
190 float32 ret
= float32_div(f1
, f2
, &env
->fpu_status
);
191 handle_exceptions(env
, GETPC());
195 /* 64-bit FP division */
196 uint64_t HELPER(ddb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
198 float64 ret
= float64_div(f1
, f2
, &env
->fpu_status
);
199 handle_exceptions(env
, GETPC());
203 /* 128-bit FP division */
204 uint64_t HELPER(dxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
205 uint64_t bh
, uint64_t bl
)
207 float128 ret
= float128_div(make_float128(ah
, al
),
208 make_float128(bh
, bl
),
210 handle_exceptions(env
, GETPC());
214 /* 32-bit FP multiplication */
215 uint64_t HELPER(meeb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
217 float32 ret
= float32_mul(f1
, f2
, &env
->fpu_status
);
218 handle_exceptions(env
, GETPC());
222 /* 64-bit FP multiplication */
223 uint64_t HELPER(mdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
225 float64 ret
= float64_mul(f1
, f2
, &env
->fpu_status
);
226 handle_exceptions(env
, GETPC());
230 /* 64/32-bit FP multiplication */
231 uint64_t HELPER(mdeb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
233 float64 ret
= float32_to_float64(f2
, &env
->fpu_status
);
234 ret
= float64_mul(f1
, ret
, &env
->fpu_status
);
235 handle_exceptions(env
, GETPC());
239 /* 128-bit FP multiplication */
240 uint64_t HELPER(mxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
241 uint64_t bh
, uint64_t bl
)
243 float128 ret
= float128_mul(make_float128(ah
, al
),
244 make_float128(bh
, bl
),
246 handle_exceptions(env
, GETPC());
250 /* 128/64-bit FP multiplication */
251 uint64_t HELPER(mxdb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
254 float128 ret
= float64_to_float128(f2
, &env
->fpu_status
);
255 ret
= float128_mul(make_float128(ah
, al
), ret
, &env
->fpu_status
);
256 handle_exceptions(env
, GETPC());
260 /* convert 32-bit float to 64-bit float */
261 uint64_t HELPER(ldeb
)(CPUS390XState
*env
, uint64_t f2
)
263 float64 ret
= float32_to_float64(f2
, &env
->fpu_status
);
264 handle_exceptions(env
, GETPC());
268 /* convert 128-bit float to 64-bit float */
269 uint64_t HELPER(ldxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
)
271 float64 ret
= float128_to_float64(make_float128(ah
, al
), &env
->fpu_status
);
272 handle_exceptions(env
, GETPC());
276 /* convert 64-bit float to 128-bit float */
277 uint64_t HELPER(lxdb
)(CPUS390XState
*env
, uint64_t f2
)
279 float128 ret
= float64_to_float128(f2
, &env
->fpu_status
);
280 handle_exceptions(env
, GETPC());
284 /* convert 32-bit float to 128-bit float */
285 uint64_t HELPER(lxeb
)(CPUS390XState
*env
, uint64_t f2
)
287 float128 ret
= float32_to_float128(f2
, &env
->fpu_status
);
288 handle_exceptions(env
, GETPC());
292 /* convert 64-bit float to 32-bit float */
293 uint64_t HELPER(ledb
)(CPUS390XState
*env
, uint64_t f2
)
295 float32 ret
= float64_to_float32(f2
, &env
->fpu_status
);
296 handle_exceptions(env
, GETPC());
300 /* convert 128-bit float to 32-bit float */
301 uint64_t HELPER(lexb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
)
303 float32 ret
= float128_to_float32(make_float128(ah
, al
), &env
->fpu_status
);
304 handle_exceptions(env
, GETPC());
308 /* 32-bit FP compare */
309 uint32_t HELPER(ceb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
311 int cmp
= float32_compare_quiet(f1
, f2
, &env
->fpu_status
);
312 handle_exceptions(env
, GETPC());
313 return float_comp_to_cc(env
, cmp
);
316 /* 64-bit FP compare */
317 uint32_t HELPER(cdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
319 int cmp
= float64_compare_quiet(f1
, f2
, &env
->fpu_status
);
320 handle_exceptions(env
, GETPC());
321 return float_comp_to_cc(env
, cmp
);
324 /* 128-bit FP compare */
325 uint32_t HELPER(cxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
326 uint64_t bh
, uint64_t bl
)
328 int cmp
= float128_compare_quiet(make_float128(ah
, al
),
329 make_float128(bh
, bl
),
331 handle_exceptions(env
, GETPC());
332 return float_comp_to_cc(env
, cmp
);
335 static int swap_round_mode(CPUS390XState
*env
, int m3
)
337 int ret
= env
->fpu_status
.float_rounding_mode
;
343 /* biased round no nearest */
345 /* round to nearest */
346 set_float_rounding_mode(float_round_nearest_even
, &env
->fpu_status
);
350 set_float_rounding_mode(float_round_to_zero
, &env
->fpu_status
);
354 set_float_rounding_mode(float_round_up
, &env
->fpu_status
);
358 set_float_rounding_mode(float_round_down
, &env
->fpu_status
);
364 /* convert 64-bit int to 32-bit float */
365 uint64_t HELPER(cegb
)(CPUS390XState
*env
, int64_t v2
, uint32_t m3
)
367 int hold
= swap_round_mode(env
, m3
);
368 float32 ret
= int64_to_float32(v2
, &env
->fpu_status
);
369 set_float_rounding_mode(hold
, &env
->fpu_status
);
370 handle_exceptions(env
, GETPC());
374 /* convert 64-bit int to 64-bit float */
375 uint64_t HELPER(cdgb
)(CPUS390XState
*env
, int64_t v2
, uint32_t m3
)
377 int hold
= swap_round_mode(env
, m3
);
378 float64 ret
= int64_to_float64(v2
, &env
->fpu_status
);
379 set_float_rounding_mode(hold
, &env
->fpu_status
);
380 handle_exceptions(env
, GETPC());
384 /* convert 64-bit int to 128-bit float */
385 uint64_t HELPER(cxgb
)(CPUS390XState
*env
, int64_t v2
, uint32_t m3
)
387 int hold
= swap_round_mode(env
, m3
);
388 float128 ret
= int64_to_float128(v2
, &env
->fpu_status
);
389 set_float_rounding_mode(hold
, &env
->fpu_status
);
390 handle_exceptions(env
, GETPC());
394 /* convert 64-bit uint to 32-bit float */
395 uint64_t HELPER(celgb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
397 int hold
= swap_round_mode(env
, m3
);
398 float32 ret
= uint64_to_float32(v2
, &env
->fpu_status
);
399 set_float_rounding_mode(hold
, &env
->fpu_status
);
400 handle_exceptions(env
, GETPC());
404 /* convert 64-bit uint to 64-bit float */
405 uint64_t HELPER(cdlgb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
407 int hold
= swap_round_mode(env
, m3
);
408 float64 ret
= uint64_to_float64(v2
, &env
->fpu_status
);
409 set_float_rounding_mode(hold
, &env
->fpu_status
);
410 handle_exceptions(env
, GETPC());
414 /* convert 64-bit uint to 128-bit float */
415 uint64_t HELPER(cxlgb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
417 int hold
= swap_round_mode(env
, m3
);
418 float128 ret
= uint64_to_float128(v2
, &env
->fpu_status
);
419 set_float_rounding_mode(hold
, &env
->fpu_status
);
420 handle_exceptions(env
, GETPC());
424 /* convert 32-bit float to 64-bit int */
425 uint64_t HELPER(cgeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
427 int hold
= swap_round_mode(env
, m3
);
428 int64_t ret
= float32_to_int64(v2
, &env
->fpu_status
);
429 set_float_rounding_mode(hold
, &env
->fpu_status
);
430 handle_exceptions(env
, GETPC());
434 /* convert 64-bit float to 64-bit int */
435 uint64_t HELPER(cgdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
437 int hold
= swap_round_mode(env
, m3
);
438 int64_t ret
= float64_to_int64(v2
, &env
->fpu_status
);
439 set_float_rounding_mode(hold
, &env
->fpu_status
);
440 handle_exceptions(env
, GETPC());
444 /* convert 128-bit float to 64-bit int */
445 uint64_t HELPER(cgxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
447 int hold
= swap_round_mode(env
, m3
);
448 float128 v2
= make_float128(h
, l
);
449 int64_t ret
= float128_to_int64(v2
, &env
->fpu_status
);
450 set_float_rounding_mode(hold
, &env
->fpu_status
);
451 handle_exceptions(env
, GETPC());
455 /* convert 32-bit float to 32-bit int */
456 uint64_t HELPER(cfeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
458 int hold
= swap_round_mode(env
, m3
);
459 int32_t ret
= float32_to_int32(v2
, &env
->fpu_status
);
460 set_float_rounding_mode(hold
, &env
->fpu_status
);
461 handle_exceptions(env
, GETPC());
465 /* convert 64-bit float to 32-bit int */
466 uint64_t HELPER(cfdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
468 int hold
= swap_round_mode(env
, m3
);
469 int32_t ret
= float64_to_int32(v2
, &env
->fpu_status
);
470 set_float_rounding_mode(hold
, &env
->fpu_status
);
471 handle_exceptions(env
, GETPC());
475 /* convert 128-bit float to 32-bit int */
476 uint64_t HELPER(cfxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
478 int hold
= swap_round_mode(env
, m3
);
479 float128 v2
= make_float128(h
, l
);
480 int32_t ret
= float128_to_int32(v2
, &env
->fpu_status
);
481 set_float_rounding_mode(hold
, &env
->fpu_status
);
482 handle_exceptions(env
, GETPC());
486 /* convert 32-bit float to 64-bit uint */
487 uint64_t HELPER(clgeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
489 int hold
= swap_round_mode(env
, m3
);
491 v2
= float32_to_float64(v2
, &env
->fpu_status
);
492 ret
= float64_to_uint64(v2
, &env
->fpu_status
);
493 set_float_rounding_mode(hold
, &env
->fpu_status
);
494 handle_exceptions(env
, GETPC());
498 /* convert 64-bit float to 64-bit uint */
499 uint64_t HELPER(clgdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
501 int hold
= swap_round_mode(env
, m3
);
502 uint64_t ret
= float64_to_uint64(v2
, &env
->fpu_status
);
503 set_float_rounding_mode(hold
, &env
->fpu_status
);
504 handle_exceptions(env
, GETPC());
508 /* convert 128-bit float to 64-bit uint */
509 uint64_t HELPER(clgxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
511 int hold
= swap_round_mode(env
, m3
);
512 float128 v2
= make_float128(h
, l
);
513 /* ??? Not 100% correct. */
514 uint64_t ret
= float128_to_int64(v2
, &env
->fpu_status
);
515 set_float_rounding_mode(hold
, &env
->fpu_status
);
516 handle_exceptions(env
, GETPC());
520 /* convert 32-bit float to 32-bit uint */
521 uint64_t HELPER(clfeb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
523 int hold
= swap_round_mode(env
, m3
);
524 uint32_t ret
= float32_to_uint32(v2
, &env
->fpu_status
);
525 set_float_rounding_mode(hold
, &env
->fpu_status
);
526 handle_exceptions(env
, GETPC());
530 /* convert 64-bit float to 32-bit uint */
531 uint64_t HELPER(clfdb
)(CPUS390XState
*env
, uint64_t v2
, uint32_t m3
)
533 int hold
= swap_round_mode(env
, m3
);
534 uint32_t ret
= float64_to_uint32(v2
, &env
->fpu_status
);
535 set_float_rounding_mode(hold
, &env
->fpu_status
);
536 handle_exceptions(env
, GETPC());
540 /* convert 128-bit float to 32-bit uint */
541 uint64_t HELPER(clfxb
)(CPUS390XState
*env
, uint64_t h
, uint64_t l
, uint32_t m3
)
543 int hold
= swap_round_mode(env
, m3
);
544 float128 v2
= make_float128(h
, l
);
545 /* Not 100% correct. */
546 uint32_t ret
= float128_to_int64(v2
, &env
->fpu_status
);
547 set_float_rounding_mode(hold
, &env
->fpu_status
);
548 handle_exceptions(env
, GETPC());
552 /* round to integer 32-bit */
553 uint64_t HELPER(fieb
)(CPUS390XState
*env
, uint64_t f2
, uint32_t m3
)
555 int hold
= swap_round_mode(env
, m3
);
556 float32 ret
= float32_round_to_int(f2
, &env
->fpu_status
);
557 set_float_rounding_mode(hold
, &env
->fpu_status
);
558 handle_exceptions(env
, GETPC());
562 /* round to integer 64-bit */
563 uint64_t HELPER(fidb
)(CPUS390XState
*env
, uint64_t f2
, uint32_t m3
)
565 int hold
= swap_round_mode(env
, m3
);
566 float64 ret
= float64_round_to_int(f2
, &env
->fpu_status
);
567 set_float_rounding_mode(hold
, &env
->fpu_status
);
568 handle_exceptions(env
, GETPC());
572 /* round to integer 128-bit */
573 uint64_t HELPER(fixb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
, uint32_t m3
)
575 int hold
= swap_round_mode(env
, m3
);
576 float128 ret
= float128_round_to_int(make_float128(ah
, al
),
578 set_float_rounding_mode(hold
, &env
->fpu_status
);
579 handle_exceptions(env
, GETPC());
583 /* 32-bit FP compare and signal */
584 uint32_t HELPER(keb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
586 int cmp
= float32_compare(f1
, f2
, &env
->fpu_status
);
587 handle_exceptions(env
, GETPC());
588 return float_comp_to_cc(env
, cmp
);
591 /* 64-bit FP compare and signal */
592 uint32_t HELPER(kdb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t f2
)
594 int cmp
= float64_compare(f1
, f2
, &env
->fpu_status
);
595 handle_exceptions(env
, GETPC());
596 return float_comp_to_cc(env
, cmp
);
599 /* 128-bit FP compare and signal */
600 uint32_t HELPER(kxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
,
601 uint64_t bh
, uint64_t bl
)
603 int cmp
= float128_compare(make_float128(ah
, al
),
604 make_float128(bh
, bl
),
606 handle_exceptions(env
, GETPC());
607 return float_comp_to_cc(env
, cmp
);
610 /* 32-bit FP multiply and add */
611 uint64_t HELPER(maeb
)(CPUS390XState
*env
, uint64_t f1
,
612 uint64_t f2
, uint64_t f3
)
614 float32 ret
= float32_muladd(f2
, f3
, f1
, 0, &env
->fpu_status
);
615 handle_exceptions(env
, GETPC());
619 /* 64-bit FP multiply and add */
620 uint64_t HELPER(madb
)(CPUS390XState
*env
, uint64_t f1
,
621 uint64_t f2
, uint64_t f3
)
623 float64 ret
= float64_muladd(f2
, f3
, f1
, 0, &env
->fpu_status
);
624 handle_exceptions(env
, GETPC());
628 /* 32-bit FP multiply and subtract */
629 uint64_t HELPER(mseb
)(CPUS390XState
*env
, uint64_t f1
,
630 uint64_t f2
, uint64_t f3
)
632 float32 ret
= float32_muladd(f2
, f3
, f1
, float_muladd_negate_c
,
634 handle_exceptions(env
, GETPC());
638 /* 64-bit FP multiply and subtract */
639 uint64_t HELPER(msdb
)(CPUS390XState
*env
, uint64_t f1
,
640 uint64_t f2
, uint64_t f3
)
642 float64 ret
= float64_muladd(f2
, f3
, f1
, float_muladd_negate_c
,
644 handle_exceptions(env
, GETPC());
648 /* test data class 32-bit */
649 uint32_t HELPER(tceb
)(CPUS390XState
*env
, uint64_t f1
, uint64_t m2
)
652 int neg
= float32_is_neg(v1
);
655 if ((float32_is_zero(v1
) && (m2
& (1 << (11-neg
)))) ||
656 (float32_is_infinity(v1
) && (m2
& (1 << (5-neg
)))) ||
657 (float32_is_any_nan(v1
) && (m2
& (1 << (3-neg
)))) ||
658 (float32_is_signaling_nan(v1
, &env
->fpu_status
) &&
659 (m2
& (1 << (1-neg
))))) {
661 } else if (m2
& (1 << (9-neg
))) {
662 /* assume normalized number */
665 /* FIXME: denormalized? */
669 /* test data class 64-bit */
670 uint32_t HELPER(tcdb
)(CPUS390XState
*env
, uint64_t v1
, uint64_t m2
)
672 int neg
= float64_is_neg(v1
);
675 if ((float64_is_zero(v1
) && (m2
& (1 << (11-neg
)))) ||
676 (float64_is_infinity(v1
) && (m2
& (1 << (5-neg
)))) ||
677 (float64_is_any_nan(v1
) && (m2
& (1 << (3-neg
)))) ||
678 (float64_is_signaling_nan(v1
, &env
->fpu_status
) &&
679 (m2
& (1 << (1-neg
))))) {
681 } else if (m2
& (1 << (9-neg
))) {
682 /* assume normalized number */
685 /* FIXME: denormalized? */
689 /* test data class 128-bit */
690 uint32_t HELPER(tcxb
)(CPUS390XState
*env
, uint64_t ah
,
691 uint64_t al
, uint64_t m2
)
693 float128 v1
= make_float128(ah
, al
);
694 int neg
= float128_is_neg(v1
);
697 if ((float128_is_zero(v1
) && (m2
& (1 << (11-neg
)))) ||
698 (float128_is_infinity(v1
) && (m2
& (1 << (5-neg
)))) ||
699 (float128_is_any_nan(v1
) && (m2
& (1 << (3-neg
)))) ||
700 (float128_is_signaling_nan(v1
, &env
->fpu_status
) &&
701 (m2
& (1 << (1-neg
))))) {
703 } else if (m2
& (1 << (9-neg
))) {
704 /* assume normalized number */
707 /* FIXME: denormalized? */
711 /* square root 32-bit */
712 uint64_t HELPER(sqeb
)(CPUS390XState
*env
, uint64_t f2
)
714 float32 ret
= float32_sqrt(f2
, &env
->fpu_status
);
715 handle_exceptions(env
, GETPC());
719 /* square root 64-bit */
720 uint64_t HELPER(sqdb
)(CPUS390XState
*env
, uint64_t f2
)
722 float64 ret
= float64_sqrt(f2
, &env
->fpu_status
);
723 handle_exceptions(env
, GETPC());
727 /* square root 128-bit */
728 uint64_t HELPER(sqxb
)(CPUS390XState
*env
, uint64_t ah
, uint64_t al
)
730 float128 ret
= float128_sqrt(make_float128(ah
, al
), &env
->fpu_status
);
731 handle_exceptions(env
, GETPC());
735 static const int fpc_to_rnd
[4] = {
736 float_round_nearest_even
,
743 void HELPER(sfpc
)(CPUS390XState
*env
, uint64_t fpc
)
745 /* Install everything in the main FPC. */
748 /* Install the rounding mode in the shadow fpu_status. */
749 set_float_rounding_mode(fpc_to_rnd
[fpc
& 3], &env
->fpu_status
);
752 /* set fpc and signal */
753 void HELPER(sfas
)(CPUS390XState
*env
, uint64_t val
)
755 uint32_t signalling
= env
->fpc
;
756 uint32_t source
= val
;
759 /* The contents of the source operand are placed in the FPC register;
760 then the flags in the FPC register are set to the logical OR of the
761 signalling flags and the source flags. */
762 env
->fpc
= source
| (signalling
& 0x00ff0000);
763 set_float_rounding_mode(fpc_to_rnd
[source
& 3], &env
->fpu_status
);
765 /* If any signalling flag is 1 and the corresponding source mask
766 is also 1, a simulated-iee-exception trap occurs. */
767 s390_exc
= (signalling
>> 16) & (source
>> 24);
769 tcg_s390_data_exception(env
, s390_exc
| 3, GETPC());