From patchwork Wed Jan 16 20:23:45 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: 155760 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1098290jaa; Wed, 16 Jan 2019 12:24:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Nayimpl20crairt8gjAytJOGWNkCQruy21lRTb+QIUDVq5y/rYSRdHX2nyqbJfrfY6h7F X-Received: by 2002:adf:fe8f:: with SMTP id l15mr8633774wrr.313.1547670261234; Wed, 16 Jan 2019 12:24:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547670261; cv=none; d=google.com; s=arc-20160816; b=IohL4OayAtMQgdTZvIcWWHGZbjbLQPRYIZDlBuFQteOz6jIcJ2Xst50SCALKINQNTK kKVlPtp1UpHU2COAOCJ0lB5F12A3udzcAMypmSyoaXavavrRI1pvTJlNGfnGz2/CKx3k VGe3hx2HZrnqNdIkF1ryiTgzZgL1gC+VVp+HXW+t7wpxZaAo86RiIzqpoeth1/uWPxMl ij+4Xh6eufckQaX4DctkjaShn2l2HoM+fQ5dOPPIct4lfqoSDVwJXyo/VB9UWRtCYwnD 7bWokyfNbNuGQdeoljLm8xRjC++a+N85xQ4cBoVXO3gakcQAhXYPOGWBOyClb/3hgYSO YRaA== 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=V4sA7A65E2SWFC74zBDODZmknqvCshvStCQltJmAmqo=; b=Ieayl8UIeIYk9KFHJG0Mz6TKkOaDUSaLYROVte+bYQ5PNJlsl7w3VG7tv/IfS3jdis G+9SkXfQobhxOljBfGVKLtmuYi5BUVfYVHE5cjGdGVf3fVc+VcIFb/gH7avUN++VoTbn 8GyKJnvpBXHJco8NGWoAQ/gNgikoJ+yVOCYWAVyL6Y2DIHqhmZmh1ifRJ4CM7oARLM1g lvAuTxd6ACnt32mpmBILLsrLAg57AusUFCm6pfna+nk0z25VvruwW+PmOiohQ3f2icZ/ A7Zk4Ycs5q8998lJTxPrDZTjwBoomp19d3KigI84p7yN/HEezWO5EY7A6MkezU0ny/LK l7zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=adhpLQus; 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 h4si23385843wmh.124.2019.01.16.12.24.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 16 Jan 2019 12:24:21 -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=adhpLQus; 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]:45331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjrjX-0006yX-NU for patch@linaro.org; Wed, 16 Jan 2019 15:24:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gjrj9-0006ut-GW for qemu-devel@nongnu.org; Wed, 16 Jan 2019 15:23:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gjrj8-000653-HV for qemu-devel@nongnu.org; Wed, 16 Jan 2019 15:23:55 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:34597) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gjrj8-00060F-AN for qemu-devel@nongnu.org; Wed, 16 Jan 2019 15:23:54 -0500 Received: by mail-wm1-x342.google.com with SMTP id y185so1921552wmd.1 for ; Wed, 16 Jan 2019 12:23:54 -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=V4sA7A65E2SWFC74zBDODZmknqvCshvStCQltJmAmqo=; b=adhpLQusJL5zHwRexa4Zd+cLrLGFFUnQ5PJ3RKhZZpJlqmbXUdrMKVQjNJmfPrDlxL NOzx7zZqQd2d4/z2XvWzcbEAhQbgz1XwY3JnuLKaWTSkrDvBrzh+Mpf+urrI/wslfRs+ FlirSqgMltJ2alV5xah4uGcy0LYY6XQpf7hv0= 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=V4sA7A65E2SWFC74zBDODZmknqvCshvStCQltJmAmqo=; b=tHiBr3AyQScFNt3PchDOqdaLea1+6qU3uFIT462vdRHbN2OQaOq1lDPxtFrNE1G5Mj knzYY2ASbnqdTcDcntmjDF2mYpNCvtmTstcY55gqBa8HfSs7/l/u0SlQ36lCeRBhsHLV PQ7JrGbaaS61f3khoOAAzdwXpgKOtWKh6GWL9410mvZvJXHOmEtTPqZ6FMQafGZ61qzU yiKTIZywEmiXHxr/qNN0oPDKW6Yj7xojd6gNLNbEFKU5e9J7rekeFnnB1WCPXpySQTxA 3RITaFUnJd6AHvQS0Msfv9OdlPKqcNVH+dV9QmZUlDZqsp7tyFoP1xFXNQ8wJw4eQenX ZJKA== X-Gm-Message-State: AJcUukeQ2fUgQ7sHEWazKSRkE2YA6d+Iob+qqjhYiXcISfO7xF1u+BLU JXsDFO+7OKJfLKmRN+m6G6PViA== X-Received: by 2002:a7b:c757:: with SMTP id w23mr8430756wmk.59.1547670232663; Wed, 16 Jan 2019 12:23:52 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s1sm115908380wro.9.2019.01.16.12.23.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 12:23:50 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A48A13E0F77; Wed, 16 Jan 2019 20:23:49 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2019 20:23:45 +0000 Message-Id: <20190116202349.29272-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190116202349.29272-1-alex.bennee@linaro.org> References: <20190116202349.29272-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::342 Subject: [Qemu-devel] [PATCH v2 3/7] 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 , cohuck@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , "Emilio G. Cota" , 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 Signed-off-by: Alex Bennée --- fpu/softfloat.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) -- 2.17.1 Reviewed-by: Richard Henderson 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; + } +}