]> Git Repo - qemu.git/blame - target/s390x/fpu_helper.c
target/s390x: introduce internal.h
[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
9615495a 21#include "qemu/osdep.h"
e72ca652 22#include "cpu.h"
4e58b838 23#include "internal.h"
63c91552 24#include "exec/exec-all.h"
f08b6170 25#include "exec/cpu_ldst.h"
2ef6175a 26#include "exec/helper-proto.h"
e72ca652 27
e72ca652
BS
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 82{
a47dddd7
AF
83 S390CPU *cpu = s390_env_get_cpu(env);
84
e72ca652
BS
85 switch (float_compare) {
86 case float_relation_equal:
87 return 0;
88 case float_relation_less:
89 return 1;
90 case float_relation_greater:
91 return 2;
92 case float_relation_unordered:
93 return 3;
94 default:
a47dddd7 95 cpu_abort(CPU(cpu), "unknown return value for float compare\n");
e72ca652
BS
96 }
97}
98
e72ca652
BS
99/* condition codes for unary FP ops */
100uint32_t set_cc_nz_f32(float32 v)
101{
102 if (float32_is_any_nan(v)) {
103 return 3;
104 } else if (float32_is_zero(v)) {
105 return 0;
106 } else if (float32_is_neg(v)) {
107 return 1;
108 } else {
109 return 2;
110 }
111}
112
113uint32_t set_cc_nz_f64(float64 v)
114{
115 if (float64_is_any_nan(v)) {
116 return 3;
117 } else if (float64_is_zero(v)) {
118 return 0;
119 } else if (float64_is_neg(v)) {
120 return 1;
121 } else {
122 return 2;
123 }
124}
125
587626f8 126uint32_t set_cc_nz_f128(float128 v)
e72ca652
BS
127{
128 if (float128_is_any_nan(v)) {
129 return 3;
130 } else if (float128_is_zero(v)) {
131 return 0;
132 } else if (float128_is_neg(v)) {
133 return 1;
134 } else {
135 return 2;
136 }
137}
138
587626f8
RH
139/* 32-bit FP addition */
140uint64_t HELPER(aeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 141{
587626f8
RH
142 float32 ret = float32_add(f1, f2, &env->fpu_status);
143 handle_exceptions(env, GETPC());
144 return ret;
e72ca652
BS
145}
146
587626f8
RH
147/* 64-bit FP addition */
148uint64_t HELPER(adb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 149{
587626f8
RH
150 float64 ret = float64_add(f1, f2, &env->fpu_status);
151 handle_exceptions(env, GETPC());
152 return ret;
153}
e72ca652 154
587626f8
RH
155/* 128-bit FP addition */
156uint64_t HELPER(axb)(CPUS390XState *env, uint64_t ah, uint64_t al,
157 uint64_t bh, uint64_t bl)
158{
159 float128 ret = float128_add(make_float128(ah, al),
160 make_float128(bh, bl),
161 &env->fpu_status);
162 handle_exceptions(env, GETPC());
163 return RET128(ret);
e72ca652
BS
164}
165
1a800a2d
RH
166/* 32-bit FP subtraction */
167uint64_t HELPER(seb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 168{
1a800a2d
RH
169 float32 ret = float32_sub(f1, f2, &env->fpu_status);
170 handle_exceptions(env, GETPC());
171 return ret;
e72ca652
BS
172}
173
1a800a2d
RH
174/* 64-bit FP subtraction */
175uint64_t HELPER(sdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 176{
1a800a2d
RH
177 float64 ret = float64_sub(f1, f2, &env->fpu_status);
178 handle_exceptions(env, GETPC());
179 return ret;
180}
e72ca652 181
1a800a2d
RH
182/* 128-bit FP subtraction */
183uint64_t HELPER(sxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
184 uint64_t bh, uint64_t bl)
185{
186 float128 ret = float128_sub(make_float128(ah, al),
187 make_float128(bh, bl),
188 &env->fpu_status);
189 handle_exceptions(env, GETPC());
190 return RET128(ret);
e72ca652
BS
191}
192
f08a5c31
RH
193/* 32-bit FP division */
194uint64_t HELPER(deb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 195{
f08a5c31
RH
196 float32 ret = float32_div(f1, f2, &env->fpu_status);
197 handle_exceptions(env, GETPC());
198 return ret;
e72ca652
BS
199}
200
f08a5c31
RH
201/* 64-bit FP division */
202uint64_t HELPER(ddb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 203{
f08a5c31
RH
204 float64 ret = float64_div(f1, f2, &env->fpu_status);
205 handle_exceptions(env, GETPC());
206 return ret;
207}
e72ca652 208
f08a5c31
RH
209/* 128-bit FP division */
210uint64_t HELPER(dxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
211 uint64_t bh, uint64_t bl)
212{
213 float128 ret = float128_div(make_float128(ah, al),
214 make_float128(bh, bl),
215 &env->fpu_status);
216 handle_exceptions(env, GETPC());
217 return RET128(ret);
e72ca652
BS
218}
219
83b00736
RH
220/* 32-bit FP multiplication */
221uint64_t HELPER(meeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 222{
83b00736
RH
223 float32 ret = float32_mul(f1, f2, &env->fpu_status);
224 handle_exceptions(env, GETPC());
225 return ret;
e72ca652
BS
226}
227
83b00736
RH
228/* 64-bit FP multiplication */
229uint64_t HELPER(mdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 230{
83b00736
RH
231 float64 ret = float64_mul(f1, f2, &env->fpu_status);
232 handle_exceptions(env, GETPC());
233 return ret;
234}
e72ca652 235
83b00736
RH
236/* 64/32-bit FP multiplication */
237uint64_t HELPER(mdeb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
238{
239 float64 ret = float32_to_float64(f2, &env->fpu_status);
240 ret = float64_mul(f1, ret, &env->fpu_status);
241 handle_exceptions(env, GETPC());
242 return ret;
243}
244
245/* 128-bit FP multiplication */
246uint64_t HELPER(mxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
247 uint64_t bh, uint64_t bl)
248{
249 float128 ret = float128_mul(make_float128(ah, al),
250 make_float128(bh, bl),
251 &env->fpu_status);
252 handle_exceptions(env, GETPC());
253 return RET128(ret);
254}
255
256/* 128/64-bit FP multiplication */
257uint64_t HELPER(mxdb)(CPUS390XState *env, uint64_t ah, uint64_t al,
258 uint64_t f2)
259{
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());
263 return RET128(ret);
e72ca652
BS
264}
265
266/* convert 32-bit float to 64-bit float */
587626f8 267uint64_t HELPER(ldeb)(CPUS390XState *env, uint64_t f2)
e72ca652 268{
587626f8
RH
269 float64 ret = float32_to_float64(f2, &env->fpu_status);
270 handle_exceptions(env, GETPC());
af39bc8c 271 return float64_maybe_silence_nan(ret, &env->fpu_status);
e72ca652
BS
272}
273
274/* convert 128-bit float to 64-bit float */
587626f8 275uint64_t HELPER(ldxb)(CPUS390XState *env, uint64_t ah, uint64_t al)
e72ca652 276{
587626f8
RH
277 float64 ret = float128_to_float64(make_float128(ah, al), &env->fpu_status);
278 handle_exceptions(env, GETPC());
af39bc8c 279 return float64_maybe_silence_nan(ret, &env->fpu_status);
e72ca652
BS
280}
281
282/* convert 64-bit float to 128-bit float */
587626f8 283uint64_t HELPER(lxdb)(CPUS390XState *env, uint64_t f2)
e72ca652 284{
587626f8
RH
285 float128 ret = float64_to_float128(f2, &env->fpu_status);
286 handle_exceptions(env, GETPC());
af39bc8c 287 return RET128(float128_maybe_silence_nan(ret, &env->fpu_status));
587626f8 288}
e72ca652 289
587626f8
RH
290/* convert 32-bit float to 128-bit float */
291uint64_t HELPER(lxeb)(CPUS390XState *env, uint64_t f2)
292{
293 float128 ret = float32_to_float128(f2, &env->fpu_status);
294 handle_exceptions(env, GETPC());
af39bc8c 295 return RET128(float128_maybe_silence_nan(ret, &env->fpu_status));
e72ca652
BS
296}
297
298/* convert 64-bit float to 32-bit float */
587626f8 299uint64_t HELPER(ledb)(CPUS390XState *env, uint64_t f2)
e72ca652 300{
587626f8
RH
301 float32 ret = float64_to_float32(f2, &env->fpu_status);
302 handle_exceptions(env, GETPC());
af39bc8c 303 return float32_maybe_silence_nan(ret, &env->fpu_status);
e72ca652
BS
304}
305
306/* convert 128-bit float to 32-bit float */
587626f8 307uint64_t HELPER(lexb)(CPUS390XState *env, uint64_t ah, uint64_t al)
e72ca652 308{
587626f8
RH
309 float32 ret = float128_to_float32(make_float128(ah, al), &env->fpu_status);
310 handle_exceptions(env, GETPC());
af39bc8c 311 return float32_maybe_silence_nan(ret, &env->fpu_status);
e72ca652
BS
312}
313
587626f8
RH
314/* 32-bit FP compare */
315uint32_t HELPER(ceb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 316{
587626f8
RH
317 int cmp = float32_compare_quiet(f1, f2, &env->fpu_status);
318 handle_exceptions(env, GETPC());
319 return float_comp_to_cc(env, cmp);
e72ca652
BS
320}
321
587626f8
RH
322/* 64-bit FP compare */
323uint32_t HELPER(cdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
e72ca652 324{
587626f8
RH
325 int cmp = float64_compare_quiet(f1, f2, &env->fpu_status);
326 handle_exceptions(env, GETPC());
327 return float_comp_to_cc(env, cmp);
e72ca652
BS
328}
329
587626f8
RH
330/* 128-bit FP compare */
331uint32_t HELPER(cxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
332 uint64_t bh, uint64_t bl)
e72ca652 333{
587626f8
RH
334 int cmp = float128_compare_quiet(make_float128(ah, al),
335 make_float128(bh, bl),
336 &env->fpu_status);
337 handle_exceptions(env, GETPC());
338 return float_comp_to_cc(env, cmp);
e72ca652
BS
339}
340
68c8bd93 341static int swap_round_mode(CPUS390XState *env, int m3)
e72ca652 342{
68c8bd93 343 int ret = env->fpu_status.float_rounding_mode;
e72ca652
BS
344 switch (m3) {
345 case 0:
346 /* current mode */
347 break;
348 case 1:
349 /* biased round no nearest */
350 case 4:
351 /* round to nearest */
352 set_float_rounding_mode(float_round_nearest_even, &env->fpu_status);
353 break;
354 case 5:
355 /* round to zero */
356 set_float_rounding_mode(float_round_to_zero, &env->fpu_status);
357 break;
358 case 6:
359 /* round to +inf */
360 set_float_rounding_mode(float_round_up, &env->fpu_status);
361 break;
362 case 7:
363 /* round to -inf */
364 set_float_rounding_mode(float_round_down, &env->fpu_status);
365 break;
366 }
68c8bd93 367 return ret;
e72ca652
BS
368}
369
683bb9a8
RH
370/* convert 64-bit int to 32-bit float */
371uint64_t HELPER(cegb)(CPUS390XState *env, int64_t v2, uint32_t m3)
372{
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());
377 return ret;
378}
379
380/* convert 64-bit int to 64-bit float */
381uint64_t HELPER(cdgb)(CPUS390XState *env, int64_t v2, uint32_t m3)
382{
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());
387 return ret;
388}
389
390/* convert 64-bit int to 128-bit float */
391uint64_t HELPER(cxgb)(CPUS390XState *env, int64_t v2, uint32_t m3)
392{
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);
2112bf1b
RH
396 handle_exceptions(env, GETPC());
397 return RET128(ret);
398}
399
400/* convert 64-bit uint to 32-bit float */
401uint64_t HELPER(celgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
402{
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());
407 return ret;
408}
409
410/* convert 64-bit uint to 64-bit float */
411uint64_t HELPER(cdlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
412{
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());
417 return ret;
418}
419
420/* convert 64-bit uint to 128-bit float */
421uint64_t HELPER(cxlgb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
422{
423 int hold = swap_round_mode(env, m3);
d2d9feac 424 float128 ret = uint64_to_float128(v2, &env->fpu_status);
2112bf1b 425 set_float_rounding_mode(hold, &env->fpu_status);
683bb9a8
RH
426 handle_exceptions(env, GETPC());
427 return RET128(ret);
428}
429
e72ca652 430/* convert 32-bit float to 64-bit int */
68c8bd93 431uint64_t HELPER(cgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 432{
68c8bd93
RH
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());
437 return ret;
e72ca652
BS
438}
439
440/* convert 64-bit float to 64-bit int */
68c8bd93 441uint64_t HELPER(cgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 442{
68c8bd93
RH
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());
447 return ret;
e72ca652
BS
448}
449
450/* convert 128-bit float to 64-bit int */
68c8bd93 451uint64_t HELPER(cgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
e72ca652 452{
68c8bd93
RH
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());
458 return ret;
e72ca652
BS
459}
460
461/* convert 32-bit float to 32-bit int */
68c8bd93 462uint64_t HELPER(cfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 463{
68c8bd93
RH
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());
468 return ret;
e72ca652
BS
469}
470
471/* convert 64-bit float to 32-bit int */
68c8bd93 472uint64_t HELPER(cfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
e72ca652 473{
68c8bd93
RH
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());
478 return ret;
e72ca652
BS
479}
480
481/* convert 128-bit float to 32-bit int */
68c8bd93 482uint64_t HELPER(cfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
e72ca652 483{
68c8bd93
RH
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());
489 return ret;
e72ca652
BS
490}
491
6ac1b45f
RH
492/* convert 32-bit float to 64-bit uint */
493uint64_t HELPER(clgeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
494{
495 int hold = swap_round_mode(env, m3);
496 uint64_t ret;
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());
501 return ret;
502}
503
504/* convert 64-bit float to 64-bit uint */
505uint64_t HELPER(clgdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
506{
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());
511 return ret;
512}
513
514/* convert 128-bit float to 64-bit uint */
515uint64_t HELPER(clgxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
516{
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());
523 return ret;
524}
525
526/* convert 32-bit float to 32-bit uint */
527uint64_t HELPER(clfeb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
528{
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());
533 return ret;
534}
535
536/* convert 64-bit float to 32-bit uint */
537uint64_t HELPER(clfdb)(CPUS390XState *env, uint64_t v2, uint32_t m3)
538{
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());
543 return ret;
544}
545
546/* convert 128-bit float to 32-bit uint */
547uint64_t HELPER(clfxb)(CPUS390XState *env, uint64_t h, uint64_t l, uint32_t m3)
548{
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());
555 return ret;
556}
557
ed0bcece
AJ
558/* round to integer 32-bit */
559uint64_t HELPER(fieb)(CPUS390XState *env, uint64_t f2, uint32_t m3)
560{
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());
565 return ret;
566}
567
568/* round to integer 64-bit */
569uint64_t HELPER(fidb)(CPUS390XState *env, uint64_t f2, uint32_t m3)
570{
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());
575 return ret;
576}
577
578/* round to integer 128-bit */
579uint64_t HELPER(fixb)(CPUS390XState *env, uint64_t ah, uint64_t al, uint32_t m3)
580{
581 int hold = swap_round_mode(env, m3);
582 float128 ret = float128_round_to_int(make_float128(ah, al),
583 &env->fpu_status);
584 set_float_rounding_mode(hold, &env->fpu_status);
585 handle_exceptions(env, GETPC());
586 return RET128(ret);
587}
588
9c8be598
AJ
589/* 32-bit FP compare and signal */
590uint32_t HELPER(keb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
591{
592 int cmp = float32_compare(f1, f2, &env->fpu_status);
593 handle_exceptions(env, GETPC());
594 return float_comp_to_cc(env, cmp);
595}
596
597/* 64-bit FP compare and signal */
598uint32_t HELPER(kdb)(CPUS390XState *env, uint64_t f1, uint64_t f2)
599{
600 int cmp = float64_compare(f1, f2, &env->fpu_status);
601 handle_exceptions(env, GETPC());
602 return float_comp_to_cc(env, cmp);
603}
604
605/* 128-bit FP compare and signal */
606uint32_t HELPER(kxb)(CPUS390XState *env, uint64_t ah, uint64_t al,
607 uint64_t bh, uint64_t bl)
608{
609 int cmp = float128_compare(make_float128(ah, al),
610 make_float128(bh, bl),
611 &env->fpu_status);
612 handle_exceptions(env, GETPC());
613 return float_comp_to_cc(env, cmp);
614}
615
722bfec3
RH
616/* 32-bit FP multiply and add */
617uint64_t HELPER(maeb)(CPUS390XState *env, uint64_t f1,
618 uint64_t f2, uint64_t f3)
e72ca652 619{
722bfec3
RH
620 float32 ret = float32_muladd(f2, f3, f1, 0, &env->fpu_status);
621 handle_exceptions(env, GETPC());
622 return ret;
e72ca652
BS
623}
624
722bfec3
RH
625/* 64-bit FP multiply and add */
626uint64_t HELPER(madb)(CPUS390XState *env, uint64_t f1,
627 uint64_t f2, uint64_t f3)
e72ca652 628{
722bfec3
RH
629 float64 ret = float64_muladd(f2, f3, f1, 0, &env->fpu_status);
630 handle_exceptions(env, GETPC());
631 return ret;
e72ca652
BS
632}
633
722bfec3
RH
634/* 32-bit FP multiply and subtract */
635uint64_t HELPER(mseb)(CPUS390XState *env, uint64_t f1,
636 uint64_t f2, uint64_t f3)
e72ca652 637{
722bfec3
RH
638 float32 ret = float32_muladd(f2, f3, f1, float_muladd_negate_c,
639 &env->fpu_status);
640 handle_exceptions(env, GETPC());
641 return ret;
e72ca652
BS
642}
643
722bfec3
RH
644/* 64-bit FP multiply and subtract */
645uint64_t HELPER(msdb)(CPUS390XState *env, uint64_t f1,
646 uint64_t f2, uint64_t f3)
e72ca652 647{
722bfec3
RH
648 float64 ret = float64_muladd(f2, f3, f1, float_muladd_negate_c,
649 &env->fpu_status);
650 handle_exceptions(env, GETPC());
651 return ret;
e72ca652
BS
652}
653
e72ca652 654/* test data class 32-bit */
af39bc8c 655uint32_t HELPER(tceb)(CPUS390XState *env, uint64_t f1, uint64_t m2)
e72ca652 656{
31aa97d1 657 float32 v1 = f1;
e72ca652
BS
658 int neg = float32_is_neg(v1);
659 uint32_t cc = 0;
660
e72ca652
BS
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)))) ||
af39bc8c
AM
664 (float32_is_signaling_nan(v1, &env->fpu_status) &&
665 (m2 & (1 << (1-neg))))) {
e72ca652
BS
666 cc = 1;
667 } else if (m2 & (1 << (9-neg))) {
668 /* assume normalized number */
669 cc = 1;
670 }
e72ca652
BS
671 /* FIXME: denormalized? */
672 return cc;
673}
674
675/* test data class 64-bit */
af39bc8c 676uint32_t HELPER(tcdb)(CPUS390XState *env, uint64_t v1, uint64_t m2)
e72ca652 677{
e72ca652
BS
678 int neg = float64_is_neg(v1);
679 uint32_t cc = 0;
680
e72ca652
BS
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)))) ||
af39bc8c
AM
684 (float64_is_signaling_nan(v1, &env->fpu_status) &&
685 (m2 & (1 << (1-neg))))) {
e72ca652
BS
686 cc = 1;
687 } else if (m2 & (1 << (9-neg))) {
688 /* assume normalized number */
689 cc = 1;
690 }
691 /* FIXME: denormalized? */
692 return cc;
693}
694
695/* test data class 128-bit */
af39bc8c
AM
696uint32_t HELPER(tcxb)(CPUS390XState *env, uint64_t ah,
697 uint64_t al, uint64_t m2)
e72ca652 698{
31aa97d1
RH
699 float128 v1 = make_float128(ah, al);
700 int neg = float128_is_neg(v1);
e72ca652 701 uint32_t cc = 0;
e72ca652 702
31aa97d1
RH
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)))) ||
af39bc8c
AM
706 (float128_is_signaling_nan(v1, &env->fpu_status) &&
707 (m2 & (1 << (1-neg))))) {
e72ca652
BS
708 cc = 1;
709 } else if (m2 & (1 << (9-neg))) {
710 /* assume normalized number */
711 cc = 1;
712 }
713 /* FIXME: denormalized? */
714 return cc;
715}
716
16d7b2a4
RH
717/* square root 32-bit */
718uint64_t HELPER(sqeb)(CPUS390XState *env, uint64_t f2)
e72ca652 719{
16d7b2a4
RH
720 float32 ret = float32_sqrt(f2, &env->fpu_status);
721 handle_exceptions(env, GETPC());
722 return ret;
723}
724
725/* square root 64-bit */
726uint64_t HELPER(sqdb)(CPUS390XState *env, uint64_t f2)
727{
728 float64 ret = float64_sqrt(f2, &env->fpu_status);
729 handle_exceptions(env, GETPC());
730 return ret;
731}
732
733/* square root 128-bit */
734uint64_t HELPER(sqxb)(CPUS390XState *env, uint64_t ah, uint64_t al)
735{
736 float128 ret = float128_sqrt(make_float128(ah, al), &env->fpu_status);
737 handle_exceptions(env, GETPC());
738 return RET128(ret);
e72ca652 739}
8379bfdb 740
411edc22
RH
741static const int fpc_to_rnd[4] = {
742 float_round_nearest_even,
743 float_round_to_zero,
744 float_round_up,
745 float_round_down
746};
747
8379bfdb
RH
748/* set fpc */
749void HELPER(sfpc)(CPUS390XState *env, uint64_t fpc)
750{
8379bfdb
RH
751 /* Install everything in the main FPC. */
752 env->fpc = fpc;
753
754 /* Install the rounding mode in the shadow fpu_status. */
411edc22
RH
755 set_float_rounding_mode(fpc_to_rnd[fpc & 3], &env->fpu_status);
756}
757
758/* set fpc and signal */
759void HELPER(sfas)(CPUS390XState *env, uint64_t val)
760{
761 uint32_t signalling = env->fpc;
762 uint32_t source = val;
763 uint32_t s390_exc;
764
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);
770
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);
774 if (s390_exc) {
775 ieee_exception(env, s390_exc | 3, GETPC());
776 }
8379bfdb 777}
This page took 0.422035 seconds and 4 git commands to generate.