]> git.proxmox.com Git - qemu.git/blame - target-s390x/fpu_helper.c
target-s390: Implement CONVERT FROM LOGICAL
[qemu.git] / target-s390x / fpu_helper.c
CommitLineData
e72ca652
BS
1/*
2 * S/390 FPU helper routines
3 *
4 * Copyright (c) 2009 Ulrich Hecht
5 * Copyright (c) 2009 Alexander Graf
6 *
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.
11 *
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.
16 *
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/>.
19 */
20
21#include "cpu.h"
e72ca652
BS
22#include "helper.h"
23
19b0516f 24#if !defined(CONFIG_USER_ONLY)
022c62cb 25#include "exec/softmmu_exec.h"
e72ca652
BS
26#endif
27
28/* #define DEBUG_HELPER */
29#ifdef DEBUG_HELPER
30#define HELPER_LOG(x...) qemu_log(x)
31#else
32#define HELPER_LOG(x...)
33#endif
34
587626f8
RH
35#define RET128(F) (env->retxl = F.low, F.high)
36
37#define convert_bit(mask, from, to) \
38 (to < from \
39 ? (mask / (from / to)) & to \
40 : (mask & from) * (to / from))
41
42static void ieee_exception(CPUS390XState *env, uint32_t dxc, uintptr_t retaddr)
43{
44 /* Install the DXC code. */
45 env->fpc = (env->fpc & ~0xff00) | (dxc << 8);
46 /* Trap. */
47 runtime_exception(env, PGM_DATA, retaddr);
48}
49
50/* Should be called after any operation that may raise IEEE exceptions. */
51static void handle_exceptions(CPUS390XState *env, uintptr_t retaddr)
52{
53 unsigned s390_exc, qemu_exc;
54
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;
58 if (qemu_exc == 0) {
59 return;
60 }
61 env->fpu_status.float_exception_flags = 0;
62
63 /* Convert softfloat exception bits to s390 exception bits. */
64 s390_exc = 0;
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);
70
71 /* Install the exceptions that we raised. */
72 env->fpc |= s390_exc << 16;
73
74 /* Send signals for enabled exceptions. */
75 s390_exc &= env->fpc >> 24;
76 if (s390_exc) {
77 ieee_exception(env, s390_exc, retaddr);
78 }
79}
80
449c0d70 81static inline int float_comp_to_cc(CPUS390XState *env, int float_compare)
e72ca652
BS
82{
83 switch (float_compare) {
84 case float_relation_equal:
85 return 0;
86 case float_relation_less:
87 return 1;
88 case float_relation_greater:
89 return 2;
90 case float_relation_unordered:
91 return 3;
92 default:
93 cpu_abort(env, "unknown return value for float compare\n");
94 }
95}
96
e72ca652
BS
97/* condition codes for unary FP ops */
98uint32_t set_cc_nz_f32(float32 v)
99{
100 if (float32_is_any_nan(v)) {
101 return 3;
102 } else if (float32_is_zero(v)) {
103 return 0;
104 } else if (float32_is_neg(v)) {
105 return 1;
106 } else {
107 return 2;
108 }
109}
110
111uint32_t set_cc_nz_f64(float64 v)
112{
113 if (float64_is_any_nan(v)) {
114 return 3;
115 } else if (float64_is_zero(v)) {
116 return 0;
117 } else if (float64_is_neg(v)) {
118 return 1;
119 } else {
120 return 2;
121 }
122}
123
587626f8 124uint32_t set_cc_nz_f128(float128 v)
e72ca652
BS
125{
126 if (float128_is_any_nan(v)) {
127 return 3;
128 } else if (float128_is_zero(v)) {
129 return 0;
130 } else if (float128_is_neg(v)) {
131 return 1;
132 } else {
133 return 2;
134 }
135}
136
587626f8
RH
137/* 32-bit FP addition */
138uint64_t HELPER(aeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 139{
587626f8
RH
140 float32 ret = float32_add(f1, f2, &env->fpu_status);
141 handle_exceptions(env, GETPC());
142 return ret;
e72ca652
BS
143}
144
587626f8
RH
145/* 64-bit FP addition */
146uint64_t HELPER(adb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 147{
587626f8
RH
148 float64 ret = float64_add(f1, f2, &env->fpu_status);
149 handle_exceptions(env, GETPC());
150 return ret;
151}
e72ca652 152
587626f8
RH
153/* 128-bit FP addition */
154uint64_t HELPER(axb)(CPUS390XState *env, uint64_t ah, uint64_t al,
155 uint64_t bh, uint64_t bl)
156{
157 float128 ret = float128_add(make_float128(ah, al),
158 make_float128(bh, bl),
159 &env->fpu_status);
160 handle_exceptions(env, GETPC());
161 return RET128(ret);
e72ca652
BS
162}
163
1a800a2d
RH
164/* 32-bit FP subtraction */
165uint64_t HELPER(seb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 166{
1a800a2d
RH
167 float32 ret = float32_sub(f1, f2, &env->fpu_status);
168 handle_exceptions(env, GETPC());
169 return ret;
e72ca652
BS
170}
171
1a800a2d
RH
172/* 64-bit FP subtraction */
173uint64_t HELPER(sdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 174{
1a800a2d
RH
175 float64 ret = float64_sub(f1, f2, &env->fpu_status);
176 handle_exceptions(env, GETPC());
177 return ret;
178}
e72ca652 179
1a800a2d
RH
180/* 128-bit FP subtraction */
181uint64_t HELPER(sxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
182 uint64_t bh, uint64_t bl)
183{
184 float128 ret = float128_sub(make_float128(ah, al),
185 make_float128(bh, bl),
186 &env->fpu_status);
187 handle_exceptions(env, GETPC());
188 return RET128(ret);
e72ca652
BS
189}
190
f08a5c31
RH
191/* 32-bit FP division */
192uint64_t HELPER(deb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 193{
f08a5c31
RH
194 float32 ret = float32_div(f1, f2, &env->fpu_status);
195 handle_exceptions(env, GETPC());
196 return ret;
e72ca652
BS
197}
198
f08a5c31
RH
199/* 64-bit FP division */
200uint64_t HELPER(ddb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 201{
f08a5c31
RH
202 float64 ret = float64_div(f1, f2, &env->fpu_status);
203 handle_exceptions(env, GETPC());
204 return ret;
205}
e72ca652 206
f08a5c31
RH
207/* 128-bit FP division */
208uint64_t HELPER(dxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
209 uint64_t bh, uint64_t bl)
210{
211 float128 ret = float128_div(make_float128(ah, al),
212 make_float128(bh, bl),
213 &env->fpu_status);
214 handle_exceptions(env, GETPC());
215 return RET128(ret);
e72ca652
BS
216}
217
83b00736
RH
218/* 32-bit FP multiplication */
219uint64_t HELPER(meeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 220{
83b00736
RH
221 float32 ret = float32_mul(f1, f2, &env->fpu_status);
222 handle_exceptions(env, GETPC());
223 return ret;
e72ca652
BS
224}
225
83b00736
RH
226/* 64-bit FP multiplication */
227uint64_t HELPER(mdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 228{
83b00736
RH
229 float64 ret = float64_mul(f1, f2, &env->fpu_status);
230 handle_exceptions(env, GETPC());
231 return ret;
232}
e72ca652 233
83b00736
RH
234/* 64/32-bit FP multiplication */
235uint64_t HELPER(mdeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
236{
237 float64 ret = float32_to_float64(f2, &env->fpu_status);
238 ret = float64_mul(f1, ret, &env->fpu_status);
239 handle_exceptions(env, GETPC());
240 return ret;
241}
242
243/* 128-bit FP multiplication */
244uint64_t HELPER(mxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
245 uint64_t bh, uint64_t bl)
246{
247 float128 ret = float128_mul(make_float128(ah, al),
248 make_float128(bh, bl),
249 &env->fpu_status);
250 handle_exceptions(env, GETPC());
251 return RET128(ret);
252}
253
254/* 128/64-bit FP multiplication */
255uint64_t HELPER(mxdb)(CPUS390XState *env, uint64_t ah, uint64_t al,
256 uint64_t f2)
257{
258 float128 ret = float64_to_float128(f2, &env->fpu_status);
259 ret = float128_mul(make_float128(ah, al), ret, &env->fpu_status);
260 handle_exceptions(env, GETPC());
261 return RET128(ret);
e72ca652
BS
262}
263
264/* convert 32-bit float to 64-bit float */
587626f8 265uint64_t HELPER(ldeb)(CPUS390XState *env, uint64_t f2)
e72ca652 266{
587626f8
RH
267 float64 ret = float32_to_float64(f2, &env->fpu_status);
268 handle_exceptions(env, GETPC());
269 return ret;
e72ca652
BS
270}
271
272/* convert 128-bit float to 64-bit float */
587626f8 273uint64_t HELPER(ldxb)(CPUS390XState *env, uint64_t ah, uint64_t al)
e72ca652 274{
587626f8
RH
275 float64 ret = float128_to_float64(make_float128(ah, al), &env->fpu_status);
276 handle_exceptions(env, GETPC());
277 return ret;
e72ca652
BS
278}
279
280/* convert 64-bit float to 128-bit float */
587626f8 281uint64_t HELPER(lxdb)(CPUS390XState *env, uint64_t f2)
e72ca652 282{
587626f8
RH
283 float128 ret = float64_to_float128(f2, &env->fpu_status);
284 handle_exceptions(env, GETPC());
285 return RET128(ret);
286}
e72ca652 287
587626f8
RH
288/* convert 32-bit float to 128-bit float */
289uint64_t HELPER(lxeb)(CPUS390XState *env, uint64_t f2)
290{
291 float128 ret = float32_to_float128(f2, &env->fpu_status);
292 handle_exceptions(env, GETPC());
293 return RET128(ret);
e72ca652
BS
294}
295
296/* convert 64-bit float to 32-bit float */
587626f8 297uint64_t HELPER(ledb)(CPUS390XState *env, uint64_t f2)
e72ca652 298{
587626f8
RH
299 float32 ret = float64_to_float32(f2, &env->fpu_status);
300 handle_exceptions(env, GETPC());
301 return ret;
e72ca652
BS
302}
303
304/* convert 128-bit float to 32-bit float */
587626f8 305uint64_t HELPER(lexb)(CPUS390XState *env, uint64_t ah, uint64_t al)
e72ca652 306{
587626f8
RH
307 float32 ret = float128_to_float32(make_float128(ah, al), &env->fpu_status);
308 handle_exceptions(env, GETPC());
309 return ret;
e72ca652
BS
310}
311
587626f8
RH
312/* 32-bit FP compare */
313uint32_t HELPER(ceb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 314{
587626f8
RH
315 int cmp = float32_compare_quiet(f1, f2, &env->fpu_status);
316 handle_exceptions(env, GETPC());
317 return float_comp_to_cc(env, cmp);
e72ca652
BS
318}
319
587626f8
RH
320/* 64-bit FP compare */
321uint32_t HELPER(cdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 322{
587626f8
RH
323 int cmp = float64_compare_quiet(f1, f2, &env->fpu_status);
324 handle_exceptions(env, GETPC());
325 return float_comp_to_cc(env, cmp);
e72ca652
BS
326}
327
587626f8
RH
328/* 128-bit FP compare */
329uint32_t HELPER(cxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
330 uint64_t bh, uint64_t bl)
e72ca652 331{
587626f8
RH
332 int cmp = float128_compare_quiet(make_float128(ah, al),
333 make_float128(bh, bl),
334 &env->fpu_status);
335 handle_exceptions(env, GETPC());
336 return float_comp_to_cc(env, cmp);
e72ca652
BS
337}
338
68c8bd93 339static int swap_round_mode(CPUS390XState *env, int m3)
e72ca652 340{
68c8bd93 341 int ret = env->fpu_status.float_rounding_mode;
e72ca652
BS
342 switch (m3) {
343 case 0:
344 /* current mode */
345 break;
346 case 1:
347 /* biased round no nearest */
348 case 4:
349 /* round to nearest */
350 set_float_rounding_mode(float_round_nearest_even, &env->fpu_status);
351 break;
352 case 5:
353 /* round to zero */
354 set_float_rounding_mode(float_round_to_zero, &env->fpu_status);
355 break;
356 case 6:
357 /* round to +inf */
358 set_float_rounding_mode(float_round_up, &env->fpu_status);
359 break;
360 case 7:
361 /* round to -inf */
362 set_float_rounding_mode(float_round_down, &env->fpu_status);
363 break;
364 }
68c8bd93 365 return ret;
e72ca652
BS
366}
367
683bb9a8
RH
368/* convert 64-bit int to 32-bit float */
369uint64_t HELPER(cegb)(CPUS390XState *env, int64_t v2, uint32_t m3)
370{
371 int hold = swap_round_mode(env, m3);
372 float32 ret = int64_to_float32(v2, &env->fpu_status);
373 set_float_rounding_mode(hold, &env->fpu_status);
374 handle_exceptions(env, GETPC());
375 return ret;
376}
377
378/* convert 64-bit int to 64-bit float */
379uint64_t HELPER(cdgb)(CPUS390XState *env, int64_t v2, uint32_t m3)
380{
381 int hold = swap_round_mode(env, m3);
382 float64 ret = int64_to_float64(v2, &env->fpu_status);
383 set_float_rounding_mode(hold, &env->fpu_status);
384 handle_exceptions(env, GETPC());
385 return ret;
386}
387
388/* convert 64-bit int to 128-bit float */
389uint64_t HELPER(cxgb)(CPUS390XState *env, int64_t v2, uint32_t m3)
390{
391 int hold = swap_round_mode(env, m3);
392 float128 ret = int64_to_float128(v2, &env->fpu_status);
393 set_float_rounding_mode(hold, &env->fpu_status);
2112bf1b
RH
394 handle_exceptions(env, GETPC());
395 return RET128(ret);
396}
397
398/* convert 64-bit uint to 32-bit float */
399uint64_t HELPER(celgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
400{
401 int hold = swap_round_mode(env, m3);
402 float32 ret = uint64_to_float32(v2, &env->fpu_status);
403 set_float_rounding_mode(hold, &env->fpu_status);
404 handle_exceptions(env, GETPC());
405 return ret;
406}
407
408/* convert 64-bit uint to 64-bit float */
409uint64_t HELPER(cdlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
410{
411 int hold = swap_round_mode(env, m3);
412 float64 ret = uint64_to_float64(v2, &env->fpu_status);
413 set_float_rounding_mode(hold, &env->fpu_status);
414 handle_exceptions(env, GETPC());
415 return ret;
416}
417
418/* convert 64-bit uint to 128-bit float */
419uint64_t HELPER(cxlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
420{
421 int hold = swap_round_mode(env, m3);
422 /* ??? Not 50% correct. */
423 float128 ret = int64_to_float128(v2, &env->fpu_status);
424 set_float_rounding_mode(hold, &env->fpu_status);
683bb9a8
RH
425 handle_exceptions(env, GETPC());
426 return RET128(ret);
427}
428
e72ca652 429/* convert 32-bit float to 64-bit int */
68c8bd93 430uint64_t HELPER(cgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 431{
68c8bd93
RH
432 int hold = swap_round_mode(env, m3);
433 int64_t ret = float32_to_int64(v2, &env->fpu_status);
434 set_float_rounding_mode(hold, &env->fpu_status);
435 handle_exceptions(env, GETPC());
436 return ret;
e72ca652
BS
437}
438
439/* convert 64-bit float to 64-bit int */
68c8bd93 440uint64_t HELPER(cgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 441{
68c8bd93
RH
442 int hold = swap_round_mode(env, m3);
443 int64_t ret = float64_to_int64(v2, &env->fpu_status);
444 set_float_rounding_mode(hold, &env->fpu_status);
445 handle_exceptions(env, GETPC());
446 return ret;
e72ca652
BS
447}
448
449/* convert 128-bit float to 64-bit int */
68c8bd93 450uint64_t HELPER(cgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
e72ca652 451{
68c8bd93
RH
452 int hold = swap_round_mode(env, m3);
453 float128 v2 = make_float128(h, l);
454 int64_t ret = float128_to_int64(v2, &env->fpu_status);
455 set_float_rounding_mode(hold, &env->fpu_status);
456 handle_exceptions(env, GETPC());
457 return ret;
e72ca652
BS
458}
459
460/* convert 32-bit float to 32-bit int */
68c8bd93 461uint64_t HELPER(cfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 462{
68c8bd93
RH
463 int hold = swap_round_mode(env, m3);
464 int32_t ret = float32_to_int32(v2, &env->fpu_status);
465 set_float_rounding_mode(hold, &env->fpu_status);
466 handle_exceptions(env, GETPC());
467 return ret;
e72ca652
BS
468}
469
470/* convert 64-bit float to 32-bit int */
68c8bd93 471uint64_t HELPER(cfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 472{
68c8bd93
RH
473 int hold = swap_round_mode(env, m3);
474 int32_t ret = float64_to_int32(v2, &env->fpu_status);
475 set_float_rounding_mode(hold, &env->fpu_status);
476 handle_exceptions(env, GETPC());
477 return ret;
e72ca652
BS
478}
479
480/* convert 128-bit float to 32-bit int */
68c8bd93 481uint64_t HELPER(cfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
e72ca652 482{
68c8bd93
RH
483 int hold = swap_round_mode(env, m3);
484 float128 v2 = make_float128(h, l);
485 int32_t ret = float128_to_int32(v2, &env->fpu_status);
486 set_float_rounding_mode(hold, &env->fpu_status);
487 handle_exceptions(env, GETPC());
488 return ret;
e72ca652
BS
489}
490
6ac1b45f
RH
491/* convert 32-bit float to 64-bit uint */
492uint64_t HELPER(clgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
493{
494 int hold = swap_round_mode(env, m3);
495 uint64_t ret;
496 v2 = float32_to_float64(v2, &env->fpu_status);
497 ret = float64_to_uint64(v2, &env->fpu_status);
498 set_float_rounding_mode(hold, &env->fpu_status);
499 handle_exceptions(env, GETPC());
500 return ret;
501}
502
503/* convert 64-bit float to 64-bit uint */
504uint64_t HELPER(clgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
505{
506 int hold = swap_round_mode(env, m3);
507 uint64_t ret = float64_to_uint64(v2, &env->fpu_status);
508 set_float_rounding_mode(hold, &env->fpu_status);
509 handle_exceptions(env, GETPC());
510 return ret;
511}
512
513/* convert 128-bit float to 64-bit uint */
514uint64_t HELPER(clgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
515{
516 int hold = swap_round_mode(env, m3);
517 float128 v2 = make_float128(h, l);
518 /* ??? Not 100% correct. */
519 uint64_t ret = float128_to_int64(v2, &env->fpu_status);
520 set_float_rounding_mode(hold, &env->fpu_status);
521 handle_exceptions(env, GETPC());
522 return ret;
523}
524
525/* convert 32-bit float to 32-bit uint */
526uint64_t HELPER(clfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
527{
528 int hold = swap_round_mode(env, m3);
529 uint32_t ret = float32_to_uint32(v2, &env->fpu_status);
530 set_float_rounding_mode(hold, &env->fpu_status);
531 handle_exceptions(env, GETPC());
532 return ret;
533}
534
535/* convert 64-bit float to 32-bit uint */
536uint64_t HELPER(clfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
537{
538 int hold = swap_round_mode(env, m3);
539 uint32_t ret = float64_to_uint32(v2, &env->fpu_status);
540 set_float_rounding_mode(hold, &env->fpu_status);
541 handle_exceptions(env, GETPC());
542 return ret;
543}
544
545/* convert 128-bit float to 32-bit uint */
546uint64_t HELPER(clfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
547{
548 int hold = swap_round_mode(env, m3);
549 float128 v2 = make_float128(h, l);
550 /* Not 100% correct. */
551 uint32_t ret = float128_to_int64(v2, &env->fpu_status);
552 set_float_rounding_mode(hold, &env->fpu_status);
553 handle_exceptions(env, GETPC());
554 return ret;
555}
556
722bfec3
RH
557/* 32-bit FP multiply and add */
558uint64_t HELPER(maeb)(CPUS390XState *env, uint64_t f1,
559 uint64_t f2, uint64_t f3)
e72ca652 560{
722bfec3
RH
561 float32 ret = float32_muladd(f2, f3, f1, 0, &env->fpu_status);
562 handle_exceptions(env, GETPC());
563 return ret;
e72ca652
BS
564}
565
722bfec3
RH
566/* 64-bit FP multiply and add */
567uint64_t HELPER(madb)(CPUS390XState *env, uint64_t f1,
568 uint64_t f2, uint64_t f3)
e72ca652 569{
722bfec3
RH
570 float64 ret = float64_muladd(f2, f3, f1, 0, &env->fpu_status);
571 handle_exceptions(env, GETPC());
572 return ret;
e72ca652
BS
573}
574
722bfec3
RH
575/* 32-bit FP multiply and subtract */
576uint64_t HELPER(mseb)(CPUS390XState *env, uint64_t f1,
577 uint64_t f2, uint64_t f3)
e72ca652 578{
722bfec3
RH
579 float32 ret = float32_muladd(f2, f3, f1, float_muladd_negate_c,
580 &env->fpu_status);
581 handle_exceptions(env, GETPC());
582 return ret;
e72ca652
BS
583}
584
722bfec3
RH
585/* 64-bit FP multiply and subtract */
586uint64_t HELPER(msdb)(CPUS390XState *env, uint64_t f1,
587 uint64_t f2, uint64_t f3)
e72ca652 588{
722bfec3
RH
589 float64 ret = float64_muladd(f2, f3, f1, float_muladd_negate_c,
590 &env->fpu_status);
591 handle_exceptions(env, GETPC());
592 return ret;
e72ca652
BS
593}
594
e72ca652 595/* test data class 32-bit */
31aa97d1 596uint32_t HELPER(tceb)(uint64_t f1, uint64_t m2)
e72ca652 597{
31aa97d1 598 float32 v1 = f1;
e72ca652
BS
599 int neg = float32_is_neg(v1);
600 uint32_t cc = 0;
601
e72ca652
BS
602 if ((float32_is_zero(v1) && (m2 & (1 << (11-neg)))) ||
603 (float32_is_infinity(v1) && (m2 & (1 << (5-neg)))) ||
604 (float32_is_any_nan(v1) && (m2 & (1 << (3-neg)))) ||
605 (float32_is_signaling_nan(v1) && (m2 & (1 << (1-neg))))) {
606 cc = 1;
607 } else if (m2 & (1 << (9-neg))) {
608 /* assume normalized number */
609 cc = 1;
610 }
e72ca652
BS
611 /* FIXME: denormalized? */
612 return cc;
613}
614
615/* test data class 64-bit */
31aa97d1 616uint32_t HELPER(tcdb)(uint64_t v1, uint64_t m2)
e72ca652 617{
e72ca652
BS
618 int neg = float64_is_neg(v1);
619 uint32_t cc = 0;
620
e72ca652
BS
621 if ((float64_is_zero(v1) && (m2 & (1 << (11-neg)))) ||
622 (float64_is_infinity(v1) && (m2 & (1 << (5-neg)))) ||
623 (float64_is_any_nan(v1) && (m2 & (1 << (3-neg)))) ||
624 (float64_is_signaling_nan(v1) && (m2 & (1 << (1-neg))))) {
625 cc = 1;
626 } else if (m2 & (1 << (9-neg))) {
627 /* assume normalized number */
628 cc = 1;
629 }
630 /* FIXME: denormalized? */
631 return cc;
632}
633
634/* test data class 128-bit */
31aa97d1 635uint32_t HELPER(tcxb)(uint64_t ah, uint64_t al, uint64_t m2)
e72ca652 636{
31aa97d1
RH
637 float128 v1 = make_float128(ah, al);
638 int neg = float128_is_neg(v1);
e72ca652 639 uint32_t cc = 0;
e72ca652 640
31aa97d1
RH
641 if ((float128_is_zero(v1) && (m2 & (1 << (11-neg)))) ||
642 (float128_is_infinity(v1) && (m2 & (1 << (5-neg)))) ||
643 (float128_is_any_nan(v1) && (m2 & (1 << (3-neg)))) ||
644 (float128_is_signaling_nan(v1) && (m2 & (1 << (1-neg))))) {
e72ca652
BS
645 cc = 1;
646 } else if (m2 & (1 << (9-neg))) {
647 /* assume normalized number */
648 cc = 1;
649 }
650 /* FIXME: denormalized? */
651 return cc;
652}
653
16d7b2a4
RH
654/* square root 32-bit */
655uint64_t HELPER(sqeb)(CPUS390XState *env, uint64_t f2)
e72ca652 656{
16d7b2a4
RH
657 float32 ret = float32_sqrt(f2, &env->fpu_status);
658 handle_exceptions(env, GETPC());
659 return ret;
660}
661
662/* square root 64-bit */
663uint64_t HELPER(sqdb)(CPUS390XState *env, uint64_t f2)
664{
665 float64 ret = float64_sqrt(f2, &env->fpu_status);
666 handle_exceptions(env, GETPC());
667 return ret;
668}
669
670/* square root 128-bit */
671uint64_t HELPER(sqxb)(CPUS390XState *env, uint64_t ah, uint64_t al)
672{
673 float128 ret = float128_sqrt(make_float128(ah, al), &env->fpu_status);
674 handle_exceptions(env, GETPC());
675 return RET128(ret);
e72ca652 676}
8379bfdb
RH
677
678/* set fpc */
679void HELPER(sfpc)(CPUS390XState *env, uint64_t fpc)
680{
681 static const int rnd[4] = {
682 float_round_nearest_even,
683 float_round_to_zero,
684 float_round_up,
685 float_round_down
686 };
687
688 /* Install everything in the main FPC. */
689 env->fpc = fpc;
690
691 /* Install the rounding mode in the shadow fpu_status. */
692 set_float_rounding_mode(rnd[fpc & 3], &env->fpu_status);
693}