From nobody Tue Feb 10 22:18:05 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512997684433804.6814854875854; Mon, 11 Dec 2017 05:08:04 -0800 (PST) Received: from localhost ([::1]:52668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eONoQ-0006Bn-PX for importer@patchew.org; Mon, 11 Dec 2017 08:08:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51644) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eONe8-0002So-3i for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eONe7-0007nb-1y for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:24 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:46918) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eONe6-0007mV-Oj for qemu-devel@nongnu.org; Mon, 11 Dec 2017 07:57:22 -0500 Received: by mail-wm0-x243.google.com with SMTP id r78so14298667wme.5 for ; Mon, 11 Dec 2017 04:57:22 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s195sm9557491wmb.33.2017.12.11.04.57.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 04:57:18 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A59283E0F56; Mon, 11 Dec 2017 12:57:06 +0000 (GMT) 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=lZsn0E0fKsWEEcIFtvDvOYzz27C6Ibj9Yt+0VPbKhro=; b=J9EhZU0Ew7zU3S1t5G8kTBJx/NUWJX1S6MIBNq2yYDnUeHSkMJWww8TytlA01sqgoZ qdi7zeoju2VrWeZslYfbt6/Bg9Ammc7D8+Z3zCoTPfuQHW0dxgVJ8lhQ/yY25XlNEnpD 0AMKtNWmbSSBuaPpUpsxS6fED4FcFznuFhHzw= 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=lZsn0E0fKsWEEcIFtvDvOYzz27C6Ibj9Yt+0VPbKhro=; b=DbcvzNb+3kKhN2ae+Pe2iKpIlYvkIQgWB/TEDEJGtQI7J2mpRg6mk/YcE2/U+4l10Z kIpzN+390hP6hiLw6Fzfi++ETafR4WjsfukQ/qpEl6CkWl/P7qtPrCI7q/D83I0v3D5M gOdu1cX+6+NjzXhVyFIae9/B7mXRNO5OwyZz97sa0WjzidyO7ELKJ80com5o6sW5ffP5 0FwTO7MKPYGZaKlmOeJEIUXMPBxwLOJpTt2Ppg4xf5FMGz0+9910y9etiQnJ3bclL1H/ 0wuJ2F/1IOEmGCrl7voSXxhGoZtDY9mC+X3MzLGztHRVTqVaZ8P5EyMLnBvqCKfcz7Zu BtSw== X-Gm-Message-State: AKGB3mIEUWWS5KYApUA6GB/HIEs8yuEqJhvPGt6fO8f4nXKxKT6rWqCS QNcPgRa9SZjSLDiZXPnXmEHdomGOHrk= X-Google-Smtp-Source: ACJfBottokfBepRTCk5cP08xYW69+H6lMHjscFmBZRl/5Nz91Yq2h5hYqs4+taKJRlH3B0+ETxugLA== X-Received: by 10.28.130.15 with SMTP id e15mr833504wmd.52.1512997041548; Mon, 11 Dec 2017 04:57:21 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: richard.henderson@linaro.org, peter.maydell@linaro.org, laurent@vivier.eu, bharata@linux.vnet.ibm.com, andrew@andrewdutcher.com, aleksandar.markovic@imgtec.com Date: Mon, 11 Dec 2017 12:57:03 +0000 Message-Id: <20171211125705.16120-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171211125705.16120-1-alex.bennee@linaro.org> References: <20171211125705.16120-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH v1 17/19] fpu/softfloat: re-factor scalbn 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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 This is one of the simpler manipulations you could make to a floating point number. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- fpu/softfloat.c | 104 +++++++++++++++-----------------------------= ---- include/fpu/softfloat.h | 1 + 2 files changed, 32 insertions(+), 73 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 1a7f1cab10..b7ea56dfa5 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1662,6 +1662,37 @@ float64 uint16_to_float64(uint16_t a, float_status *= status) return uint64_to_float64((uint64_t) a, status); } =20 +/* Multiply A by 2 raised to the power N. */ +static decomposed_parts scalbn_decomposed(decomposed_parts a, int n, + float_status *s) +{ + if (a.cls =3D=3D float_class_normal) { + a.exp +=3D n; + } + return a; +} + +float16 float16_scalbn(float16 a, int n, float_status *status) +{ + decomposed_parts pa =3D float16_unpack_canonical(a, status); + decomposed_parts pr =3D scalbn_decomposed(pa, n, status); + return float16_round_pack_canonical(pr, status); +} + +float32 float32_scalbn(float32 a, int n, float_status *status) +{ + decomposed_parts pa =3D float32_unpack_canonical(a, status); + decomposed_parts pr =3D scalbn_decomposed(pa, n, status); + return float32_round_pack_canonical(pr, status); +} + +float64 float64_scalbn(float64 a, int n, float_status *status) +{ + decomposed_parts pa =3D float64_unpack_canonical(a, status); + decomposed_parts pr =3D scalbn_decomposed(pa, n, status); + return float64_round_pack_canonical(pr, status); +} + /*------------------------------------------------------------------------= ---- | Takes a 64-bit fixed-point value `absZ' with binary point between bits 6 | and 7, and returns the properly rounded 32-bit integer corresponding to = the @@ -6991,79 +7022,6 @@ MINMAX(32) MINMAX(64) =20 =20 -/* Multiply A by 2 raised to the power N. */ -float32 float32_scalbn(float32 a, int n, float_status *status) -{ - flag aSign; - int16_t aExp; - uint32_t aSig; - - a =3D float32_squash_input_denormal(a, status); - aSig =3D extractFloat32Frac( a ); - aExp =3D extractFloat32Exp( a ); - aSign =3D extractFloat32Sign( a ); - - if ( aExp =3D=3D 0xFF ) { - if ( aSig ) { - return propagateFloat32NaN(a, a, status); - } - return a; - } - if (aExp !=3D 0) { - aSig |=3D 0x00800000; - } else if (aSig =3D=3D 0) { - return a; - } else { - aExp++; - } - - if (n > 0x200) { - n =3D 0x200; - } else if (n < -0x200) { - n =3D -0x200; - } - - aExp +=3D n - 1; - aSig <<=3D 7; - return normalizeRoundAndPackFloat32(aSign, aExp, aSig, status); -} - -float64 float64_scalbn(float64 a, int n, float_status *status) -{ - flag aSign; - int16_t aExp; - uint64_t aSig; - - a =3D float64_squash_input_denormal(a, status); - aSig =3D extractFloat64Frac( a ); - aExp =3D extractFloat64Exp( a ); - aSign =3D extractFloat64Sign( a ); - - if ( aExp =3D=3D 0x7FF ) { - if ( aSig ) { - return propagateFloat64NaN(a, a, status); - } - return a; - } - if (aExp !=3D 0) { - aSig |=3D LIT64( 0x0010000000000000 ); - } else if (aSig =3D=3D 0) { - return a; - } else { - aExp++; - } - - if (n > 0x1000) { - n =3D 0x1000; - } else if (n < -0x1000) { - n =3D -0x1000; - } - - aExp +=3D n - 1; - aSig <<=3D 10; - return normalizeRoundAndPackFloat64(aSign, aExp, aSig, status); -} - floatx80 floatx80_scalbn(floatx80 a, int n, float_status *status) { flag aSign; diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 8ebde83251..c1224aab8c 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -353,6 +353,7 @@ float16 float16_sub(float16, float16, float_status *sta= tus); float16 float16_mul(float16, float16, float_status *status); float16 float16_muladd(float16, float16, float16, int, float_status *statu= s); float16 float16_div(float16, float16, float_status *status); +float16 float16_scalbn(float16, int, float_status *status); =20 int float16_is_quiet_nan(float16, float_status *status); int float16_is_signaling_nan(float16, float_status *status); --=20 2.15.1