From patchwork Thu Jun 3 21:41:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 453313 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp627555jao; Thu, 3 Jun 2021 14:44:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB4heSug1qD7NoB0ByKvyBD8JapFDTmiiM2dbzaS3wGco+YnonieU7zeUKJXXvDA5n1MHO X-Received: by 2002:a05:6808:b22:: with SMTP id t2mr8545602oij.67.1622756681732; Thu, 03 Jun 2021 14:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622756681; cv=none; d=google.com; s=arc-20160816; b=QKtDOqBXU/dcAQ79MBOdA2XKyszuaRuNai24iZcXPibMolTguy+bwhgse/BboMYSGk CsMGT6zSSQ9iHUZ+so/bG0Tm6ECLA2h7rmF5316FDYfvuv8jB/XLGiBuzxdiXSVUloR1 h96O8GO2zLPOZYGJKaBVzaEJPMXSqthewyRRTza8z7UJ+sqdL+y/rEv4h5j73RkOhmNi BdNq1FeH1QKYT4DRH0xinw0C2sMVt1Wc/EIDiws979I2nBqwl8SbjnlfABMaixfCP0FM Qv3hgh0RQP703QOcLDjwYfhtpJbL6c2aaJ9C0wO7H8k4rXLeikUT6TYzKUsYQcrRzNY/ fuKQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=WsA5H1SuomDIfHMs/+kNzjnQxEcCGSovs51rLnUzoiU=; b=U2TC6ePuwOx3WYxejfA6LObCCkShq86iiujzHMlqcs95s/OR6yNGxmWeT6xr5svhbY O8ULjvr6fJxCrS/Brcnkl1+XGKM/dRMDs4WNslilnZGmG24ONPeC6Qc3o04CeNBmXFFF TkCQxvOwrjSK7PtBLlFMI9D72XSM1B9eMIxrIpLk9opWDPw/5IkmmXDwqiFORIAkg1xd z2uu3PL17ni1SiXMhfK+bdXRPXU8N1hBoI5TfQYKwykWa1J5HX8AtlgzOX2HvYKHsRwQ jytSHCHFIcf8/SGr1nMD/xQa5gkDIDKztfFIQ6GBHYVW953tlNjn27bjpbg5dPwaLyYg Gc5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dP7hLQuV; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p16si159956oto.74.2021.06.03.14.44.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jun 2021 14:44:41 -0700 (PDT) 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=dP7hLQuV; 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 Received: from localhost ([::1]:57010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lov8r-0001XP-4G for patch@linaro.org; Thu, 03 Jun 2021 17:44:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lov5y-0002Ah-99 for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:42 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:42771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lov5u-00012e-Oh for qemu-devel@nongnu.org; Thu, 03 Jun 2021 17:41:42 -0400 Received: by mail-pl1-x632.google.com with SMTP id v13so3582253ple.9 for ; Thu, 03 Jun 2021 14:41:38 -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=WsA5H1SuomDIfHMs/+kNzjnQxEcCGSovs51rLnUzoiU=; b=dP7hLQuVnKWMn920KUn1YXKSwBLOwSDF9yjYp9atbS4QrOYTthuPJlpEAh4oqu1w0T +30ja24isQQiEEIAlzixdbtTtkaAhb7ygX8kRP3sL1/KQmn0+l4xA66XQTtUSpMXNOaz sbpmVYxh/sG3euRekcSKfMeyyTkG4DGOR9mJpbobGs20fdUPPyX4XmHO9P9LruSbVyHp pEPEWZnlLRVyiuhJ7bwwI9ZIM0JLwsKs6cDAcTY5HoJleTM3afR4wpgYwofVlA1FdJkN P8lIHFEpGd+KGCVQ34ixxRNQCy+gxBLaW7QuegI4DkoyoDgB9cne1+ByfhIdzqB/o/1J wGQw== 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=WsA5H1SuomDIfHMs/+kNzjnQxEcCGSovs51rLnUzoiU=; b=b+E+4rN5rAEbuBIKnN94h/g9Md9YyctexWntp1AMnclb/KjOebQdPOsD981FAtsP8J FNqAEx9OU0UjnZSjajiOrRAc/n90DGGoIlUf/BsYPDSEtBi1xj6b+8aTeEmGvWW+ahw+ X0MYwvwgSsNFZYVO7x4wtBTRhRJUXnDp0KlZWE3jMcYDjy2iCdann+f2+k2Ds1KX1xg1 zNlyK9fDr2vaz19MT1fiqeJRqGieYo+vXA0eDXTHcd77WIDiqXrY+q39EZqzB6ZzOYEj ueaHf0YF76X9L1H422anBNguLFZovynNyn+8UjISqWu50cNqatOKPF+dgK0RA9s69SQC NIoA== X-Gm-Message-State: AOAM530t3CkqhUJoEb7OtbeYO8bD0WT7CYCjA+ZW8oCKrUezn+KH+ShF XGg69C2RIvQNNG3IMBI0j1eIz84p5nuuuQ== X-Received: by 2002:a17:902:9f91:b029:107:5976:f9de with SMTP id g17-20020a1709029f91b02901075976f9demr1163505plq.38.1622756497301; Thu, 03 Jun 2021 14:41:37 -0700 (PDT) Received: from localhost.localdomain (174-21-70-228.tukw.qwest.net. [174.21.70.228]) by smtp.gmail.com with ESMTPSA id p65sm40115pfb.62.2021.06.03.14.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jun 2021 14:41:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 07/29] softfloat: Move scalbn_decomposed to softfloat-parts.c.inc Date: Thu, 3 Jun 2021 14:41:09 -0700 Message-Id: <20210603214131.629841-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210603214131.629841-1-richard.henderson@linaro.org> References: <20210603214131.629841-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Rename to parts$N_scalbn. Reimplement float128_scalbn with FloatParts128. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- fpu/softfloat.c | 103 +++++++++++++------------------------- fpu/softfloat-parts.c.inc | 21 ++++++++ 2 files changed, 55 insertions(+), 69 deletions(-) -- 2.25.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 6f1bbbe6cf..666b5a25d6 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -890,6 +890,12 @@ static int parts128_compare(FloatParts128 *a, FloatParts128 *b, #define parts_compare(A, B, S, Q) \ PARTS_GENERIC_64_128(compare, A)(A, B, S, Q) +static void parts64_scalbn(FloatParts64 *a, int n, float_status *s); +static void parts128_scalbn(FloatParts128 *a, int n, float_status *s); + +#define parts_scalbn(A, N, S) \ + PARTS_GENERIC_64_128(scalbn, A)(A, N, S) + /* * Helper functions for softfloat-parts.c.inc, per-size operations. */ @@ -3529,58 +3535,53 @@ FloatRelation float128_compare_quiet(float128 a, float128 b, float_status *s) return float128_do_compare(a, b, s, true); } -/* Multiply A by 2 raised to the power N. */ -static FloatParts64 scalbn_decomposed(FloatParts64 a, int n, float_status *s) -{ - if (unlikely(is_nan(a.cls))) { - parts_return_nan(&a, s); - } - if (a.cls == float_class_normal) { - /* The largest float type (even though not supported by FloatParts64) - * is float128, which has a 15 bit exponent. Bounding N to 16 bits - * still allows rounding to infinity, without allowing overflow - * within the int32_t that backs FloatParts64.exp. - */ - n = MIN(MAX(n, -0x10000), 0x10000); - a.exp += n; - } - return a; -} +/* + * Scale by 2**N + */ float16 float16_scalbn(float16 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; - float16_unpack_canonical(&pa, a, status); - pr = scalbn_decomposed(pa, n, status); - return float16_round_pack_canonical(&pr, status); + float16_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float16_round_pack_canonical(&p, status); } float32 float32_scalbn(float32 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; - float32_unpack_canonical(&pa, a, status); - pr = scalbn_decomposed(pa, n, status); - return float32_round_pack_canonical(&pr, status); + float32_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float32_round_pack_canonical(&p, status); } float64 float64_scalbn(float64 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; - float64_unpack_canonical(&pa, a, status); - pr = scalbn_decomposed(pa, n, status); - return float64_round_pack_canonical(&pr, status); + float64_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float64_round_pack_canonical(&p, status); } bfloat16 bfloat16_scalbn(bfloat16 a, int n, float_status *status) { - FloatParts64 pa, pr; + FloatParts64 p; - bfloat16_unpack_canonical(&pa, a, status); - pr = scalbn_decomposed(pa, n, status); - return bfloat16_round_pack_canonical(&pr, status); + bfloat16_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return bfloat16_round_pack_canonical(&p, status); +} + +float128 float128_scalbn(float128 a, int n, float_status *status) +{ + FloatParts128 p; + + float128_unpack_canonical(&p, a, status); + parts_scalbn(&p, n, status); + return float128_round_pack_canonical(&p, status); } /* @@ -6638,42 +6639,6 @@ floatx80 floatx80_scalbn(floatx80 a, int n, float_status *status) aSign, aExp, aSig, 0, status); } -float128 float128_scalbn(float128 a, int n, float_status *status) -{ - bool aSign; - int32_t aExp; - uint64_t aSig0, aSig1; - - aSig1 = extractFloat128Frac1( a ); - aSig0 = extractFloat128Frac0( a ); - aExp = extractFloat128Exp( a ); - aSign = extractFloat128Sign( a ); - if ( aExp == 0x7FFF ) { - if ( aSig0 | aSig1 ) { - return propagateFloat128NaN(a, a, status); - } - return a; - } - if (aExp != 0) { - aSig0 |= UINT64_C(0x0001000000000000); - } else if (aSig0 == 0 && aSig1 == 0) { - return a; - } else { - aExp++; - } - - if (n > 0x10000) { - n = 0x10000; - } else if (n < -0x10000) { - n = -0x10000; - } - - aExp += n - 1; - return normalizeRoundAndPackFloat128( aSign, aExp, aSig0, aSig1 - , status); - -} - static void __attribute__((constructor)) softfloat_init(void) { union_float64 ua, ub, uc, ur; diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 3dacb5b4f0..bf935c4fc2 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -1075,3 +1075,24 @@ static FloatRelation partsN(compare)(FloatPartsN *a, FloatPartsN *b, b_sign: return b->sign ? float_relation_greater : float_relation_less; } + +/* + * Multiply A by 2 raised to the power N. + */ +static void partsN(scalbn)(FloatPartsN *a, int n, float_status *s) +{ + switch (a->cls) { + case float_class_snan: + case float_class_qnan: + parts_return_nan(a, s); + break; + case float_class_zero: + case float_class_inf: + break; + case float_class_normal: + a->exp += MIN(MAX(n, -0x10000), 0x10000); + break; + default: + g_assert_not_reached(); + } +}