From patchwork Fri Mar 22 20:43:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 1061665 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=braap.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="pZLdtwb3"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="B6XHno9T"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Qwps6HwPz9sSS for ; Sat, 23 Mar 2019 07:53:08 +1100 (AEDT) Received: from localhost ([127.0.0.1]:34493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7RA0-000139-Pu for incoming@patchwork.ozlabs.org; Fri, 22 Mar 2019 16:53:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7R9H-0000rd-V1 for qemu-devel@nongnu.org; Fri, 22 Mar 2019 16:52:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h7R0u-0001e2-Sg for qemu-devel@nongnu.org; Fri, 22 Mar 2019 16:43:42 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:39909) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h7R0d-0001CS-7d; Fri, 22 Mar 2019 16:43:36 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id DB8EB21F0C; Fri, 22 Mar 2019 16:43:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 22 Mar 2019 16:43:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h= from:to:cc:subject:date:message-id; s=mesmtp; bh=3tZ7/H+hBqLudgB 8BJbBT8zdL1HYX7xB/pWkNrjYPXU=; b=pZLdtwb31mPRliN030eoQQa3MaGfPKa IwQz3MvOkmbx/L2gHkr8KxkgKkQ0Q6DHVJRh0o9LUx6qAAuVJwHHYQYkh9TwVQb0 K5kY1TfjKIkj3tbg6eI8Jql/5wCKo6u5FolTvV3mm4jApvBKdFvDIJTzJRA0zsMB HQzzDi8ikByU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=3tZ7/H+hBqLudgB8BJbBT8zdL1HYX7xB/pWkNrjYPXU=; b=B6XHno9T MwUKgPzKWrNpkqa4CDcdvSWnduBIuwh7hcsdegeAJZysuQBp2VBj2yfuUtGVnMrF Vp+yfatV0qu2TrducI++V49VP21RR1mVEdgdTG96EPn3It7Y+FrIrTHQEnsXcfwV /6CgIQ8JBAi3mEXlIOkpX1al22X4cW0DzB/nNrBQWk66B+2Y53Eg4wR7jnEtGMvw fa0bPgqAVugq0TGhtYczvEYAWWi7IH/qWpfuwrx2cxZFdBM18nDshcM3R+kkAfaF wKVjdQZT2noqRI96PgCpjhWEkdMUwkbX6AHpCy3JJ90lsyhid9zZSpRTLcosMERD k7U6jigsKjhXqw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrjedugddugeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffosedttdertdertddtnecuhfhrohhmpedfgfhmihhlihhoucfi rdcuvehothgrfdcuoegtohhtrgessghrrggrphdrohhrgheqnecukfhppeduvdekrdehle drvddtrddvudeinecurfgrrhgrmhepmhgrihhlfhhrohhmpegtohhtrgessghrrggrphdr ohhrghenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id A7A46E46B8; Fri, 22 Mar 2019 16:43:20 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Fri, 22 Mar 2019 16:43:20 -0400 Message-Id: <20190322204320.17777-1-cota@braap.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH v2 for-4.0] hardfloat: fix float32/64 fused multiply-add 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: Peter Maydell , qemu-riscv@nongnu.org, Richard Henderson , Kito Cheng , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Kito Cheng Before falling back to softfloat FMA, we do not restore the original values of inputs A and C. Fix it. This bug was caught by running gcc's testsuite on RISC-V qemu. Note that this change gives a small perf increase for fp-bench: Host: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz Command: perf stat -r 3 taskset -c 0 ./fp-bench -o mulAdd -p $prec - $prec = single: - before: 101.71 MFlops 102.18 MFlops 100.96 MFlops - after: 103.63 MFlops 103.05 MFlops 102.96 MFlops - $prec = double: - before: 173.10 MFlops 173.93 MFlops 172.11 MFlops - after: 178.49 MFlops 178.88 MFlops 178.66 MFlops Signed-off-by: Kito Cheng Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Tested-by: Palmer Dabbelt --- fpu/softfloat.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 4610738ab1..2ba36ec370 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1596,6 +1596,9 @@ float32_muladd(float32 xa, float32 xb, float32 xc, int flags, float_status *s) } ur.h = up.h + uc.h; } else { + union_float32 ua_orig = ua; + union_float32 uc_orig = uc; + if (flags & float_muladd_negate_product) { ua.h = -ua.h; } @@ -1608,6 +1611,8 @@ float32_muladd(float32 xa, float32 xb, float32 xc, int flags, float_status *s) if (unlikely(f32_is_inf(ur))) { s->float_exception_flags |= float_flag_overflow; } else if (unlikely(fabsf(ur.h) <= FLT_MIN)) { + ua = ua_orig; + uc = uc_orig; goto soft; } } @@ -1662,6 +1667,9 @@ float64_muladd(float64 xa, float64 xb, float64 xc, int flags, float_status *s) } ur.h = up.h + uc.h; } else { + union_float64 ua_orig = ua; + union_float64 uc_orig = uc; + if (flags & float_muladd_negate_product) { ua.h = -ua.h; } @@ -1674,6 +1682,8 @@ float64_muladd(float64 xa, float64 xb, float64 xc, int flags, float_status *s) if (unlikely(f64_is_inf(ur))) { s->float_exception_flags |= float_flag_overflow; } else if (unlikely(fabs(ur.h) <= FLT_MIN)) { + ua = ua_orig; + uc = uc_orig; goto soft; } }