From patchwork Tue Jul 3 15:17:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 140977 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1297006ljj; Tue, 3 Jul 2018 08:23:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcYD5pz73+ZRB6aDX3SsLQTZKRPBcWw2HHckxYIPEavhSvOMhxkyIWgkPR52RDlv3pSC+QG X-Received: by 2002:a37:b203:: with SMTP id b3-v6mr25762098qkf.266.1530631414480; Tue, 03 Jul 2018 08:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530631414; cv=none; d=google.com; s=arc-20160816; b=bg5NaTyKSLtcimT0IK0D8CCBDZTgZNyzNo8p+Tn/wjPax0bYVdjkYAdv6bWQqO0epM 7j0qdJByRm0yz0QRHVAIeG6MMVh3/p2USmQSTujAhlFiyM1K0yMJOxMIDWp0SjIqSdDh TpInYF0lcGwM9qWykUijUeWcaUJk8Z8xPOLxagZX3tgKNjyzKuoGPrWz3/iFy19FXcuX iohZRVPDx1j/iq9e4PwnZLJLu7RFBFkCayQrELfbajjZFTjkXg0eb4+/NZuXdKcKdta/ Ddx1XTgHtOh2CZh4tSBqoKf+vMJbzckjudOevGeqMbbGODOB5C+xCJsQEdOSHN0cPt0H U1BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=x2t1XFI2QFPK2VzG0H6uB4M9ibalVxnRLpzzWNvPaFo=; b=YPh05vwRQB8WPFvT3HWonnfFOCBEih/uyJ48KPBRSiwDbFfsrfRqPeSBQjGwrWRXLH HWH22CCdFan6HjE9yTRDaFspyT/3I0qFYT0svem7j+8mEKDoYHY8MvepdvN9aLCgUxhM ke0JNr0UkcJ3voydZh+jbfiQBH2QjTRreOIyn7cI+VWNxuHYUuh1qNCIkbt1GhbF7OAn sP6Uw6IeEIGEfZsWoKd8eShk/V6tS1wnucb9NMcFGnUhwLV0mHgOq8X5MCEOctoZKAL6 Ad3fF4gl1IWaKMMBV7MLonNQMIcDM96MASMkeJ4lTo8HvoXNnF333IKPkTh06fOJeFUW 53ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="eMQZWc/s"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x9-v6si1216060qka.303.2018.07.03.08.23.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 03 Jul 2018 08:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="eMQZWc/s"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faN9R-0001gh-I1 for patch@linaro.org; Tue, 03 Jul 2018 11:23:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faN3k-0006IR-3K for qemu-devel@nongnu.org; Tue, 03 Jul 2018 11:17:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faN3i-0000Mh-L5 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 11:17:40 -0400 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:42184) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1faN3i-0000MG-FI for qemu-devel@nongnu.org; Tue, 03 Jul 2018 11:17:38 -0400 Received: by mail-pg0-x244.google.com with SMTP id c10-v6so1126279pgu.9 for ; Tue, 03 Jul 2018 08:17:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x2t1XFI2QFPK2VzG0H6uB4M9ibalVxnRLpzzWNvPaFo=; b=eMQZWc/sw7hB9QWhhfnqh1BxXPNc4BdZM8QgKiRX/2Hp4YtKyjXCI0hgojchkFovhp BxjCjaWfMheb/pMx8n1bFR+SVXJPQNHOXrFfy49Tp37E0UwTLX52moY1GRq3wF5O8L7v tkspR2bL8HCX6k9LoKGzyruI/l0mug1cfMM5E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x2t1XFI2QFPK2VzG0H6uB4M9ibalVxnRLpzzWNvPaFo=; b=kZP3CWmeBcxT4dF+Nv9wHEDZ2g34T8ZLd2qDbS4rkNRR1xLtRqDlO3hZ1X02NKXEO+ w1kB8xtYOZZkapaFKd88sd7xg7przk5mcQ0KY7NIZ5nD/LjR32VCUXqIVYtFbU88FE22 sbtw596AQUGmf2RoRH/pulyJ1PM0xxIbUp29Jj6JJ8vMELuzfIDGN6BKN/6aRc3z2oMe 6bJFQ+P3cgOmkuy/eGk/y0uBYaAE6TX7O/lFMTTJ0jOS83CfGQKgC5HJ17xSBUPT6LU0 x+icnnFzrRAm+neOK5h7EcNSMsdtcAgZw9I9gJX0WsLc1042dhwo6nNweKsc9r7WKS4g I1kQ== X-Gm-Message-State: APt69E3ccwyJNlaip2KWo0Q99JjkcQOt+JDnLZb+oZPOgrJncW9981bi eYC9SR7IMxkAUJBqMvML/IaySlGm/jY= X-Received: by 2002:a65:4e09:: with SMTP id r9-v6mr25493523pgt.369.1530631057244; Tue, 03 Jul 2018 08:17:37 -0700 (PDT) Received: from cloudburst.twiddle.net (97-126-112-211.tukw.qwest.net. [97.126.112.211]) by smtp.gmail.com with ESMTPSA id s185-v6sm4834201pfb.116.2018.07.03.08.17.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Jul 2018 08:17:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2018 08:17:27 -0700 Message-Id: <20180703151732.29843-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180703151732.29843-1-richard.henderson@linaro.org> References: <20180703151732.29843-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::244 Subject: [Qemu-devel] [PATCH 2/7] target/ppc: Honor fpscr_ze semantics and tidy fdiv 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: programmingkidx@gmail.com, qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Divide by zero, exception taken, leaves the destination register unmodified. Therefore we must raise the exception before returning from helper_fdiv. Move the check from do_float_check_status into helper_fdiv. 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 --- target/ppc/helper.h | 2 +- target/ppc/fpu_helper.c | 44 ++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 23 deletions(-) -- 2.17.1 diff --git a/target/ppc/helper.h b/target/ppc/helper.h index d751f0e219..151437d8fc 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -88,7 +88,7 @@ DEF_HELPER_2(frim, i64, env, i64) DEF_HELPER_3(fadd, i64, env, i64, i64) DEF_HELPER_3(fsub, i64, env, i64, i64) DEF_HELPER_3(fmul, i64, env, i64, i64) -DEF_HELPER_3(fdiv, i64, env, i64, i64) +DEF_HELPER_3(fdiv, f64, env, f64, f64) DEF_HELPER_4(fmadd, i64, env, i64, i64, i64) DEF_HELPER_4(fmsub, i64, env, i64, i64, i64) DEF_HELPER_4(fnmadd, i64, env, i64, i64, i64) diff --git a/target/ppc/fpu_helper.c b/target/ppc/fpu_helper.c index 119826b5a7..0df7e31c10 100644 --- a/target/ppc/fpu_helper.c +++ b/target/ppc/fpu_helper.c @@ -543,9 +543,7 @@ static void do_float_check_status(CPUPPCState *env, uintptr_t raddr) CPUState *cs = CPU(ppc_env_get_cpu(env)); int status = get_float_exception_flags(&env->fp_status); - if (status & float_flag_divbyzero) { - float_zero_divide_excp(env, raddr); - } else if (status & float_flag_overflow) { + if (status & float_flag_overflow) { float_overflow_excp(env); } else if (status & float_flag_underflow) { float_underflow_excp(env); @@ -653,30 +651,32 @@ uint64_t helper_fmul(CPUPPCState *env, uint64_t arg1, uint64_t arg2) } /* fdiv - fdiv. */ -uint64_t helper_fdiv(CPUPPCState *env, uint64_t arg1, uint64_t arg2) +float64 helper_fdiv(CPUPPCState *env, float64 arg1, float64 arg2) { - CPU_DoubleU farg1, farg2; + float64 ret = float64_div(arg1, arg2, &env->fp_status); + int status = get_float_exception_flags(&env->fp_status); - farg1.ll = arg1; - farg2.ll = arg2; - - if (unlikely(float64_is_infinity(farg1.d) && - float64_is_infinity(farg2.d))) { - /* Division of infinity by infinity */ - farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIDI, 1); - } else if (unlikely(float64_is_zero(farg1.d) && float64_is_zero(farg2.d))) { - /* Division of zero by zero */ - farg1.ll = float_invalid_op_excp(env, POWERPC_EXCP_FP_VXZDZ, 1); - } else { - if (unlikely(float64_is_signaling_nan(farg1.d, &env->fp_status) || - float64_is_signaling_nan(farg2.d, &env->fp_status))) { - /* sNaN division */ - float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); + if (unlikely(status)) { + if (status & float_flag_invalid) { + /* Determine what kind of invalid operation was seen. */ + if (float64_is_infinity(arg1) && float64_is_infinity(arg2)) { + /* Division of infinity by infinity */ + float_invalid_op_excp(env, POWERPC_EXCP_FP_VXIDI, 1); + } else if (float64_is_zero(arg1) && float64_is_zero(arg2)) { + /* Division of zero by zero */ + float_invalid_op_excp(env, POWERPC_EXCP_FP_VXZDZ, 1); + } else if (float64_is_signaling_nan(arg1, &env->fp_status) || + float64_is_signaling_nan(arg2, &env->fp_status)) { + /* sNaN division */ + float_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN, 1); + } + } + if (status & float_flag_divbyzero) { + float_zero_divide_excp(env, GETPC()); } - farg1.d = float64_div(farg1.d, farg2.d, &env->fp_status); } - return farg1.ll; + return ret; }