2 * UniCore-F64 simulation helpers for QEMU.
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or any later version.
9 * See the COPYING file in the top-level directory.
15 * The convention used for UniCore-F64 instructions:
16 * Single precition routines have a "s" suffix
17 * Double precision routines have a "d" suffix.
20 /* Convert host exception flags to f64 form. */
21 static inline int ucf64_exceptbits_from_host(int host_bits
)
25 if (host_bits
& float_flag_invalid
) {
26 target_bits
|= UCF64_FPSCR_FLAG_INVALID
;
28 if (host_bits
& float_flag_divbyzero
) {
29 target_bits
|= UCF64_FPSCR_FLAG_DIVZERO
;
31 if (host_bits
& float_flag_overflow
) {
32 target_bits
|= UCF64_FPSCR_FLAG_OVERFLOW
;
34 if (host_bits
& float_flag_underflow
) {
35 target_bits
|= UCF64_FPSCR_FLAG_UNDERFLOW
;
37 if (host_bits
& float_flag_inexact
) {
38 target_bits
|= UCF64_FPSCR_FLAG_INEXACT
;
43 uint32_t HELPER(ucf64_get_fpscr
)(CPUUniCore32State
*env
)
48 fpscr
= (env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] & UCF64_FPSCR_MASK
);
49 i
= get_float_exception_flags(&env
->ucf64
.fp_status
);
50 fpscr
|= ucf64_exceptbits_from_host(i
);
54 /* Convert ucf64 exception flags to target form. */
55 static inline int ucf64_exceptbits_to_host(int target_bits
)
59 if (target_bits
& UCF64_FPSCR_FLAG_INVALID
) {
60 host_bits
|= float_flag_invalid
;
62 if (target_bits
& UCF64_FPSCR_FLAG_DIVZERO
) {
63 host_bits
|= float_flag_divbyzero
;
65 if (target_bits
& UCF64_FPSCR_FLAG_OVERFLOW
) {
66 host_bits
|= float_flag_overflow
;
68 if (target_bits
& UCF64_FPSCR_FLAG_UNDERFLOW
) {
69 host_bits
|= float_flag_underflow
;
71 if (target_bits
& UCF64_FPSCR_FLAG_INEXACT
) {
72 host_bits
|= float_flag_inexact
;
77 void HELPER(ucf64_set_fpscr
)(CPUUniCore32State
*env
, uint32_t val
)
82 changed
= env
->ucf64
.xregs
[UC32_UCF64_FPSCR
];
83 env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] = (val
& UCF64_FPSCR_MASK
);
86 if (changed
& (UCF64_FPSCR_RND_MASK
)) {
87 i
= UCF64_FPSCR_RND(val
);
90 i
= float_round_nearest_even
;
93 i
= float_round_to_zero
;
101 default: /* 100 and 101 not implement */
102 cpu_abort(env
, "Unsupported UniCore-F64 round mode");
104 set_float_rounding_mode(i
, &env
->ucf64
.fp_status
);
107 i
= ucf64_exceptbits_to_host(UCF64_FPSCR_TRAPEN(val
));
108 set_float_exception_flags(i
, &env
->ucf64
.fp_status
);
111 float32
HELPER(ucf64_adds
)(float32 a
, float32 b
, CPUUniCore32State
*env
)
113 return float32_add(a
, b
, &env
->ucf64
.fp_status
);
116 float64
HELPER(ucf64_addd
)(float64 a
, float64 b
, CPUUniCore32State
*env
)
118 return float64_add(a
, b
, &env
->ucf64
.fp_status
);
121 float32
HELPER(ucf64_subs
)(float32 a
, float32 b
, CPUUniCore32State
*env
)
123 return float32_sub(a
, b
, &env
->ucf64
.fp_status
);
126 float64
HELPER(ucf64_subd
)(float64 a
, float64 b
, CPUUniCore32State
*env
)
128 return float64_sub(a
, b
, &env
->ucf64
.fp_status
);
131 float32
HELPER(ucf64_muls
)(float32 a
, float32 b
, CPUUniCore32State
*env
)
133 return float32_mul(a
, b
, &env
->ucf64
.fp_status
);
136 float64
HELPER(ucf64_muld
)(float64 a
, float64 b
, CPUUniCore32State
*env
)
138 return float64_mul(a
, b
, &env
->ucf64
.fp_status
);
141 float32
HELPER(ucf64_divs
)(float32 a
, float32 b
, CPUUniCore32State
*env
)
143 return float32_div(a
, b
, &env
->ucf64
.fp_status
);
146 float64
HELPER(ucf64_divd
)(float64 a
, float64 b
, CPUUniCore32State
*env
)
148 return float64_div(a
, b
, &env
->ucf64
.fp_status
);
151 float32
HELPER(ucf64_negs
)(float32 a
)
153 return float32_chs(a
);
156 float64
HELPER(ucf64_negd
)(float64 a
)
158 return float64_chs(a
);
161 float32
HELPER(ucf64_abss
)(float32 a
)
163 return float32_abs(a
);
166 float64
HELPER(ucf64_absd
)(float64 a
)
168 return float64_abs(a
);
171 void HELPER(ucf64_cmps
)(float32 a
, float32 b
, uint32_t c
,
172 CPUUniCore32State
*env
)
175 flag
= float32_compare_quiet(a
, b
, &env
->ucf64
.fp_status
);
191 if ((flag
== 0) || (flag
== 2)) {
201 if ((flag
== -1) || (flag
== 2)) {
206 if ((flag
== -1) || (flag
== 0)) {
216 env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] = (env
->CF
<< 29)
217 | (env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] & 0x0fffffff);
220 void HELPER(ucf64_cmpd
)(float64 a
, float64 b
, uint32_t c
,
221 CPUUniCore32State
*env
)
224 flag
= float64_compare_quiet(a
, b
, &env
->ucf64
.fp_status
);
240 if ((flag
== 0) || (flag
== 2)) {
250 if ((flag
== -1) || (flag
== 2)) {
255 if ((flag
== -1) || (flag
== 0)) {
265 env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] = (env
->CF
<< 29)
266 | (env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] & 0x0fffffff);
269 /* Helper routines to perform bitwise copies between float and int. */
270 static inline float32
ucf64_itos(uint32_t i
)
281 static inline uint32_t ucf64_stoi(float32 s
)
292 static inline float64
ucf64_itod(uint64_t i
)
303 static inline uint64_t ucf64_dtoi(float64 d
)
314 /* Integer to float conversion. */
315 float32
HELPER(ucf64_si2sf
)(float32 x
, CPUUniCore32State
*env
)
317 return int32_to_float32(ucf64_stoi(x
), &env
->ucf64
.fp_status
);
320 float64
HELPER(ucf64_si2df
)(float32 x
, CPUUniCore32State
*env
)
322 return int32_to_float64(ucf64_stoi(x
), &env
->ucf64
.fp_status
);
325 /* Float to integer conversion. */
326 float32
HELPER(ucf64_sf2si
)(float32 x
, CPUUniCore32State
*env
)
328 return ucf64_itos(float32_to_int32(x
, &env
->ucf64
.fp_status
));
331 float32
HELPER(ucf64_df2si
)(float64 x
, CPUUniCore32State
*env
)
333 return ucf64_itos(float64_to_int32(x
, &env
->ucf64
.fp_status
));
336 /* floating point conversion */
337 float64
HELPER(ucf64_sf2df
)(float32 x
, CPUUniCore32State
*env
)
339 return float32_to_float64(x
, &env
->ucf64
.fp_status
);
342 float32
HELPER(ucf64_df2sf
)(float64 x
, CPUUniCore32State
*env
)
344 return float64_to_float32(x
, &env
->ucf64
.fp_status
);