From nobody Wed Nov 5 14:24:48 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534826414715814.5482486550043; Mon, 20 Aug 2018 21:40:14 -0700 (PDT) Received: from localhost ([::1]:50666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frySj-0000J8-L4 for importer@patchew.org; Tue, 21 Aug 2018 00:40:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fryMp-00047P-7K for qemu-devel@nongnu.org; Tue, 21 Aug 2018 00:34:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fryMl-0000It-2v for qemu-devel@nongnu.org; Tue, 21 Aug 2018 00:34:06 -0400 Received: from ozlabs.org ([203.11.71.1]:33979) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fryMk-0000EU-5v; Tue, 21 Aug 2018 00:34:02 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 41vd9D4YQdz9s8F; Tue, 21 Aug 2018 14:33:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1534826032; bh=ymmkFgW2+kau1eTvEWlF10Lv92x+ZQOpCHYcA09KofI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AmlXoGorRRY5xVup48CYOHk8MT1B7PtpHBeuWb/91AloWA0tWtJ4FfCQ+nEMEmBFw 3RndllKVHW4YCAUyVPu6I0uMo0ueLUsYYpwhKN1KVDF9qa3YdA3lCQAjt2jk1WCPKi Z9NFtLDzKmKpSkWftPBHusyCII6N1Z3MZZ2aV+Bg= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 21 Aug 2018 14:33:25 +1000 Message-Id: <20180821043343.7514-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180821043343.7514-1-david@gibson.dropbear.id.au> References: <20180821043343.7514-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 08/26] target/ppc: Honor fpscr_ze semantics and tidy fre, fresqrt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, aik@ozlabs.ru, Richard Henderson , groug@kaod.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Henderson Divide by zero, exception taken, leaves the destination register unmodified. Therefore we must raise the exception before returning from the respective helpers. >From helper_fre, divide by zero exception not taken, return the documented +/- 0.5. At the same time, tidy the invalid exception checking so that we rely on softfloat for initial argument validation, and select the kind of invalid operand exception only when we know we must. At the same time, pass and return float64 values directly rather than bounce through the CPU_DoubleU union. Signed-off-by: Richard Henderson Signed-off-by: David Gibson --- target/ppc/fpu_helper.c | 62 ++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/target/ppc/fpu_helper.c b/target/ppc/fpu_helper.c index 44f3fed17d..5af5241ab0 100644 --- a/target/ppc/fpu_helper.c +++ b/target/ppc/fpu_helper.c @@ -879,18 +879,27 @@ float64 helper_fsqrt(CPUPPCState *env, float64 arg) } =20 /* fre - fre. */ -uint64_t helper_fre(CPUPPCState *env, uint64_t arg) +float64 helper_fre(CPUPPCState *env, float64 arg) { - CPU_DoubleU farg; - - farg.ll =3D arg; + /* "Estimate" the reciprocal with actual division. */ + float64 ret =3D float64_div(float64_one, arg, &env->fp_status); + int status =3D get_float_exception_flags(&env->fp_status); =20 - if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) { - /* sNaN reciprocal */ - float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); + if (unlikely(status)) { + if (status & float_flag_invalid) { + if (float64_is_signaling_nan(arg, &env->fp_status)) { + /* sNaN reciprocal */ + float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); + } + } + if (status & float_flag_divbyzero) { + float_zero_divide_excp(env, GETPC()); + /* For FPSCR.ZE =3D=3D 0, the result is 1/2. */ + ret =3D float64_set_sign(float64_half, float64_is_neg(arg)); + } } - farg.d =3D float64_div(float64_one, farg.d, &env->fp_status); - return farg.d; + + return ret; } =20 /* fres - fres. */ @@ -913,27 +922,30 @@ uint64_t helper_fres(CPUPPCState *env, uint64_t arg) } =20 /* frsqrte - frsqrte. */ -uint64_t helper_frsqrte(CPUPPCState *env, uint64_t arg) +float64 helper_frsqrte(CPUPPCState *env, float64 arg) { - CPU_DoubleU farg; - - farg.ll =3D arg; + /* "Estimate" the reciprocal with actual division. */ + float64 rets =3D float64_sqrt(arg, &env->fp_status); + float64 retd =3D float64_div(float64_one, rets, &env->fp_status); + int status =3D get_float_exception_flags(&env->fp_status); =20 - if (unlikely(float64_is_any_nan(farg.d))) { - if (unlikely(float64_is_signaling_nan(farg.d, &env->fp_status))) { - /* sNaN reciprocal square root */ - float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); - farg.ll =3D float64_snan_to_qnan(farg.ll); + if (unlikely(status)) { + if (status & float_flag_invalid) { + if (float64_is_signaling_nan(arg, &env->fp_status)) { + /* sNaN reciprocal */ + float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); + } else { + /* Square root of a negative nonzero number */ + float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSQRT, 1); + } + } + if (status & float_flag_divbyzero) { + /* Reciprocal of (square root of) zero. */ + float_zero_divide_excp(env, GETPC()); } - } else if (unlikely(float64_is_neg(farg.d) && !float64_is_zero(farg.d)= )) { - /* Reciprocal square root of a negative nonzero number */ - farg.ll =3D float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSQRT, 1); - } else { - farg.d =3D float64_sqrt(farg.d, &env->fp_status); - farg.d =3D float64_div(float64_one, farg.d, &env->fp_status); } =20 - return farg.ll; + return retd; } =20 /* fsel - fsel. */ --=20 2.17.1