From patchwork Tue Jan 22 21:50:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 156328 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp43904jaa; Tue, 22 Jan 2019 13:57:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN6RO42UzPE/oMB7Q7LMDkDYMRVjLzwLU7UxXPe+uVjV3QO5w523w8yWW+RPxrHH0/oUW17r X-Received: by 2002:adf:fd87:: with SMTP id d7mr33456272wrr.74.1548194251268; Tue, 22 Jan 2019 13:57:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548194251; cv=none; d=google.com; s=arc-20160816; b=jl/AjQ0JhczEGbnEAIFfiMm95GHrNczKLoFYKBb2exTlVHPPF7MN0Qr6NT7eWZAYwn 7DGk6h6lY7B3QDM9M60Iu1OQ9/D0MwUU0tKDLBdqJLs7nhm3btCZTUuP24pm/mp+Zlaw T3YtJ7N+uTItBsxzztrpyj+g33gT7IXMs/uOnY2lZ9WUPQkH/mPl3ReBIdOM5PRkIOLF eANcq5CBNcsilx0kNEZTJUWsvN5kY9si3dGjP/pHbOWnGYrp+0U5Pgq7aNnSA1GRHWtd 6xGQbNwA9GB0/fLQM44jTvC+MjsvOtvchwiDhHX/guhtzhF2lHSsgkNtWujuOOlg0JNj BxYQ== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=faBd61OejxUkxq2rvQ3pDsb42Y/YIlwTE9s8AKa1cmg=; b=K8WXC8935Rvi4pVl/MFprnBYz7KEQYE7aV/nCq4DR3PpSOi0pw31suMG7dLB5dH5bq CdOW2vzB1Qp5xsBG9MgdhRpuPJQdlhI3nRa74N/b5dDyLF5IYK0tje6WO9BNzBG8r88W Ata0gYDJOkaofr2d9N7+Ehvmu5WMilCoF/MMfkoJtFyhQVv6qevaz3Jzz7fxmINxIZ5B XZI0NgBqQm4oPItVdO7sougU+EGg5s6tri1WWJDEhn9ButQnH2FVcjl2JW0C8571NK2k GZFAUHr1VBG7Rl6mOKvClFy6TiPPmgBpwykC6qxzOF8++1qMGk0MPt2FSJZ8lAw5dJeY 1+ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KeP0kqWa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id r2si80385489wrc.441.2019.01.22.13.57.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 22 Jan 2019 13:57:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KeP0kqWa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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 ([127.0.0.1]:50867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm430-00049D-5O for patch@linaro.org; Tue, 22 Jan 2019 16:57:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gm3wQ-0007SZ-Bh for qemu-devel@nongnu.org; Tue, 22 Jan 2019 16:50:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gm3wP-0008Eu-25 for qemu-devel@nongnu.org; Tue, 22 Jan 2019 16:50:42 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:53089) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gm3wL-0007ph-70 for qemu-devel@nongnu.org; Tue, 22 Jan 2019 16:50:37 -0500 Received: by mail-wm1-x341.google.com with SMTP id m1so81910wml.2 for ; Tue, 22 Jan 2019 13:50:23 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=faBd61OejxUkxq2rvQ3pDsb42Y/YIlwTE9s8AKa1cmg=; b=KeP0kqWau5nI7FaqnskD8K9BYGaUs789d8O9AfKetFJ/Y1t/oWMlUn3MgA26p7Sg4n acl1XhdHokeENrbBPX3G7UqIvpB6iIeVZJHqhV/kPg1q6sU6ZtIEczVgg6UPgjQfqyNW 0zDK5tbBhq+OgNjlIKZexY8edRBF2YIjSMD6I= 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:mime-version:content-transfer-encoding; bh=faBd61OejxUkxq2rvQ3pDsb42Y/YIlwTE9s8AKa1cmg=; b=E4gTOxL0JH+K9CpANJye0kH7W21OceD6rF1KIYI672D5Wtxr/AobSnPTR28WFMRdhT puOrDoRMzWsOYPYn2aCUOhTrIiSXInYXuDV5QGbX1kB1XBPjFtJP8KkDG65GK8lZiSjy l+EzZFvWo0fe1fMm8Oaht73Qqzc6rlZxloPzyHeaEPPue94CYD9+fK5+NNlvxEceAj10 zJRYi9CSCaJP7TM6TaAC0wsy1npp82oys7wYHu3iYFJdhrW+OmVy3cWSEBMrnFBz9tC5 +DsUTBNjiBIwUkDZVaSslF4Lw+qQqV2dtpY+2Kr370LEuBj/VdVQSF0P3Xva00rXlVWq qlpA== X-Gm-Message-State: AJcUukfCe7LzD+I9mZE8Q58LEJirT3ZHOJZYUpv3ZCU00bT+m4HOLAbX 6WYq7cI30M1F5i4VdJyGaF6lQ47qDJY= X-Received: by 2002:a1c:4855:: with SMTP id v82mr179502wma.15.1548193822289; Tue, 22 Jan 2019 13:50:22 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id f187sm39611990wma.4.2019.01.22.13.50.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Jan 2019 13:50:19 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AD8E33E0B76; Tue, 22 Jan 2019 21:50:16 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Tue, 22 Jan 2019 21:50:12 +0000 Message-Id: <20190122215016.18697-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190122215016.18697-1-alex.bennee@linaro.org> References: <20190122215016.18697-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PATCH v3 07/11] softfloat: enforce softfloat if the host's FMA is broken 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 , "Emilio G. Cota" , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" The added branch to the FMA ops is marked as unlikely and therefore its impact on performance (measured with fp-bench) is within noise range when measured on an Intel(R) Xeon(R) Gold 6142 CPU @ 2.60GHz. Reported-by: Laurent Desnogues Signed-off-by: Emilio G. Cota Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée --- fpu/softfloat.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) -- 2.17.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 59eac97d10..9132d7a0b0 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1542,6 +1542,8 @@ soft_f64_muladd(float64 a, float64 b, float64 c, int flags, return float64_round_pack_canonical(pr, status); } +static bool force_soft_fma; + float32 QEMU_FLATTEN float32_muladd(float32 xa, float32 xb, float32 xc, int flags, float_status *s) { @@ -1562,6 +1564,11 @@ float32_muladd(float32 xa, float32 xb, float32 xc, int flags, float_status *s) if (unlikely(!f32_is_zon3(ua, ub, uc))) { goto soft; } + + if (unlikely(force_soft_fma)) { + goto soft; + } + /* * When (a || b) == 0, there's no need to check for under/over flow, * since we know the addend is (normal || 0) and the product is 0. @@ -1623,6 +1630,11 @@ float64_muladd(float64 xa, float64 xb, float64 xc, int flags, float_status *s) if (unlikely(!f64_is_zon3(ua, ub, uc))) { goto soft; } + + if (unlikely(force_soft_fma)) { + goto soft; + } + /* * When (a || b) == 0, there's no need to check for under/over flow, * since we know the addend is (normal || 0) and the product is 0. @@ -7974,3 +7986,24 @@ float128 float128_scalbn(float128 a, int n, float_status *status) , status); } + +static void __attribute__((constructor)) softfloat_init(void) +{ + union_float64 ua, ub, uc, ur; + + if (QEMU_NO_HARDFLOAT) { + return; + } + /* + * Test that the host's FMA is not obviously broken. For example, + * glibc < 2.23 can perform an incorrect FMA on certain hosts; see + * https://sourceware.org/bugzilla/show_bug.cgi?id=13304 + */ + ua.s = 0x0020000000000001ULL; + ub.s = 0x3ca0000000000000ULL; + uc.s = 0x0020000000000000ULL; + ur.h = fma(ua.h, ub.h, uc.h); + if (ur.s != 0x0020000000000001ULL) { + force_soft_fma = true; + } +}