From nobody Fri Apr 19 09:44:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659709203121911.9828552479331; Fri, 5 Aug 2022 07:20:03 -0700 (PDT) Received: from localhost ([::1]:51620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJyBF-0001vT-I7 for importer@patchew.org; Fri, 05 Aug 2022 10:20:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJy75-00081Q-BU; Fri, 05 Aug 2022 10:15:43 -0400 Received: from [200.168.210.66] (port=13350 helo=outlook.eldorado.org.br) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJy73-0004vg-J3; Fri, 05 Aug 2022 10:15:42 -0400 Received: from p9ibm ([10.10.71.235]) by outlook.eldorado.org.br over TLS secured channel with Microsoft SMTPSVC(8.5.9600.16384); Fri, 5 Aug 2022 11:15:23 -0300 Received: from eldorado.org.br (unknown [10.10.70.45]) by p9ibm (Postfix) with ESMTP id 5230B8003B3; Fri, 5 Aug 2022 11:15:23 -0300 (-03) From: "Lucas Mateus Castro(alqotel)" To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, danielhb413@gmail.com, "Lucas Mateus Castro (alqotel)" , Aurelien Jarno , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH 1/2] fpu: Add rebias bool, value and operation Date: Fri, 5 Aug 2022 11:15:21 -0300 Message-Id: <20220805141522.412864-2-lucas.araujo@eldorado.org.br> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805141522.412864-1-lucas.araujo@eldorado.org.br> References: <20220805141522.412864-1-lucas.araujo@eldorado.org.br> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 05 Aug 2022 14:15:23.0564 (UTC) FILETIME=[CD709EC0:01D8A8D5] X-Host-Lookup-Failed: Reverse DNS lookup failed for 200.168.210.66 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=200.168.210.66; envelope-from=lucas.araujo@eldorado.org.br; helo=outlook.eldorado.org.br X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1659709205076100003 Content-Type: text/plain; charset="utf-8" From: "Lucas Mateus Castro (alqotel)" Added the possibility of recalculating a result if it overflows or underflows, if the result overflow and the rebias bool is true then the intermediate result should have 3/4 of the total range subtracted from the exponent. The same for underflow but it should be added to the exponent of the intermediate number instead. Signed-off-by: Lucas Mateus Castro (alqotel) Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- fpu/softfloat-parts.c.inc | 21 +++++++++++++++++++-- fpu/softfloat.c | 2 ++ include/fpu/softfloat-types.h | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index bbeadaa189..a9f268fcab 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -214,18 +214,35 @@ static void partsN(uncanon_normal)(FloatPartsN *p, fl= oat_status *s, p->frac_lo &=3D ~round_mask; } } else if (unlikely(exp >=3D exp_max)) { - flags |=3D float_flag_overflow | float_flag_inexact; - if (overflow_norm) { + flags |=3D float_flag_overflow; + if (s->rebias_overflow) { + exp -=3D fmt->exp_re_bias; + } else if (overflow_norm) { + flags |=3D float_flag_inexact; exp =3D exp_max - 1; frac_allones(p); p->frac_lo &=3D ~round_mask; } else { + flags |=3D float_flag_inexact; p->cls =3D float_class_inf; exp =3D exp_max; frac_clear(p); } } frac_shr(p, frac_shift); + } else if (unlikely(s->rebias_underflow)) { + flags |=3D float_flag_underflow; + exp +=3D fmt->exp_re_bias; + if (p->frac_lo & round_mask) { + flags |=3D float_flag_inexact; + if (frac_addi(p, p, inc)) { + frac_shr(p, 1); + p->frac_hi |=3D DECOMPOSED_IMPLICIT_BIT; + exp++; + } + p->frac_lo &=3D ~round_mask; + } + frac_shr(p, frac_shift); } else if (s->flush_to_zero) { flags |=3D float_flag_output_denormal; p->cls =3D float_class_zero; diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 4a871ef2a1..c7454c3eb1 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -521,6 +521,7 @@ typedef struct { typedef struct { int exp_size; int exp_bias; + int exp_re_bias; int exp_max; int frac_size; int frac_shift; @@ -532,6 +533,7 @@ typedef struct { #define FLOAT_PARAMS_(E) \ .exp_size =3D E, \ .exp_bias =3D ((1 << E) - 1) >> 1, \ + .exp_re_bias =3D (1 << (E - 1)) + (1 << (E - 2)), \ .exp_max =3D (1 << E) - 1 =20 #define FLOAT_PARAMS(E, F) \ diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h index 7a6ea881d8..9735543ac4 100644 --- a/include/fpu/softfloat-types.h +++ b/include/fpu/softfloat-types.h @@ -195,6 +195,10 @@ typedef struct float_status { bool snan_bit_is_one; bool use_first_nan; bool no_signaling_nans; + /* should overflowed results subtract re_bias to its exponent? */ + bool rebias_overflow; + /* should underflowed results add re_bias to its exponent? */ + bool rebias_underflow; } float_status; =20 #endif /* SOFTFLOAT_TYPES_H */ --=20 2.31.1 From nobody Fri Apr 19 09:44:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659709249169863.2161496640099; Fri, 5 Aug 2022 07:20:49 -0700 (PDT) Received: from localhost ([::1]:52400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJyC0-0002RV-0c for importer@patchew.org; Fri, 05 Aug 2022 10:20:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJy7A-00081w-Jn; Fri, 05 Aug 2022 10:15:49 -0400 Received: from [200.168.210.66] (port=13350 helo=outlook.eldorado.org.br) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJy78-0004vg-IQ; Fri, 05 Aug 2022 10:15:47 -0400 Received: from p9ibm ([10.10.71.235]) by outlook.eldorado.org.br over TLS secured channel with Microsoft SMTPSVC(8.5.9600.16384); Fri, 5 Aug 2022 11:15:23 -0300 Received: from eldorado.org.br (unknown [10.10.70.45]) by p9ibm (Postfix) with ESMTP id 78168800358; Fri, 5 Aug 2022 11:15:23 -0300 (-03) From: "Lucas Mateus Castro(alqotel)" To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, danielhb413@gmail.com, "Lucas Mateus Castro (alqotel)" , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz Subject: [PATCH 2/2] target/ppc: Bugfix FP when OE/UE are set Date: Fri, 5 Aug 2022 11:15:22 -0300 Message-Id: <20220805141522.412864-3-lucas.araujo@eldorado.org.br> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805141522.412864-1-lucas.araujo@eldorado.org.br> References: <20220805141522.412864-1-lucas.araujo@eldorado.org.br> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 05 Aug 2022 14:15:23.0704 (UTC) FILETIME=[CD85FB80:01D8A8D5] X-Host-Lookup-Failed: Reverse DNS lookup failed for 200.168.210.66 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=200.168.210.66; envelope-from=lucas.araujo@eldorado.org.br; helo=outlook.eldorado.org.br X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, PDS_HP_HELO_NORDNS=0.659, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1659709251292100003 Content-Type: text/plain; charset="utf-8" From: "Lucas Mateus Castro (alqotel)" When an overflow exception occurs and OE is set the intermediate result should be adjusted (by subtracting from the exponent) to avoid rounding to inf. The same applies to an underflow exceptionion and UE (but adding to the exponent). To do this set the fp_status.rebias_overflow when OE is set and fp_status.rebias_underflow when UE is set as the FPU will recalculate in case of a overflow/underflow if the according rebias* is set. Signed-off-by: Lucas Mateus Castro (alqotel) Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- target/ppc/cpu.c | 2 ++ target/ppc/fpu_helper.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target/ppc/cpu.c b/target/ppc/cpu.c index 401b6f9e63..0ebac04bc4 100644 --- a/target/ppc/cpu.c +++ b/target/ppc/cpu.c @@ -120,6 +120,8 @@ void ppc_store_fpscr(CPUPPCState *env, target_ulong val) val |=3D FP_FEX; } env->fpscr =3D val; + env->fp_status.rebias_overflow =3D (FP_OE & env->fpscr) ? true : fals= e; + env->fp_status.rebias_underflow =3D (FP_UE & env->fpscr) ? true : fals= e; if (tcg_enabled()) { fpscr_set_rounding_mode(env); } diff --git a/target/ppc/fpu_helper.c b/target/ppc/fpu_helper.c index 134804628b..c17575de5d 100644 --- a/target/ppc/fpu_helper.c +++ b/target/ppc/fpu_helper.c @@ -344,7 +344,6 @@ static inline int float_overflow_excp(CPUPPCState *env) =20 bool overflow_enabled =3D !!(env->fpscr & FP_OE); if (overflow_enabled) { - /* XXX: should adjust the result */ /* Update the floating-point enabled exception summary */ env->fpscr |=3D FP_FEX; /* We must update the target FPR before raising the exception */ @@ -363,7 +362,6 @@ static inline void float_underflow_excp(CPUPPCState *en= v) /* Update the floating-point exception summary */ env->fpscr |=3D FP_FX; if (env->fpscr & FP_UE) { - /* XXX: should adjust the result */ /* Update the floating-point enabled exception summary */ env->fpscr |=3D FP_FEX; /* We must update the target FPR before raising the exception */ --=20 2.31.1