From patchwork Mon Dec 11 12:57:03 2017 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: 121406 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2769074qgn; Mon, 11 Dec 2017 05:08:48 -0800 (PST) X-Google-Smtp-Source: ACJfBotaOBSiSm7tNlCkjR779Yfubelz+M774SkPfXnKr3VZLG17spJnpALy8z+hTmPoAjAvOJGw X-Received: by 10.37.160.200 with SMTP id i8mr220721ybm.118.1512997728722; Mon, 11 Dec 2017 05:08:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512997728; cv=none; d=google.com; s=arc-20160816; b=qOa8gt9woOWa1FwkMP4VkWDLcMHss6morguoPoXAL7P/uwDckYH6wg4vSSjA3F1fBr jplL1dVxhciDy9ZTkI065bz9gUevCeSgAaEbEjIRwZ5IE+qdNwMSB+mbNWMjdx9ni0tR kn2ad361eHxVnKM+0rV89lmyybnQlw19TrEA5NPhUwqVOW1SVZ+ta2QIF0/sTi/cp8sI cOd1Q4/WbjtkxnHOZJspahw1GqTgspg3oiJCuGDuVjkKTbAN675rn9ixuT+aSa63nhDe 0LKHb1Ib0DY9TyJs76hu9HcYCRTvw4ZJfpPOBXFEMuqWots6f2f8yONoP2iyQ8UolkTH 3NpQ== 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=lZsn0E0fKsWEEcIFtvDvOYzz27C6Ibj9Yt+0VPbKhro=; b=XCnAIDjT0C5R0QBzt8VYXFe35vx4bm/jbQSpBuPpj46wMLJjmm6h4UA6pWcEVUnO4d bIbHl91dM8lW1koY3TkAmAYsim11KIcKnmMuwW/JEtflzbFyQLUKn64OuVzB3chEZIPh RRR9yWnXz/qDZWHQLYwGVmOD8NzDTiFOjHpCKjbV6PmSSxIDOC3joyrV4VxRsJ+8Cn+0 fInh4Og6XBxQR/q6DSHEfSrKLNbwwc4UaxyRV7xQDocfXOF1SNI3q21xj3mLOekoAPW0 8/JEUc7/1UyIBSLqM+NhaPRaamJMzHGt6qcd74p1altOwdRxEOvbQnSHUm9DxYpqUGxw T7Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=J9EhZU0E; 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 f10si2996528ywh.121.2017.12.11.05.08.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Dec 2017 05:08:48 -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=J9EhZU0E; 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]:52668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eONpA-0006Bn-4J for patch@linaro.org; Mon, 11 Dec 2017 08:08:48 -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) 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-Received: by 10.28.130.15 with SMTP id e15mr833504wmd.52.1512997041548; Mon, 11 Dec 2017 04:57:21 -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) 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, 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 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_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 --- fpu/softfloat.c | 104 +++++++++++++++--------------------------------- include/fpu/softfloat.h | 1 + 2 files changed, 32 insertions(+), 73 deletions(-) -- 2.15.1 Reviewed-by: Richard Henderson 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); } +/* 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 == float_class_normal) { + a.exp += n; + } + return a; +} + +float16 float16_scalbn(float16 a, int n, float_status *status) +{ + decomposed_parts pa = float16_unpack_canonical(a, status); + decomposed_parts pr = 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 = float32_unpack_canonical(a, status); + decomposed_parts pr = 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 = float64_unpack_canonical(a, status); + decomposed_parts 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 @@ -6991,79 +7022,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 8ebde83251..c1224aab8c 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -353,6 +353,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);