2 * Copyright (c) 2011 - 2019, Max Filippov, Open Source and Linux Lab.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Open Source and Linux Lab nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "qemu/osdep.h"
29 #include "qemu/main-loop.h"
31 #include "exec/helper-proto.h"
32 #include "qemu/host-utils.h"
33 #include "exec/exec-all.h"
34 #include "fpu/softfloat.h"
36 void HELPER(wur_fcr
)(CPUXtensaState
*env
, uint32_t v
)
38 static const int rounding_mode
[] = {
39 float_round_nearest_even
,
45 env
->uregs
[FCR
] = v
& 0xfffff07f;
46 set_float_rounding_mode(rounding_mode
[v
& 3], &env
->fp_status
);
49 float32
HELPER(abs_s
)(float32 v
)
51 return float32_abs(v
);
54 float32
HELPER(neg_s
)(float32 v
)
56 return float32_chs(v
);
59 float32
HELPER(add_s
)(CPUXtensaState
*env
, float32 a
, float32 b
)
61 return float32_add(a
, b
, &env
->fp_status
);
64 float32
HELPER(sub_s
)(CPUXtensaState
*env
, float32 a
, float32 b
)
66 return float32_sub(a
, b
, &env
->fp_status
);
69 float32
HELPER(mul_s
)(CPUXtensaState
*env
, float32 a
, float32 b
)
71 return float32_mul(a
, b
, &env
->fp_status
);
74 float32
HELPER(madd_s
)(CPUXtensaState
*env
, float32 a
, float32 b
, float32 c
)
76 return float32_muladd(b
, c
, a
, 0, &env
->fp_status
);
79 float32
HELPER(msub_s
)(CPUXtensaState
*env
, float32 a
, float32 b
, float32 c
)
81 return float32_muladd(b
, c
, a
, float_muladd_negate_product
,
85 uint32_t HELPER(ftoi
)(float32 v
, uint32_t rounding_mode
, uint32_t scale
)
87 float_status fp_status
= {0};
89 set_float_rounding_mode(rounding_mode
, &fp_status
);
90 return float32_to_int32(float32_scalbn(v
, scale
, &fp_status
), &fp_status
);
93 uint32_t HELPER(ftoui
)(float32 v
, uint32_t rounding_mode
, uint32_t scale
)
95 float_status fp_status
= {0};
98 set_float_rounding_mode(rounding_mode
, &fp_status
);
100 res
= float32_scalbn(v
, scale
, &fp_status
);
102 if (float32_is_neg(v
) && !float32_is_any_nan(v
)) {
103 return float32_to_int32(res
, &fp_status
);
105 return float32_to_uint32(res
, &fp_status
);
109 float32
HELPER(itof
)(CPUXtensaState
*env
, uint32_t v
, uint32_t scale
)
111 return float32_scalbn(int32_to_float32(v
, &env
->fp_status
),
112 (int32_t)scale
, &env
->fp_status
);
115 float32
HELPER(uitof
)(CPUXtensaState
*env
, uint32_t v
, uint32_t scale
)
117 return float32_scalbn(uint32_to_float32(v
, &env
->fp_status
),
118 (int32_t)scale
, &env
->fp_status
);
121 static inline void set_br(CPUXtensaState
*env
, bool v
, uint32_t br
)
124 env
->sregs
[BR
] |= br
;
126 env
->sregs
[BR
] &= ~br
;
130 void HELPER(un_s
)(CPUXtensaState
*env
, uint32_t br
, float32 a
, float32 b
)
132 set_br(env
, float32_unordered_quiet(a
, b
, &env
->fp_status
), br
);
135 void HELPER(oeq_s
)(CPUXtensaState
*env
, uint32_t br
, float32 a
, float32 b
)
137 set_br(env
, float32_eq_quiet(a
, b
, &env
->fp_status
), br
);
140 void HELPER(ueq_s
)(CPUXtensaState
*env
, uint32_t br
, float32 a
, float32 b
)
142 FloatRelation v
= float32_compare_quiet(a
, b
, &env
->fp_status
);
143 set_br(env
, v
== float_relation_equal
|| v
== float_relation_unordered
, br
);
146 void HELPER(olt_s
)(CPUXtensaState
*env
, uint32_t br
, float32 a
, float32 b
)
148 set_br(env
, float32_lt_quiet(a
, b
, &env
->fp_status
), br
);
151 void HELPER(ult_s
)(CPUXtensaState
*env
, uint32_t br
, float32 a
, float32 b
)
153 FloatRelation v
= float32_compare_quiet(a
, b
, &env
->fp_status
);
154 set_br(env
, v
== float_relation_less
|| v
== float_relation_unordered
, br
);
157 void HELPER(ole_s
)(CPUXtensaState
*env
, uint32_t br
, float32 a
, float32 b
)
159 set_br(env
, float32_le_quiet(a
, b
, &env
->fp_status
), br
);
162 void HELPER(ule_s
)(CPUXtensaState
*env
, uint32_t br
, float32 a
, float32 b
)
164 FloatRelation v
= float32_compare_quiet(a
, b
, &env
->fp_status
);
165 set_br(env
, v
!= float_relation_greater
, br
);