[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 3/3] target/ppc: Bugfix fdiv result with OE/UE set
From: |
Lucas Mateus Castro(alqotel) |
Subject: |
[RFC PATCH 3/3] target/ppc: Bugfix fdiv result with OE/UE set |
Date: |
Wed, 3 Aug 2022 09:22:17 -0300 |
From: "Lucas Mateus Castro (alqotel)" <lucas.araujo@eldorado.org.br>
Change fdiv in the same way of fadd/fsub to handle overflow/underflow if
OE/UE is set (i.e. function that receives a value to add/subtract from
the exponent if an overflow/underflow occurs).
Signed-off-by: Lucas Mateus Castro (alqotel) <lucas.araujo@eldorado.org.br>
---
fpu/softfloat.c | 30 ++++++++++++++++++++++++++++++
include/fpu/softfloat.h | 1 +
target/ppc/fpu_helper.c | 5 ++++-
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index e2b4ad4b63..0e9d2d2678 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -2558,6 +2558,27 @@ soft_f64_div(float64 a, float64 b, float_status *status)
return float64_round_pack_canonical(pr, status);
}
+static float64 QEMU_SOFTFLOAT_ATTR
+soft_f64_div_excp_en(float64 a, float64 b, int oe_sub, int ue_sum,
+ float_status *status)
+{
+ FloatParts64 pa, pb, *pr;
+
+ float64_unpack_canonical(&pa, a, status);
+ float64_unpack_canonical(&pb, b, status);
+ pr = parts_div(&pa, &pb, status);
+
+ if (unlikely(oe_sub && (pr->exp > 1023))) {
+ pr->exp -= oe_sub;
+ float_raise(float_flag_overflow, status);
+ } else if (unlikely(ue_sum && (pr->exp < -1022))) {
+ pr->exp += ue_sum;
+ float_raise(float_flag_underflow, status);
+ }
+
+ return float64_round_pack_canonical(pr, status);
+}
+
static float hard_f32_div(float a, float b)
{
return a / b;
@@ -2616,6 +2637,15 @@ float64_div(float64 a, float64 b, float_status *s)
f64_div_pre, f64_div_post);
}
+float64 QEMU_FLATTEN
+float64_div_excp_en(float64 a, float64 b, int oe_sub, int ue_sum,
+ float_status *s)
+{
+ return float64_gen2_excp(a, b, oe_sub, ue_sum, s, hard_f64_div,
+ soft_f64_div, soft_f64_div_excp_en, f64_div_pre,
+ f64_div_post);
+}
+
float64 float64r32_div(float64 a, float64 b, float_status *status)
{
FloatParts64 pa, pb, *pr;
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
index 4ff56b0e10..a6c7885fcd 100644
--- a/include/fpu/softfloat.h
+++ b/include/fpu/softfloat.h
@@ -778,6 +778,7 @@ float64 float64_sub_excp_en(float64, float64, int, int,
float_status *status);
float64 float64_mul(float64, float64, float_status *status);
float64 float64_mul_excp_en(float64, float64, int, int, float_status *status);
float64 float64_div(float64, float64, float_status *status);
+float64 float64_div_excp_en(float64, float64, int, int, float_status *status);
float64 float64_rem(float64, float64, float_status *status);
float64 float64_muladd(float64, float64, float64, int, float_status *status);
float64 float64_sqrt(float64, float_status *status);
diff --git a/target/ppc/fpu_helper.c b/target/ppc/fpu_helper.c
index 18cf720743..1a6869a920 100644
--- a/target/ppc/fpu_helper.c
+++ b/target/ppc/fpu_helper.c
@@ -635,7 +635,10 @@ static void float_invalid_op_div(CPUPPCState *env, int
flags,
/* fdiv - fdiv. */
float64 helper_fdiv(CPUPPCState *env, float64 arg1, float64 arg2)
{
- float64 ret = float64_div(arg1, arg2, &env->fp_status);
+ int oe_sub = (FP_OE & env->fpscr) ? 1536 : 0;
+ int ue_sum = (FP_UE & env->fpscr) ? 1536 : 0;
+ float64 ret = float64_div_excp_en(arg1, arg2, oe_sub, ue_sum,
+ &env->fp_status);
int flags = get_float_exception_flags(&env->fp_status);
if (unlikely(flags & float_flag_invalid)) {
--
2.31.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [RFC PATCH 3/3] target/ppc: Bugfix fdiv result with OE/UE set,
Lucas Mateus Castro(alqotel) <=