From patchwork Thu Dec 20 11:10:08 2018 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: 1016721 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=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="MAOzAc4J"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43L8FS0ylnz9s55 for ; Thu, 20 Dec 2018 22:10:50 +1100 (AEDT) Received: from localhost ([::1]:36651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZwE2-0007il-NM for incoming@patchwork.ozlabs.org; Thu, 20 Dec 2018 06:10:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZwDi-0007iU-R2 for qemu-devel@nongnu.org; Thu, 20 Dec 2018 06:10:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZwDf-0002T1-Ns for qemu-devel@nongnu.org; Thu, 20 Dec 2018 06:10:26 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:40182) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gZwDf-0002S0-EX for qemu-devel@nongnu.org; Thu, 20 Dec 2018 06:10:23 -0500 Received: by mail-wm1-x341.google.com with SMTP id f188so1654201wmf.5 for ; Thu, 20 Dec 2018 03:10:22 -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:mime-version :content-transfer-encoding; bh=CLEy4EypX5hb9wrXwR6jYX+R+Inoh2VumlXfXIcCTuc=; b=MAOzAc4Jxrt/rke5ucKy0EyXV5/aTFOQVmSPsAAL3FI171qMtQeuYx/8FtVjeERH7x pz6+ZQM4XYlwRsw0nYvzf/eIAMWCVMXgE53HwVVayw8jy2wgdFgP8S+VH++dONpB0khW OkwLK5WXCTg/e6K/zitt1BJEEydZRLWKQqPcI= 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:mime-version :content-transfer-encoding; bh=CLEy4EypX5hb9wrXwR6jYX+R+Inoh2VumlXfXIcCTuc=; b=LJP04J4aEWp4WrUVVvXDZidHi17W05HAdNUV7xO/gpKRUW9FaprFarGX5H8GLy25SK IALMAOaBucjnaGQpieyJo3QZRS7BHUUoDfXR19H/SbH21yRz4kySNZipneY3adefd4tQ 4cL0LSZ/xzumFxjm5ogQ7EGBkbuFf1Qlk1UnHOOVGlj83hlsSD8N/8vanfQd6kTQzykH +RRkWuVhtRuNTSFdrwiK2xZ7D2fiIUEox5eujSW52DVcCACDP42RHTYpc3TYAcL4HabX nETbmg9cFYLCSr8AmbHvBFDdkTlFr2YEwTtZZrQvIam3oHVGuRZRTjorD9XPEm3yI9EP UgAA== X-Gm-Message-State: AA+aEWY83x5Wyux7mfpsIBXtVaIfZTo3y+Qx2kdKFtVO7uUKivyGzyPO 5ds3G+viqmh6kVtBGN6EpHRn4Q== X-Google-Smtp-Source: AFSGD/V4XRRsgB3bRTlSTh3QgaXe4ynHFibBFUmO2CTeXWQQ3URhnDrNpXuOt1xjTvG05RE6/tuqdw== X-Received: by 2002:a1c:87cc:: with SMTP id j195mr10891234wmd.2.1545304221637; Thu, 20 Dec 2018 03:10:21 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l20sm16930297wrb.93.2018.12.20.03.10.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Dec 2018 03:10:20 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id C31EF3E059D; Thu, 20 Dec 2018 11:10:19 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 20 Dec 2018 11:10:08 +0000 Message-Id: <20181220111008.24954-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 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] [RFC PATCH] fpu: add compile time check for old glibc/libm and fma 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: laurent.desnogues@gmail.com, Peter Maydell , "Emilio G . Cota" , =?utf-8?q?Alex_Benn=C3=A9e?= , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Some versions of glibc have been reported to have problems with fused-multiply-accumulate operations. If the underlying fma implementation does a two step operation it will instroduce subtle rounding errors. Newer versions of the library seem to deal with this better and modern hardware has fused operations which the library can use. Reported-by: Laurent Desnogues Signed-off-by: Alex Bennée Cc: Emilio G. Cota Acked-by: Aleksandar Markovic Tested-by: Laurent Desnogues --- fpu/softfloat.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 59eac97d10..9c2dbd04b5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -203,6 +203,25 @@ GEN_INPUT_FLUSH3(float64_input_flush3, float64) # define QEMU_HARDFLOAT_3F64_USE_FP 0 #endif +/* + * Choose whether to accelerate fused multiply-accumulate operations + * with hard float functions. Some versions of glibc's maths library + * have been reported to be broken on x86 without FMA instructions. + */ +#if defined(__x86_64__) +/* this was actually reported as glibc-2.12-1.149.el6_6.5.x86_64 was + * broken but glibc 2.12-1.209 works but out of caution lets disable + * for all older glibcs. + */ +#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 12) +#define QEMU_HARDFLOAT_USE_FMA 0 +#else +#define QEMU_HARDFLOAT_USE_FMA 1 +#endif +#else +#define QEMU_HARDFLOAT_USE_FMA 1 +#endif + /* * QEMU_HARDFLOAT_USE_ISINF chooses whether to use isinf() over * float{32,64}_is_infinity when !USE_FP. @@ -1551,6 +1570,9 @@ float32_muladd(float32 xa, float32 xb, float32 xc, int flags, float_status *s) ub.s = xb; uc.s = xc; + if (!QEMU_HARDFLOAT_USE_FMA) { + goto soft; + } if (unlikely(!can_use_fpu(s))) { goto soft; } @@ -1612,6 +1634,9 @@ float64_muladd(float64 xa, float64 xb, float64 xc, int flags, float_status *s) ub.s = xb; uc.s = xc; + if (!QEMU_HARDFLOAT_USE_FMA) { + goto soft; + } if (unlikely(!can_use_fpu(s))) { goto soft; }