From patchwork Tue May 15 22:25:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135937 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp74687lji; Tue, 15 May 2018 15:27:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpNgrPL5X1x2D7KzSsJxWeLynkNOybYZc1t2XopHUknvN1qZeovwllddF1ImegOrvA6Tvdn X-Received: by 2002:ac8:3487:: with SMTP id w7-v6mr15620922qtb.220.1526423261476; Tue, 15 May 2018 15:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526423261; cv=none; d=google.com; s=arc-20160816; b=rADliuMDeMq5gwEwcpC6DgBYu/OQzGblQsOe+k0B9ePVukpZ96rCsce4fErxdBGhIM qqKs917yyRLHJBT7+ZLI9WS4BqYnV+eyvFLdOS6OlPUKAJ2DyfPR++OuA/EG6CMfsc+F aElLONCowUJN9C7BJn3xrxUz9VuyqSvKW3DR5ktbJ/4SfQ80JC1LgdIKEhUjNdqAo+VS b4DCIa7HZAjPOz1/WiUeOoNWjMRvQDDpTiUdhEN1cQ4TKnNKU8bs8azAAHtggFG6z0cm zJZ2FmshR811YC94+g4l6Hj+CFrFVQKrQ9sKvYsrrOTAWgR7pqcpJgTjEoTuY/2Y0112 yAAA== 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:arc-authentication-results; bh=n043IcTuWLeJOrF4bZrWAR222qKx5CvPEizqYpyknu8=; b=sNPXbSAgZX3GF1CTllFUU2NquiXaLxD8/BEOwZpzP+wGbxRnEPMlTCm9vV4VgpQrvs YzjSX8L/IqqOCyf70Ini4kkyqCRrX05GbYYD7u/FNAb/Zb1AyGWWd1Hlz+YFAchquUi8 BFpwiteXULzWXcCvXwXX7bHHXDyZBIxyVzt3CKAAYzHLJUoQo3qewMGgQm30AmFyoIT+ fzWwtBANXQ7xr6NdAHcFNHi2rvv76JuFHQ4J1oCehY5NRUjzL3Gcigf17p2bq4edwS7m FUzBLEHaH5FkLwmsvfaAD8jWF1CZcuPskA9RsyujS5rV0mAixo6/SicvbHRJlxSrWZY0 xA/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kXb+TbX9; 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 g101-v6si1136717qkh.343.2018.05.15.15.27.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 15 May 2018 15:27:41 -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=kXb+TbX9; 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]:36313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIiQ0-0004QC-Ru for patch@linaro.org; Tue, 15 May 2018 18:27:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIiOO-0003Mg-BT for qemu-devel@nongnu.org; Tue, 15 May 2018 18:26:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fIiOK-0004ay-V2 for qemu-devel@nongnu.org; Tue, 15 May 2018 18:26:00 -0400 Received: from mail-pl0-x22a.google.com ([2607:f8b0:400e:c01::22a]:36260) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fIiOK-0004Ua-LY for qemu-devel@nongnu.org; Tue, 15 May 2018 18:25:56 -0400 Received: by mail-pl0-x22a.google.com with SMTP id v24-v6so867614plo.3 for ; Tue, 15 May 2018 15:25:56 -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 :mime-version:content-transfer-encoding; bh=n043IcTuWLeJOrF4bZrWAR222qKx5CvPEizqYpyknu8=; b=kXb+TbX9LYFrKXDXkFtqLe8gChywchnh7qrLtA5k5qjYyk06SJhBTnFhoPr9Bnlf2l pl9+ID2L05fuplqO/KHfmktu/K7/ATjfASOnyrESblx4DOsvBClURQH99XIQ5IJLyhq5 ZodA7CMwLQ+PrwRlcV/WY6NN7ePz8CeGNgUzw= 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=n043IcTuWLeJOrF4bZrWAR222qKx5CvPEizqYpyknu8=; b=ecb05cYiuKNrB9i/nFtNi3WkgmPWtntGyuOc8G4jBblTILDgylO6k1bEmKLpydD0W0 Wsd0XtTDi4J4Y6q4lIFrVnQcwiiR1ps909drO97GrMQOA1iIQ2MoQtsj0+utml3GxKoE e2pLkSYovbgG9LnemvHBCpDS2Zyij/L9tRi2Gcj+JlaxsFX57uvSZyfTh66YCWJHLN38 qPhStIkhKSBzGJy5YsIWsZbh2io3NfQ/9kvkiId90V/pLaHpEP/LLo9/UgFEkRQDb3Q6 IdyaQBCC8PsDsRniXn/CLT+brRhjMPb28x/Q1H33eB3tNeguZgqA7f8xUIjmrJUKfk2G PPCA== X-Gm-Message-State: ALKqPwdUk9qUR6pia//GLNTM+lzzfV33Yi2xW87dNaE8q222E+V0vcNQ HTt81gOD0HZ5xh20HkoUDROEABLNtOk= X-Received: by 2002:a17:902:274a:: with SMTP id j10-v6mr16636167plg.393.1526423155284; Tue, 15 May 2018 15:25:55 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id g11-v6sm941419pgq.62.2018.05.15.15.25.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 15:25:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 15 May 2018 15:25:20 -0700 Message-Id: <20180515222540.9988-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180515222540.9988-1-richard.henderson@linaro.org> References: <20180515222540.9988-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::22a Subject: [Qemu-devel] [PATCH v6 08/28] fpu/softfloat: Replace float_class_msnan with parts_silence_nan 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@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" With a canonical representation of NaNs, we can silence an SNaN immediately rather than delay until the final format is known. Tested-by: Alex Bennée Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- fpu/softfloat-specialize.h | 23 ++++++++++++++++++++++ fpu/softfloat.c | 40 ++++++++++---------------------------- 2 files changed, 33 insertions(+), 30 deletions(-) -- 2.17.0 diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h index 0d3d81a52b..571d1df378 100644 --- a/fpu/softfloat-specialize.h +++ b/fpu/softfloat-specialize.h @@ -138,6 +138,29 @@ static FloatParts parts_default_nan(float_status *status) }; } +/*---------------------------------------------------------------------------- +| Returns a quiet NaN from a signalling NaN for the deconstructed +| floating-point parts. +*----------------------------------------------------------------------------*/ + +static FloatParts parts_silence_nan(FloatParts a, float_status *status) +{ +#ifdef NO_SIGNALING_NANS + g_assert_not_reached(); +#elif defined(TARGET_HPPA) + a.frac &= ~(1ULL << (DECOMPOSED_BINARY_POINT - 1)); + a.frac |= 1ULL << (DECOMPOSED_BINARY_POINT - 2); +#else + if (status->snan_bit_is_one) { + return parts_default_nan(status); + } else { + a.frac |= 1ULL << (DECOMPOSED_BINARY_POINT - 1); + } +#endif + a.cls = float_class_qnan; + return a; +} + /*---------------------------------------------------------------------------- | The pattern for a default generated half-precision NaN. *----------------------------------------------------------------------------*/ diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 51780b718f..41253c6749 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -188,7 +188,6 @@ typedef enum __attribute__ ((__packed__)) { float_class_inf, float_class_qnan, /* all NaNs from here */ float_class_snan, - float_class_msnan, /* maybe silenced */ } FloatClass; /* @@ -492,14 +491,7 @@ static FloatParts float16_unpack_canonical(float16 f, float_status *s) static float16 float16_round_pack_canonical(FloatParts p, float_status *s) { - switch (p.cls) { - case float_class_msnan: - p.frac >>= float16_params.frac_shift; - return float16_maybe_silence_nan(float16_pack_raw(p), s); - default: - p = round_canonical(p, s, &float16_params); - return float16_pack_raw(p); - } + return float16_pack_raw(round_canonical(p, s, &float16_params)); } static FloatParts float32_unpack_canonical(float32 f, float_status *s) @@ -509,14 +501,7 @@ static FloatParts float32_unpack_canonical(float32 f, float_status *s) static float32 float32_round_pack_canonical(FloatParts p, float_status *s) { - switch (p.cls) { - case float_class_msnan: - p.frac >>= float32_params.frac_shift; - return float32_maybe_silence_nan(float32_pack_raw(p), s); - default: - p = round_canonical(p, s, &float32_params); - return float32_pack_raw(p); - } + return float32_pack_raw(round_canonical(p, s, &float32_params)); } static FloatParts float64_unpack_canonical(float64 f, float_status *s) @@ -526,14 +511,7 @@ static FloatParts float64_unpack_canonical(float64 f, float_status *s) static float64 float64_round_pack_canonical(FloatParts p, float_status *s) { - switch (p.cls) { - case float_class_msnan: - p.frac >>= float64_params.frac_shift; - return float64_maybe_silence_nan(float64_pack_raw(p), s); - default: - p = round_canonical(p, s, &float64_params); - return float64_pack_raw(p); - } + return float64_pack_raw(round_canonical(p, s, &float64_params)); } /* Simple helpers for checking if what NaN we have */ @@ -555,7 +533,7 @@ static FloatParts return_nan(FloatParts a, float_status *s) switch (a.cls) { case float_class_snan: s->float_exception_flags |= float_flag_invalid; - a.cls = float_class_msnan; + a = parts_silence_nan(a, s); /* fall through */ case float_class_qnan: if (s->default_nan_mode) { @@ -584,7 +562,9 @@ static FloatParts pick_nan(FloatParts a, FloatParts b, float_status *s) (a.frac == b.frac && a.sign < b.sign))) { a = b; } - a.cls = float_class_msnan; + if (is_snan(a.cls)) { + return parts_silence_nan(a, s); + } } return a; } @@ -624,8 +604,10 @@ static FloatParts pick_nan_muladd(FloatParts a, FloatParts b, FloatParts c, default: g_assert_not_reached(); } - a.cls = float_class_msnan; + if (is_snan(a.cls)) { + return parts_silence_nan(a, s); + } return a; } @@ -1334,7 +1316,6 @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode, switch (p.cls) { case float_class_snan: case float_class_qnan: - case float_class_msnan: s->float_exception_flags = orig_flags | float_flag_invalid; return max; case float_class_inf: @@ -1425,7 +1406,6 @@ static uint64_t round_to_uint_and_pack(FloatParts in, int rmode, uint64_t max, switch (p.cls) { case float_class_snan: case float_class_qnan: - case float_class_msnan: s->float_exception_flags = orig_flags | float_flag_invalid; return max; case float_class_inf: