Merge remote-tracking branch 'remotes/kvaneesh/for-upstream' into staging
[qemu/qmp-unstable.git] / target-s390x / fpu_helper.c
blobb946ec1d5143c4e198b74f41c5e1644c7d2ffba1
1 /*
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 "cpu.h"
22 #include "exec/cpu_ldst.h"
23 #include "exec/helper-proto.h"
25 /* #define DEBUG_HELPER */
26 #ifdef DEBUG_HELPER
27 #define HELPER_LOG(x...) qemu_log(x)
28 #else
29 #define HELPER_LOG(x...)
30 #endif
32 #define RET128(F) (env->retxl = F.low, F.high)
34 #define convert_bit(mask, from, to) \
35 (to < from \
36 ? (mask / (from / to)) & to \
37 : (mask & from) * (to / from))
39 static void ieee_exception(CPUS390XState *env, uint32_t dxc, uintptr_t retaddr)
41 /* Install the DXC code. */
42 env->fpc = (env->fpc & ~0xff00) | (dxc << 8);
43 /* Trap. */
44 runtime_exception(env, PGM_DATA, retaddr);
47 /* Should be called after any operation that may raise IEEE exceptions. */
48 static void handle_exceptions(CPUS390XState *env, uintptr_t retaddr)
50 unsigned s390_exc, qemu_exc;
52 /* Get the exceptions raised by the current operation. Reset the
53 fpu_status contents so that the next operation has a clean slate. */
54 qemu_exc = env->fpu_status.float_exception_flags;
55 if (qemu_exc == 0) {
56 return;
58 env->fpu_status.float_exception_flags = 0;
60 /* Convert softfloat exception bits to s390 exception bits. */
61 s390_exc = 0;
62 s390_exc |= convert_bit(qemu_exc, float_flag_invalid, 0x80);
63 s390_exc |= convert_bit(qemu_exc, float_flag_divbyzero, 0x40);
64 s390_exc |= convert_bit(qemu_exc, float_flag_overflow, 0x20);
65 s390_exc |= convert_bit(qemu_exc, float_flag_underflow, 0x10);
66 s390_exc |= convert_bit(qemu_exc, float_flag_inexact, 0x08);
68 /* Install the exceptions that we raised. */
69 env->fpc |= s390_exc << 16;
71 /* Send signals for enabled exceptions. */
72 s390_exc &= env->fpc >> 24;
73 if (s390_exc) {
74 ieee_exception(env, s390_exc, retaddr);
78 static inline int float_comp_to_cc(CPUS390XState *env, int float_compare)
80 S390CPU *cpu = s390_env_get_cpu(env);
82 switch (float_compare) {
83 case float_relation_equal:
84 return 0;
85 case float_relation_less:
86 return 1;
87 case float_relation_greater:
88 return 2;
89 case float_relation_unordered:
90 return 3;
91 default:
92 cpu_abort(CPU(cpu), "unknown return value for float compare\n");
96 /* condition codes for unary FP ops */
97 uint32_t set_cc_nz_f32(float32 v)
99 if (float32_is_any_nan(v)) {
100 return 3;
101 } else if (float32_is_zero(v)) {
102 return 0;
103 } else if (float32_is_neg(v)) {
104 return 1;
105 } else {
106 return 2;
110 uint32_t set_cc_nz_f64(float64 v)
112 if (float64_is_any_nan(v)) {
113 return 3;
114 } else if (float64_is_zero(v)) {
115 return 0;
116 } else if (float64_is_neg(v)) {
117 return 1;
118 } else {
119 return 2;
123 uint32_t set_cc_nz_f128(float128 v)
125 if (float128_is_any_nan(v)) {
126 return 3;
127 } else if (float128_is_zero(v)) {
128 return 0;
129 } else if (float128_is_neg(v)) {
130 return 1;
131 } else {
132 return 2;
136 /* 32-bit FP addition */
137 uint64_t HELPER(aeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
139 float32 ret = float32_add(f1, f2, &env->fpu_status);
140 handle_exceptions(env, GETPC());
141 return ret;
144 /* 64-bit FP addition */
145 uint64_t HELPER(adb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
147 float64 ret = float64_add(f1, f2, &env->fpu_status);
148 handle_exceptions(env, GETPC());
149 return ret;
152 /* 128-bit FP addition */
153 uint64_t HELPER(axb)(CPUS390XState *env, uint64_t ah, uint64_t al,
154 uint64_t bh, uint64_t bl)
156 float128 ret = float128_add(make_float128(ah, al),
157 make_float128(bh, bl),
158 &env->fpu_status);
159 handle_exceptions(env, GETPC());
160 return RET128(ret);
163 /* 32-bit FP subtraction */
164 uint64_t HELPER(seb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
166 float32 ret = float32_sub(f1, f2, &env->fpu_status);
167 handle_exceptions(env, GETPC());
168 return ret;
171 /* 64-bit FP subtraction */
172 uint64_t HELPER(sdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
174 float64 ret = float64_sub(f1, f2, &env->fpu_status);
175 handle_exceptions(env, GETPC());
176 return ret;
179 /* 128-bit FP subtraction */
180 uint64_t HELPER(sxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
181 uint64_t bh, uint64_t bl)
183 float128 ret = float128_sub(make_float128(ah, al),
184 make_float128(bh, bl),
185 &env->fpu_status);
186 handle_exceptions(env, GETPC());
187 return RET128(ret);
190 /* 32-bit FP division */
191 uint64_t HELPER(deb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
193 float32 ret = float32_div(f1, f2, &env->fpu_status);
194 handle_exceptions(env, GETPC());
195 return ret;
198 /* 64-bit FP division */
199 uint64_t HELPER(ddb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
201 float64 ret = float64_div(f1, f2, &env->fpu_status);
202 handle_exceptions(env, GETPC());
203 return ret;
206 /* 128-bit FP division */
207 uint64_t HELPER(dxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
208 uint64_t bh, uint64_t bl)
210 float128 ret = float128_div(make_float128(ah, al),
211 make_float128(bh, bl),
212 &env->fpu_status);
213 handle_exceptions(env, GETPC());
214 return RET128(ret);
217 /* 32-bit FP multiplication */
218 uint64_t HELPER(meeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
220 float32 ret = float32_mul(f1, f2, &env->fpu_status);
221 handle_exceptions(env, GETPC());
222 return ret;
225 /* 64-bit FP multiplication */
226 uint64_t HELPER(mdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
228 float64 ret = float64_mul(f1, f2, &env->fpu_status);
229 handle_exceptions(env, GETPC());
230 return ret;
233 /* 64/32-bit FP multiplication */
234 uint64_t HELPER(mdeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
236 float64 ret = float32_to_float64(f2, &env->fpu_status);
237 ret = float64_mul(f1, ret, &env->fpu_status);
238 handle_exceptions(env, GETPC());
239 return ret;
242 /* 128-bit FP multiplication */
243 uint64_t HELPER(mxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
244 uint64_t bh, uint64_t bl)
246 float128 ret = float128_mul(make_float128(ah, al),
247 make_float128(bh, bl),
248 &env->fpu_status);
249 handle_exceptions(env, GETPC());
250 return RET128(ret);
253 /* 128/64-bit FP multiplication */
254 uint64_t HELPER(mxdb)(CPUS390XState *env, uint64_t ah, uint64_t al,
255 uint64_t f2)
257 float128 ret = float64_to_float128(f2, &env->fpu_status);
258 ret = float128_mul(make_float128(ah, al), ret, &env->fpu_status);
259 handle_exceptions(env, GETPC());
260 return RET128(ret);
263 /* convert 32-bit float to 64-bit float */
264 uint64_t HELPER(ldeb)(CPUS390XState *env, uint64_t f2)
266 float64 ret = float32_to_float64(f2, &env->fpu_status);
267 handle_exceptions(env, GETPC());
268 return ret;
271 /* convert 128-bit float to 64-bit float */
272 uint64_t HELPER(ldxb)(CPUS390XState *env, uint64_t ah, uint64_t al)
274 float64 ret = float128_to_float64(make_float128(ah, al), &env->fpu_status);
275 handle_exceptions(env, GETPC());
276 return ret;
279 /* convert 64-bit float to 128-bit float */
280 uint64_t HELPER(lxdb)(CPUS390XState *env, uint64_t f2)
282 float128 ret = float64_to_float128(f2, &env->fpu_status);
283 handle_exceptions(env, GETPC());
284 return RET128(ret);
287 /* convert 32-bit float to 128-bit float */
288 uint64_t HELPER(lxeb)(CPUS390XState *env, uint64_t f2)
290 float128 ret = float32_to_float128(f2, &env->fpu_status);
291 handle_exceptions(env, GETPC());
292 return RET128(ret);
295 /* convert 64-bit float to 32-bit float */
296 uint64_t HELPER(ledb)(CPUS390XState *env, uint64_t f2)
298 float32 ret = float64_to_float32(f2, &env->fpu_status);
299 handle_exceptions(env, GETPC());
300 return ret;
303 /* convert 128-bit float to 32-bit float */
304 uint64_t HELPER(lexb)(CPUS390XState *env, uint64_t ah, uint64_t al)
306 float32 ret = float128_to_float32(make_float128(ah, al), &env->fpu_status);
307 handle_exceptions(env, GETPC());
308 return ret;
311 /* 32-bit FP compare */
312 uint32_t HELPER(ceb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
314 int cmp = float32_compare_quiet(f1, f2, &env->fpu_status);
315 handle_exceptions(env, GETPC());
316 return float_comp_to_cc(env, cmp);
319 /* 64-bit FP compare */
320 uint32_t HELPER(cdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
322 int cmp = float64_compare_quiet(f1, f2, &env->fpu_status);
323 handle_exceptions(env, GETPC());
324 return float_comp_to_cc(env, cmp);
327 /* 128-bit FP compare */
328 uint32_t HELPER(cxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
329 uint64_t bh, uint64_t bl)
331 int cmp = float128_compare_quiet(make_float128(ah, al),
332 make_float128(bh, bl),
333 &env->fpu_status);
334 handle_exceptions(env, GETPC());
335 return float_comp_to_cc(env, cmp);
338 static int swap_round_mode(CPUS390XState *env, int m3)
340 int ret = env->fpu_status.float_rounding_mode;
341 switch (m3) {
342 case 0:
343 /* current mode */
344 break;
345 case 1:
346 /* biased round no nearest */
347 case 4:
348 /* round to nearest */
349 set_float_rounding_mode(float_round_nearest_even, &env->fpu_status);
350 break;
351 case 5:
352 /* round to zero */
353 set_float_rounding_mode(float_round_to_zero, &env->fpu_status);
354 break;
355 case 6:
356 /* round to +inf */
357 set_float_rounding_mode(float_round_up, &env->fpu_status);
358 break;
359 case 7:
360 /* round to -inf */
361 set_float_rounding_mode(float_round_down, &env->fpu_status);
362 break;
364 return ret;
367 /* convert 64-bit int to 32-bit float */
368 uint64_t HELPER(cegb)(CPUS390XState *env, int64_t v2, uint32_t m3)
370 int hold = swap_round_mode(env, m3);
371 float32 ret = int64_to_float32(v2, &env->fpu_status);
372 set_float_rounding_mode(hold, &env->fpu_status);
373 handle_exceptions(env, GETPC());
374 return ret;
377 /* convert 64-bit int to 64-bit float */
378 uint64_t HELPER(cdgb)(CPUS390XState *env, int64_t v2, uint32_t m3)
380 int hold = swap_round_mode(env, m3);
381 float64 ret = int64_to_float64(v2, &env->fpu_status);
382 set_float_rounding_mode(hold, &env->fpu_status);
383 handle_exceptions(env, GETPC());
384 return ret;
387 /* convert 64-bit int to 128-bit float */
388 uint64_t HELPER(cxgb)(CPUS390XState *env, int64_t v2, uint32_t m3)
390 int hold = swap_round_mode(env, m3);
391 float128 ret = int64_to_float128(v2, &env->fpu_status);
392 set_float_rounding_mode(hold, &env->fpu_status);
393 handle_exceptions(env, GETPC());
394 return RET128(ret);
397 /* convert 64-bit uint to 32-bit float */
398 uint64_t HELPER(celgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
400 int hold = swap_round_mode(env, m3);
401 float32 ret = uint64_to_float32(v2, &env->fpu_status);
402 set_float_rounding_mode(hold, &env->fpu_status);
403 handle_exceptions(env, GETPC());
404 return ret;
407 /* convert 64-bit uint to 64-bit float */
408 uint64_t HELPER(cdlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
410 int hold = swap_round_mode(env, m3);
411 float64 ret = uint64_to_float64(v2, &env->fpu_status);
412 set_float_rounding_mode(hold, &env->fpu_status);
413 handle_exceptions(env, GETPC());
414 return ret;
417 /* convert 64-bit uint to 128-bit float */
418 uint64_t HELPER(cxlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
420 int hold = swap_round_mode(env, m3);
421 float128 ret = uint64_to_float128(v2, &env->fpu_status);
422 set_float_rounding_mode(hold, &env->fpu_status);
423 handle_exceptions(env, GETPC());
424 return RET128(ret);
427 /* convert 32-bit float to 64-bit int */
428 uint64_t HELPER(cgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
430 int hold = swap_round_mode(env, m3);
431 int64_t ret = float32_to_int64(v2, &env->fpu_status);
432 set_float_rounding_mode(hold, &env->fpu_status);
433 handle_exceptions(env, GETPC());
434 return ret;
437 /* convert 64-bit float to 64-bit int */
438 uint64_t HELPER(cgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
440 int hold = swap_round_mode(env, m3);
441 int64_t ret = float64_to_int64(v2, &env->fpu_status);
442 set_float_rounding_mode(hold, &env->fpu_status);
443 handle_exceptions(env, GETPC());
444 return ret;
447 /* convert 128-bit float to 64-bit int */
448 uint64_t HELPER(cgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
450 int hold = swap_round_mode(env, m3);
451 float128 v2 = make_float128(h, l);
452 int64_t ret = float128_to_int64(v2, &env->fpu_status);
453 set_float_rounding_mode(hold, &env->fpu_status);
454 handle_exceptions(env, GETPC());
455 return ret;
458 /* convert 32-bit float to 32-bit int */
459 uint64_t HELPER(cfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
461 int hold = swap_round_mode(env, m3);
462 int32_t ret = float32_to_int32(v2, &env->fpu_status);
463 set_float_rounding_mode(hold, &env->fpu_status);
464 handle_exceptions(env, GETPC());
465 return ret;
468 /* convert 64-bit float to 32-bit int */
469 uint64_t HELPER(cfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
471 int hold = swap_round_mode(env, m3);
472 int32_t ret = float64_to_int32(v2, &env->fpu_status);
473 set_float_rounding_mode(hold, &env->fpu_status);
474 handle_exceptions(env, GETPC());
475 return ret;
478 /* convert 128-bit float to 32-bit int */
479 uint64_t HELPER(cfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
481 int hold = swap_round_mode(env, m3);
482 float128 v2 = make_float128(h, l);
483 int32_t ret = float128_to_int32(v2, &env->fpu_status);
484 set_float_rounding_mode(hold, &env->fpu_status);
485 handle_exceptions(env, GETPC());
486 return ret;
489 /* convert 32-bit float to 64-bit uint */
490 uint64_t HELPER(clgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
492 int hold = swap_round_mode(env, m3);
493 uint64_t ret;
494 v2 = float32_to_float64(v2, &env->fpu_status);
495 ret = float64_to_uint64(v2, &env->fpu_status);
496 set_float_rounding_mode(hold, &env->fpu_status);
497 handle_exceptions(env, GETPC());
498 return ret;
501 /* convert 64-bit float to 64-bit uint */
502 uint64_t HELPER(clgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
504 int hold = swap_round_mode(env, m3);
505 uint64_t ret = float64_to_uint64(v2, &env->fpu_status);
506 set_float_rounding_mode(hold, &env->fpu_status);
507 handle_exceptions(env, GETPC());
508 return ret;
511 /* convert 128-bit float to 64-bit uint */
512 uint64_t HELPER(clgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
514 int hold = swap_round_mode(env, m3);
515 float128 v2 = make_float128(h, l);
516 /* ??? Not 100% correct. */
517 uint64_t ret = float128_to_int64(v2, &env->fpu_status);
518 set_float_rounding_mode(hold, &env->fpu_status);
519 handle_exceptions(env, GETPC());
520 return ret;
523 /* convert 32-bit float to 32-bit uint */
524 uint64_t HELPER(clfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
526 int hold = swap_round_mode(env, m3);
527 uint32_t ret = float32_to_uint32(v2, &env->fpu_status);
528 set_float_rounding_mode(hold, &env->fpu_status);
529 handle_exceptions(env, GETPC());
530 return ret;
533 /* convert 64-bit float to 32-bit uint */
534 uint64_t HELPER(clfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
536 int hold = swap_round_mode(env, m3);
537 uint32_t ret = float64_to_uint32(v2, &env->fpu_status);
538 set_float_rounding_mode(hold, &env->fpu_status);
539 handle_exceptions(env, GETPC());
540 return ret;
543 /* convert 128-bit float to 32-bit uint */
544 uint64_t HELPER(clfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
546 int hold = swap_round_mode(env, m3);
547 float128 v2 = make_float128(h, l);
548 /* Not 100% correct. */
549 uint32_t ret = float128_to_int64(v2, &env->fpu_status);
550 set_float_rounding_mode(hold, &env->fpu_status);
551 handle_exceptions(env, GETPC());
552 return ret;
555 /* 32-bit FP multiply and add */
556 uint64_t HELPER(maeb)(CPUS390XState *env, uint64_t f1,
557 uint64_t f2, uint64_t f3)
559 float32 ret = float32_muladd(f2, f3, f1, 0, &env->fpu_status);
560 handle_exceptions(env, GETPC());
561 return ret;
564 /* 64-bit FP multiply and add */
565 uint64_t HELPER(madb)(CPUS390XState *env, uint64_t f1,
566 uint64_t f2, uint64_t f3)
568 float64 ret = float64_muladd(f2, f3, f1, 0, &env->fpu_status);
569 handle_exceptions(env, GETPC());
570 return ret;
573 /* 32-bit FP multiply and subtract */
574 uint64_t HELPER(mseb)(CPUS390XState *env, uint64_t f1,
575 uint64_t f2, uint64_t f3)
577 float32 ret = float32_muladd(f2, f3, f1, float_muladd_negate_c,
578 &env->fpu_status);
579 handle_exceptions(env, GETPC());
580 return ret;
583 /* 64-bit FP multiply and subtract */
584 uint64_t HELPER(msdb)(CPUS390XState *env, uint64_t f1,
585 uint64_t f2, uint64_t f3)
587 float64 ret = float64_muladd(f2, f3, f1, float_muladd_negate_c,
588 &env->fpu_status);
589 handle_exceptions(env, GETPC());
590 return ret;
593 /* test data class 32-bit */
594 uint32_t HELPER(tceb)(uint64_t f1, uint64_t m2)
596 float32 v1 = f1;
597 int neg = float32_is_neg(v1);
598 uint32_t cc = 0;
600 if ((float32_is_zero(v1) && (m2 & (1 << (11-neg)))) ||
601 (float32_is_infinity(v1) && (m2 & (1 << (5-neg)))) ||
602 (float32_is_any_nan(v1) && (m2 & (1 << (3-neg)))) ||
603 (float32_is_signaling_nan(v1) && (m2 & (1 << (1-neg))))) {
604 cc = 1;
605 } else if (m2 & (1 << (9-neg))) {
606 /* assume normalized number */
607 cc = 1;
609 /* FIXME: denormalized? */
610 return cc;
613 /* test data class 64-bit */
614 uint32_t HELPER(tcdb)(uint64_t v1, uint64_t m2)
616 int neg = float64_is_neg(v1);
617 uint32_t cc = 0;
619 if ((float64_is_zero(v1) && (m2 & (1 << (11-neg)))) ||
620 (float64_is_infinity(v1) && (m2 & (1 << (5-neg)))) ||
621 (float64_is_any_nan(v1) && (m2 & (1 << (3-neg)))) ||
622 (float64_is_signaling_nan(v1) && (m2 & (1 << (1-neg))))) {
623 cc = 1;
624 } else if (m2 & (1 << (9-neg))) {
625 /* assume normalized number */
626 cc = 1;
628 /* FIXME: denormalized? */
629 return cc;
632 /* test data class 128-bit */
633 uint32_t HELPER(tcxb)(uint64_t ah, uint64_t al, uint64_t m2)
635 float128 v1 = make_float128(ah, al);
636 int neg = float128_is_neg(v1);
637 uint32_t cc = 0;
639 if ((float128_is_zero(v1) && (m2 & (1 << (11-neg)))) ||
640 (float128_is_infinity(v1) && (m2 & (1 << (5-neg)))) ||
641 (float128_is_any_nan(v1) && (m2 & (1 << (3-neg)))) ||
642 (float128_is_signaling_nan(v1) && (m2 & (1 << (1-neg))))) {
643 cc = 1;
644 } else if (m2 & (1 << (9-neg))) {
645 /* assume normalized number */
646 cc = 1;
648 /* FIXME: denormalized? */
649 return cc;
652 /* square root 32-bit */
653 uint64_t HELPER(sqeb)(CPUS390XState *env, uint64_t f2)
655 float32 ret = float32_sqrt(f2, &env->fpu_status);
656 handle_exceptions(env, GETPC());
657 return ret;
660 /* square root 64-bit */
661 uint64_t HELPER(sqdb)(CPUS390XState *env, uint64_t f2)
663 float64 ret = float64_sqrt(f2, &env->fpu_status);
664 handle_exceptions(env, GETPC());
665 return ret;
668 /* square root 128-bit */
669 uint64_t HELPER(sqxb)(CPUS390XState *env, uint64_t ah, uint64_t al)
671 float128 ret = float128_sqrt(make_float128(ah, al), &env->fpu_status);
672 handle_exceptions(env, GETPC());
673 return RET128(ret);
676 static const int fpc_to_rnd[4] = {
677 float_round_nearest_even,
678 float_round_to_zero,
679 float_round_up,
680 float_round_down
683 /* set fpc */
684 void HELPER(sfpc)(CPUS390XState *env, uint64_t fpc)
686 /* Install everything in the main FPC. */
687 env->fpc = fpc;
689 /* Install the rounding mode in the shadow fpu_status. */
690 set_float_rounding_mode(fpc_to_rnd[fpc & 3], &env->fpu_status);
693 /* set fpc and signal */
694 void HELPER(sfas)(CPUS390XState *env, uint64_t val)
696 uint32_t signalling = env->fpc;
697 uint32_t source = val;
698 uint32_t s390_exc;
700 /* The contents of the source operand are placed in the FPC register;
701 then the flags in the FPC register are set to the logical OR of the
702 signalling flags and the source flags. */
703 env->fpc = source | (signalling & 0x00ff0000);
704 set_float_rounding_mode(fpc_to_rnd[source & 3], &env->fpu_status);
706 /* If any signalling flag is 1 and the corresponding source mask
707 is also 1, a simulated-iee-exception trap occurs. */
708 s390_exc = (signalling >> 16) & (source >> 24);
709 if (s390_exc) {
710 ieee_exception(env, s390_exc | 3, GETPC());