From patchwork Wed Jan 24 13:13:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 125661 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp419544ljf; Wed, 24 Jan 2018 05:35:19 -0800 (PST) X-Google-Smtp-Source: AH8x225Jv+5FJqNk4kd5CpLyynStI2ziMdWThiFff1+Iy+IIww0Ivzti8K1kavO9oEZMCBUPIUoC X-Received: by 10.129.65.81 with SMTP id f17mr5471364ywk.421.1516800919182; Wed, 24 Jan 2018 05:35:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516800919; cv=none; d=google.com; s=arc-20160816; b=pS9bz28WYxO0xZVa2ZVs3svd9a6ieHhcJvCrj4c2r98gt0soWZ7zXOkLsHBjK5luDB issWUreeGojayprVUmPiNk3dVEzmTVnjMZhy5BOcRD4+v+yCFKWrqgOJJR4RIsSztvTk rIEctX2CNHKKJXY06Avg9KDCq7juuT35dWFPxWuD6pax4xid98Y+4KCo+ePrku2lcIYy DuW063IefRHcm8FE2aulvidujHVFKEbbGpTMmzVHUje6zL4PcRMpIojs3XAzh55ucww1 Thb6SKjzYpAAc0cKtrNBkpX/C7Ogpudyoe90055i3wavhDs08LsYt/Je/YA4Etmsq7Wx wGRQ== 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=9WZ7HOocqRseOwRk7dlVHOxCss/IK8AYSjo0ZX0OF00=; b=yn/1kt0NRuyoiwuyPoX5RGAJUHu3Lix6otQuheTmUSeTkbJ/hdMn7fYv6mLh+5M9pG XvjaSgZ6q22v42FQSPxTfMNL5h3mvFG03Vlt34oimBHJm2anXvwyjr2n6XPAuCFe+YC3 orowfik2UfuV3kdWJSblyAfIjabk4xtG1dod8u3DqBd/Hmnwf0LN7j3XGcsaobL1G6wm 0E+HaX7XAPFopiZY88PbnEgnuaQiyyFWfZxdYbY3CGg+ml4DkuTcWnaib0+UfeKdVpbn BNr7dwFFOqQFc/qOiPuCRsOC/2kuBuij+PAk5kDj+rzLN/hh0q9gKiRAz0WjbHemFtAR EbFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dhTmbr9J; 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 p10si716342ybe.610.2018.01.24.05.35.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 24 Jan 2018 05:35:19 -0800 (PST) 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=dhTmbr9J; 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]:48892 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeLCw-0003Lk-IT for patch@linaro.org; Wed, 24 Jan 2018 08:35:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eeKwy-0007rS-Et for qemu-devel@nongnu.org; Wed, 24 Jan 2018 08:18:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eeKww-000172-Je for qemu-devel@nongnu.org; Wed, 24 Jan 2018 08:18:48 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:36049) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eeKww-00015v-Ay for qemu-devel@nongnu.org; Wed, 24 Jan 2018 08:18:46 -0500 Received: by mail-wr0-x241.google.com with SMTP id d9so4001406wre.3 for ; Wed, 24 Jan 2018 05:18:46 -0800 (PST) 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=9WZ7HOocqRseOwRk7dlVHOxCss/IK8AYSjo0ZX0OF00=; b=dhTmbr9JlzpCPmfH3FfD5fnJ0w3jClTeNtA77nuDRK5gE5E6VK+7/HAxNgzrGbtE47 7VW2crXWhQLLGoQBPtojOPWOwSKxpCnFvV5WeSRgcKFp9gomqXTYfytUFVXFdZf5ktys DZhivUXuE2r1JOL9wXSJ1dXgsfJpvjhkXAVlc= 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=9WZ7HOocqRseOwRk7dlVHOxCss/IK8AYSjo0ZX0OF00=; b=F4W2cqSYplpFqSGut/rdtMErLVoovEOV7qRZc8STRE87Ll6HyCD6H+f9iCbNfrTR9Z sGg87LLhd8uXiX5kymk2wa14su2hOCMS2qhdkDCUmzC96x7n9nuH/ZhzGyuReaqAqr/4 zQz3uTwHQA1++uT8GMFyA09rDxCt1xEyD2+IDWMg7ESOR0pyLndUjYWsrSuhS31EwGIk +x8U32cAFNFdYz7YEYS1D0Q6ZHG9Ksox+9yrTX7CMyZlPTHmBvTHQJPHX4yUGK1bOLEF OUHpDWZP8/8gdQ1gpGmYMPcK5uE/lCf1bcdT9Of5th+eL1w3CzQX5ZR3OWkSrK3FOGc6 QD8A== X-Gm-Message-State: AKwxytera4NGeNhiX5ePQWUk6KggB3NxB3EF5qnsyaecG6WNw9FdjqBH Icc2URi76dYy+BHoeafEqOTsTw== X-Received: by 10.223.177.148 with SMTP id q20mr5813272wra.228.1516799925316; Wed, 24 Jan 2018 05:18:45 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w83sm170644wma.47.2018.01.24.05.18.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 05:18:41 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1F4273E0CEF; Wed, 24 Jan 2018 13:13:17 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: richard.henderson@linaro.org, peter.maydell@linaro.org, laurent@vivier.eu, bharata@linux.vnet.ibm.com, andrew@andrewdutcher.com Date: Wed, 24 Jan 2018 13:13:12 +0000 Message-Id: <20180124131315.30567-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180124131315.30567-1-alex.bennee@linaro.org> References: <20180124131315.30567-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH v3 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_Benn=C3=A9e?= , qemu-devel@nongnu.org, Aurelien Jarno Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is one of the simpler manipulations you could make to a floating point number. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v3 - fix renames --- fpu/softfloat.c | 104 +++++++++++++++--------------------------------- include/fpu/softfloat.h | 1 + 2 files changed, 32 insertions(+), 73 deletions(-) -- 2.15.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 7baeb0e22d..24b7de30ce 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1646,6 +1646,37 @@ float64 uint16_to_float64(uint16_t a, float_status *status) return uint64_to_float64(a, status); } +/* Multiply A by 2 raised to the power N. */ +static FloatParts scalbn_decomposed(FloatParts a, int n, + float_status *s) +{ + if (a.cls == float_class_normal) { + a.exp += n; + } + return a; +} + +float16 float16_scalbn(float16 a, int n, float_status *status) +{ + FloatParts pa = float16_unpack_canonical(a, status); + FloatParts pr = scalbn_decomposed(pa, n, status); + return float16_round_pack_canonical(pr, status); +} + +float32 float32_scalbn(float32 a, int n, float_status *status) +{ + FloatParts pa = float32_unpack_canonical(a, status); + FloatParts pr = scalbn_decomposed(pa, n, status); + return float32_round_pack_canonical(pr, status); +} + +float64 float64_scalbn(float64 a, int n, float_status *status) +{ + FloatParts pa = float64_unpack_canonical(a, status); + FloatParts pr = 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 @@ -6969,79 +7000,6 @@ MINMAX(32) MINMAX(64) -/* 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 = float32_squash_input_denormal(a, status); - aSig = extractFloat32Frac( a ); - aExp = extractFloat32Exp( a ); - aSign = extractFloat32Sign( a ); - - if ( aExp == 0xFF ) { - if ( aSig ) { - return propagateFloat32NaN(a, a, status); - } - return a; - } - if (aExp != 0) { - aSig |= 0x00800000; - } else if (aSig == 0) { - return a; - } else { - aExp++; - } - - if (n > 0x200) { - n = 0x200; - } else if (n < -0x200) { - n = -0x200; - } - - aExp += n - 1; - aSig <<= 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 = float64_squash_input_denormal(a, status); - aSig = extractFloat64Frac( a ); - aExp = extractFloat64Exp( a ); - aSign = extractFloat64Sign( a ); - - if ( aExp == 0x7FF ) { - if ( aSig ) { - return propagateFloat64NaN(a, a, status); - } - return a; - } - if (aExp != 0) { - aSig |= LIT64( 0x0010000000000000 ); - } else if (aSig == 0) { - return a; - } else { - aExp++; - } - - if (n > 0x1000) { - n = 0x1000; - } else if (n < -0x1000) { - n = -0x1000; - } - - aExp += n - 1; - aSig <<= 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 *status); float16 float16_mul(float16, float16, float_status *status); float16 float16_muladd(float16, float16, float16, int, float_status *status); float16 float16_div(float16, float16, float_status *status); +float16 float16_scalbn(float16, int, float_status *status); int float16_is_quiet_nan(float16, float_status *status); int float16_is_signaling_nan(float16, float_status *status);