From nobody Tue Feb 10 21:40:20 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; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517936251454806.1246636613764; Tue, 6 Feb 2018 08:57:31 -0800 (PST) Received: from localhost ([::1]:37836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej6Yk-0000N2-K2 for importer@patchew.org; Tue, 06 Feb 2018 11:57:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej6Wb-0007BH-EC for qemu-devel@nongnu.org; Tue, 06 Feb 2018 11:55:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej6WZ-0001bL-Sk for qemu-devel@nongnu.org; Tue, 06 Feb 2018 11:55:17 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:43982) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ej6WZ-0001aB-8U for qemu-devel@nongnu.org; Tue, 06 Feb 2018 11:55:15 -0500 Received: by mail-wr0-x242.google.com with SMTP id b52so2663349wrd.10 for ; Tue, 06 Feb 2018 08:55:15 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m191sm8896068wma.42.2018.02.06.08.55.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Feb 2018 08:55:11 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id BAE413E09C4; Tue, 6 Feb 2018 16:48:16 +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=dIOCFTqn7NVlbHqtKqtMbIfU0aME3Jg60nM4GNu5gRg=; b=KdmWjpAn2BmcdfMJZ9k6PhRlgQU7ZsL90AExR0277Qj/ojPG9MTCUQVaNOuIFCxw41 CPF/ZFnDO7wfIj+p5Ck6PwBIEZFJoyGEtW9EVyzHQ/wYUPiA2fljd8U3pvsuDcfEy8CK VhsfkcaUNau5SRaoLFp2bQ8PiBLPP8tRpUkso= 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=dIOCFTqn7NVlbHqtKqtMbIfU0aME3Jg60nM4GNu5gRg=; b=l1GhfdwirYDryYGetLbqc+SuN8dBsfT41vQSHR1yFRTKiVIVo6XvEchUMCFGMjR7Tv aOpXOp2QfSiMFJ6Rh3eVxLOGpX5KRGsG/iOOU8L7Eh6a4iDnXBVkG++fjvcvXm+mo547 d7yfQ69nfpIPAT+Y3JCIKTdaIrR8F8B4ZNsVR7CmGS5haRXJN4emEtAl0jjWWiRbgDuo qa7C44EPjEeBsYHbYCrG/R9ASf/9fGU1FQd+MfJwDSb+GCsPVH6n5qI5gR6+MlfZF1sl Nh3tH5RLNy63rz3/KrMOqxn6Qdwzcjr5FU7BO0uY3HsOyvGCOemUqRLyILVc0tksHaOy +lFg== X-Gm-Message-State: APf1xPCgZLDFTnGVGa2gBCcKfvEU2ctYKuKmeRe6RCPhLUrTEhxCP7Wb XM95fnCBDU11htaN5h9ruTkaTw== X-Google-Smtp-Source: AH8x226whTWSXOnDgsnmDJe+ElD3vo/sj19qaIlcusfkAED5DhnIOaZ0NKea0AWnWoa6ZpYNV4a49g== X-Received: by 10.223.184.213 with SMTP id c21mr2936984wrg.57.1517936114073; Tue, 06 Feb 2018 08:55:14 -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 Date: Tue, 6 Feb 2018 16:48:12 +0000 Message-Id: <20180206164815.10084-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180206164815.10084-1-alex.bennee@linaro.org> References: <20180206164815.10084-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:c0c::242 Subject: [Qemu-devel] [PATCH v4 19/22] 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 --- v3 - fix renames v4 - handle NaNs with return_nan - use unlikely(is_nan) --- fpu/softfloat.c | 106 +++++++++++++++-----------------------------= ---- include/fpu/softfloat.h | 1 + 2 files changed, 34 insertions(+), 73 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 9f9f101d35..558d37ecf9 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1664,6 +1664,39 @@ float64 uint16_to_float64(uint16_t a, float_status *= status) return uint64_to_float64(a, status); } =20 +/* Multiply A by 2 raised to the power N. */ +static FloatParts scalbn_decomposed(FloatParts a, int n, float_status *s) +{ + if (unlikely(is_nan(a.cls))) { + return return_nan(a, 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) +{ + FloatParts pa =3D float16_unpack_canonical(a, status); + FloatParts pr =3D scalbn_decomposed(pa, n, status); + return float16_round_pack_canonical(pr, status); +} + +float32 float32_scalbn(float32 a, int n, float_status *status) +{ + FloatParts pa =3D float32_unpack_canonical(a, status); + FloatParts pr =3D scalbn_decomposed(pa, n, status); + return float32_round_pack_canonical(pr, status); +} + +float64 float64_scalbn(float64 a, int n, float_status *status) +{ + FloatParts pa =3D float64_unpack_canonical(a, status); + FloatParts 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 @@ -6987,79 +7020,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 3e6fdd756a..52621e0b79 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -244,6 +244,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