From patchwork Tue Dec 3 20:39:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 846973 Delivered-To: patch@linaro.org Received: by 2002:a5d:44cd:0:b0:385:e875:8a9e with SMTP id z13csp714926wrr; Tue, 3 Dec 2024 12:40:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWPae0cRmZ/gtGoC+eskpfbSn94EgBj7eLlG3fwLVmCpaYAa/mdRR/N8W5XacbMn19zBWbjqw==@linaro.org X-Google-Smtp-Source: AGHT+IFPyfHkf/85JOzJ/fa9+s2GNlpXQjgIcaZK6wzVcCMSzcroxhsROMTHlAVWaMn9AnGs9ys5 X-Received: by 2002:a05:622a:6203:b0:466:afb6:6602 with SMTP id d75a77b69052e-46717cdfafcmr31274681cf.49.1733258448036; Tue, 03 Dec 2024 12:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733258448; cv=none; d=google.com; s=arc-20240605; b=TvjcL+efo2oINoF18eI1e3xVTQSzovHmpN/4MfsRCFTxHVOkV0PAnHlmyyQ5x+fj+q QNPG/kJ+SjIfydB7KeL91q0Q6RAoi8zsPPcjK/QY539ZVy8BNnEvR40wKa9dxYQeypce 7yAPSIliCT1Y3wBeUWirlDkJyuHREBhfITvNwr4WmQLqF81mwZqJNxLbjVQcuKmEW6/4 rtvLMkSoAnosnoKrwYAL39W0LfY/AwhC4xnVpgijMcvNKDMr7TNCn9M7XshUVgqxyb0e xpbuP39vgGsoF2XUCoYDU9vP15mp8jh6D3u3d6gX09N0d4no7crtxp7Eblu4HOwBYUvk UFdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vE9Xl02UsRFXlQRaYTkoaksxQH+Xcw8LkQwIo9WLMj4=; fh=UQCixiNfr28ZOrfhmxiGPA65dFhly8CmRsnoYC6xI9k=; b=QVHpwILTbPS5+X2ZoxO0LOnyC0v87RvQK4Q4GtAeogBcqeB2FxFn6bQaBv0cfJpCGs rJiVqJMpUJ22FuYLg4KgCqX1JkNGhnUAox+DCErY5ATQK6MjHPUaAGdp9q3k+cNoom1U jZfvP9HdqXc7t1v+Ileipm5ByC6JAHiomQay3KBDF0P/4e/C+MVxfFQ/Ke89vO/misNC y0imwZe3l67pBvDyQehatfH3V9sJrNNmZDoQ1D5DmwZzCUSIi2SOqoy8qyNedqnDA1tw tnN89rVu/8zBvcTYbg8+6AgPysZnrs7TrrP/yL+OSkRM9Aw97j0hLgLRgP1Ibfsf1S7i BRaw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Aqdk3YRo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-466d78322e6si129286931cf.127.2024.12.03.12.40.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Dec 2024 12:40:48 -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=pass header.i=@linaro.org header.s=google header.b=Aqdk3YRo; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIZh9-0001cd-0h; Tue, 03 Dec 2024 15:40:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIZgh-0001Qo-L9 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 15:40:04 -0500 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIZgd-0003Bu-V5 for qemu-devel@nongnu.org; Tue, 03 Dec 2024 15:40:01 -0500 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3ea36b05654so3055760b6e.1 for ; Tue, 03 Dec 2024 12:39:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733258399; x=1733863199; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vE9Xl02UsRFXlQRaYTkoaksxQH+Xcw8LkQwIo9WLMj4=; b=Aqdk3YRoihF5I5Sm2EzaMdqKOmvHTL3Oy9a7UT13m6rwgmuggvay56dC+6Bdp8wIcH Z6r3+TJFb3uGHNuWl/fV/36JPNGlq6nLnnwzzqVmEzbtJBBX3H/7a5gSFVJ3DLNwuhkF j5EgG3PeI2x9a1YTRZZOqwznNn6mkqcFa+H+Up1BLl31qOtf3Tmc/ftCPTchLd+fAnws XTenH01nhpBAMJDQkhGzr4Yo4QRwm/tiaRxn47LICuXaplTWZiTsvsGnvlqbCJlSDXeX n3kj471hpgG9ggtiR9yQu+16I18QveuDNpjVXYuTx6ilzX231GvZ72o3dHI4kCXfrfdm IiSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733258399; x=1733863199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vE9Xl02UsRFXlQRaYTkoaksxQH+Xcw8LkQwIo9WLMj4=; b=vv9gfK2S6hzRk4mPIC9up7ZkjFWPF9HKQZKCuL1Cg1NvlOqKIoa/pXM8reT/8F6e79 X9f27QuJpwPJx4kW6ZXKTotUUZZEnfw790cdVMh3C6ZSeYSBWntRpiNnKlItt1Y6rVJy Sq6V31y8u2RzUsEmdxCjWDqVfN8gl6dLEb+6lQDM0HG5zaWcikRpiRo2KfMYIjRCsEU+ OvPRZPvu3b+Io4Yh8n5/kdJFZVOIcknhlU3xLNbmyJ+2fA1HmtyuR7/Lkb6WJoICW6JO JsglCr6kBmzTWR6EB1M+e6scvz+T5A4pkgYi3QM0k9hd8cI2t6Pwr09a6V0w4aU128BD jKHw== X-Gm-Message-State: AOJu0YxCjF9Y0dSZaivkLIiFrfa2iPO6Z7VTkf2QZWB7nyUXsDY2gatt MbcgI3NtPUE5u0s7jqK4bH8vVmb2PQ06jSO3Fc50kRHKjON0Ss9UO4p3X5xPnf8uQlNk2YQnpR3 Gvio= X-Gm-Gg: ASbGnctIy/8RA/q368xORJB3wWjOWbE9W4DK31aMcUw8bld1tvV9pZe7+63Py8YZk1U is3YRYs6DKHJAXRCeKZvHoSU0BDVXUL047y1FBr6yfTM+QKUnRY3lZHiO2Es/M7kRm9F+fhr5wa UOZZn90rcCjdw7E7meb96BOPYKd4/XOguEZW031BY+oQUr8yB2L4MKgAX7g1F/18+S+8LVp/uuH GIp/CxBBFgBQW+pfsnHcpqUnS21AY79wJbEH7brnFTVmsPSQdESfsp/VT9F1EYjphds0fPvh3CI jNBJ6K6usZnI5mnZQwNEYLniUa+LGkeIq87p X-Received: by 2002:a05:6808:17a8:b0:3e7:5af6:af0f with SMTP id 5614622812f47-3eaf04252cbmr910702b6e.39.1733258398717; Tue, 03 Dec 2024 12:39:58 -0800 (PST) Received: from localhost.localdomain (fixed-187-189-51-143.totalplay.net. [187.189.51.143]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29e3ae09f25sm2684018fac.49.2024.12.03.12.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 12:39:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org Subject: [PATCH 08/11] softfloat: Inline pickNaN Date: Tue, 3 Dec 2024 14:39:45 -0600 Message-ID: <20241203203949.483774-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241203203949.483774-1-richard.henderson@linaro.org> References: <20241203203949.483774-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x22b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Inline pickNaN into its only caller. This makes one assert redundant with the immediately preceding IF. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- fpu/softfloat-parts.c.inc | 82 +++++++++++++++++++++++++---- fpu/softfloat-specialize.c.inc | 96 ---------------------------------- 2 files changed, 73 insertions(+), 105 deletions(-) diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 06cfc6abb5..de51097dcf 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -39,24 +39,88 @@ static void partsN(return_nan)(FloatPartsN *a, float_status *s) static FloatPartsN *partsN(pick_nan)(FloatPartsN *a, FloatPartsN *b, float_status *s) { + int cmp, which; + if (is_snan(a->cls) || is_snan(b->cls)) { float_raise(float_flag_invalid | float_flag_invalid_snan, s); } if (s->default_nan_mode) { parts_default_nan(a, s); - } else { - int cmp = frac_cmp(a, b); - if (cmp == 0) { - cmp = a->sign < b->sign; - } + return a; + } - if (pickNaN(a->cls, b->cls, cmp > 0, s)) { - a = b; - } + cmp = frac_cmp(a, b); + if (cmp == 0) { + cmp = a->sign < b->sign; + } + + switch (s->float_2nan_prop_rule) { + case float_2nan_prop_s_ab: if (is_snan(a->cls)) { - parts_silence_nan(a, s); + which = 0; + } else if (is_snan(b->cls)) { + which = 1; + } else if (is_qnan(a->cls)) { + which = 0; + } else { + which = 1; } + break; + case float_2nan_prop_s_ba: + if (is_snan(b->cls)) { + which = 1; + } else if (is_snan(a->cls)) { + which = 0; + } else if (is_qnan(b->cls)) { + which = 1; + } else { + which = 0; + } + break; + case float_2nan_prop_ab: + which = is_nan(a->cls) ? 0 : 1; + break; + case float_2nan_prop_ba: + which = is_nan(b->cls) ? 1 : 0; + break; + case float_2nan_prop_x87: + /* + * This implements x87 NaN propagation rules: + * SNaN + QNaN => return the QNaN + * two SNaNs => return the one with the larger significand, silenced + * two QNaNs => return the one with the larger significand + * SNaN and a non-NaN => return the SNaN, silenced + * QNaN and a non-NaN => return the QNaN + * + * If we get down to comparing significands and they are the same, + * return the NaN with the positive sign bit (if any). + */ + if (is_snan(a->cls)) { + if (is_snan(b->cls)) { + which = cmp > 0 ? 0 : 1; + } else { + which = is_qnan(b->cls) ? 1 : 0; + } + } else if (is_qnan(a->cls)) { + if (is_snan(b->cls) || !is_qnan(b->cls)) { + which = 0; + } else { + which = cmp > 0 ? 0 : 1; + } + } else { + which = 1; + } + break; + default: + g_assert_not_reached(); + } + + if (which) { + a = b; + } + if (is_snan(a->cls)) { + parts_silence_nan(a, s); } return a; } diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc index f7a320f6ff..cbbbab52ba 100644 --- a/fpu/softfloat-specialize.c.inc +++ b/fpu/softfloat-specialize.c.inc @@ -352,102 +352,6 @@ bool float32_is_signaling_nan(float32 a_, float_status *status) } } -/*---------------------------------------------------------------------------- -| Select which NaN to propagate for a two-input operation. -| IEEE754 doesn't specify all the details of this, so the -| algorithm is target-specific. -| The routine is passed various bits of information about the -| two NaNs and should return 0 to select NaN a and 1 for NaN b. -| Note that signalling NaNs are always squashed to quiet NaNs -| by the caller, by calling floatXX_silence_nan() before -| returning them. -| -| aIsLargerSignificand is only valid if both a and b are NaNs -| of some kind, and is true if a has the larger significand, -| or if both a and b have the same significand but a is -| positive but b is negative. It is only needed for the x87 -| tie-break rule. -*----------------------------------------------------------------------------*/ - -static int pickNaN(FloatClass a_cls, FloatClass b_cls, - bool aIsLargerSignificand, float_status *status) -{ - /* - * We guarantee not to require the target to tell us how to - * pick a NaN if we're always returning the default NaN. - * But if we're not in default-NaN mode then the target must - * specify via set_float_2nan_prop_rule(). - */ - assert(!status->default_nan_mode); - - switch (status->float_2nan_prop_rule) { - case float_2nan_prop_s_ab: - if (is_snan(a_cls)) { - return 0; - } else if (is_snan(b_cls)) { - return 1; - } else if (is_qnan(a_cls)) { - return 0; - } else { - return 1; - } - break; - case float_2nan_prop_s_ba: - if (is_snan(b_cls)) { - return 1; - } else if (is_snan(a_cls)) { - return 0; - } else if (is_qnan(b_cls)) { - return 1; - } else { - return 0; - } - break; - case float_2nan_prop_ab: - if (is_nan(a_cls)) { - return 0; - } else { - return 1; - } - break; - case float_2nan_prop_ba: - if (is_nan(b_cls)) { - return 1; - } else { - return 0; - } - break; - case float_2nan_prop_x87: - /* - * This implements x87 NaN propagation rules: - * SNaN + QNaN => return the QNaN - * two SNaNs => return the one with the larger significand, silenced - * two QNaNs => return the one with the larger significand - * SNaN and a non-NaN => return the SNaN, silenced - * QNaN and a non-NaN => return the QNaN - * - * If we get down to comparing significands and they are the same, - * return the NaN with the positive sign bit (if any). - */ - if (is_snan(a_cls)) { - if (is_snan(b_cls)) { - return aIsLargerSignificand ? 0 : 1; - } - return is_qnan(b_cls) ? 1 : 0; - } else if (is_qnan(a_cls)) { - if (is_snan(b_cls) || !is_qnan(b_cls)) { - return 0; - } else { - return aIsLargerSignificand ? 0 : 1; - } - } else { - return 1; - } - default: - g_assert_not_reached(); - } -} - /*---------------------------------------------------------------------------- | Returns 1 if the double-precision floating-point value `a' is a quiet | NaN; otherwise returns 0.