From patchwork Tue Jan 9 12:22:50 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: 123923 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3971737qgn; Tue, 9 Jan 2018 04:39:43 -0800 (PST) X-Google-Smtp-Source: ACJfBouEo9hN4U+JgLyHz6iSlBJ79XISMRXHlesUoSQJnKaGY3iRO1HYuUFOHTy6/umP5gZxRTyN X-Received: by 10.129.106.213 with SMTP id f204mr4415562ywc.198.1515501583289; Tue, 09 Jan 2018 04:39:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515501583; cv=none; d=google.com; s=arc-20160816; b=bRqB5ZxicOrmXnkW+frWWfoGGQBY8pZuDX4eUo+iNStPRGdxgTBmGLaz3M0C7icz5z FKgEeZVwGrz1Ap3Hl5wym1PpQ/sQ7I4MVXohvaLwFAut2yL5Dhz2lgwK1emxxM6Mt3Of kqWeOcGbMhWqnjbnfQdD5qGmJJbOlWsUHWT2xvdyniuS7Bxt1GIQWknc18uBJogX3zsC Leud8hFPoEK7n0vUru8Hklv+e2cXkgkbA/p1mlOTBSWf0FHEY1WKMN1mExvEkrAWt1Gz p9bMd/pLCKxr853/BVx0jvW959/sIeOuZsDvNSqU83CnSw/AzvR5bOU004awrYmX3L+k LJsQ== 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=iqs4IKr51meQKEBEWobMjAnSDOK0/YUs1Bat82nJ60M=; b=t7lKy0uHze3Z9aJLmIBx0WmxNKUdsn62LHC2KKEUTB8P+Orl7K3HvGW4N0500Etddl h4hKYwEliMV2mNAoDdX7ytWmKmvSCGSfCd61bYsG6VvQO4gANCQ8l/h1Vma5sLmmI3A5 j76Lewu6S1ovMIXqyEzHj7E01bdNf01NAMx4BnW7GBfgxtFDMs+wlb8+TVjXUwIZ2ujq 5YiLAns7bUpMkl97exjaTxwSf0B/Ey9YeN4j3owVGN7MwznpisBHkVAoCAEjD9JIlAz8 iZPit3F+XVqihv41vI5Thqm5cUm2whBsyk9UlEDQ2q+M8Bi0UEkjRpSIFikKZpFX/OOq 5v1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Rd6bSRdm; 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 x11si2938554ybj.154.2018.01.09.04.39.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 09 Jan 2018 04:39:43 -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=Rd6bSRdm; 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]:49814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYtBu-0003J6-Oz for patch@linaro.org; Tue, 09 Jan 2018 07:39:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYt15-0002ae-TR for qemu-devel@nongnu.org; Tue, 09 Jan 2018 07:28:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eYt11-00029s-0T for qemu-devel@nongnu.org; Tue, 09 Jan 2018 07:28:31 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33357) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eYt10-00029D-OR for qemu-devel@nongnu.org; Tue, 09 Jan 2018 07:28:26 -0500 Received: by mail-wm0-x241.google.com with SMTP id 123so742650wme.0 for ; Tue, 09 Jan 2018 04:28:26 -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=iqs4IKr51meQKEBEWobMjAnSDOK0/YUs1Bat82nJ60M=; b=Rd6bSRdmay10qJdcjkI/r5RqqVMiFfs0LXhdgFbva0Au7AElSQIflkjhSFbb6OL3SJ LKFD8mKA/okpQUk3kLVnoEblUhaRAEzOJblGBpZOugZtdAOLc4yDER6lYVpUfiAnzyK+ Ytub6QdTDlEP8je3Bln+ENUhPpwfCsuD//5RE= 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=iqs4IKr51meQKEBEWobMjAnSDOK0/YUs1Bat82nJ60M=; b=frqtW3QmO0rLFoFaaF7zDsF9rlzBaAn4FffcPhwYhfyeWFG8c7oyg96HsJwuKndIGk LpJgMhxqjPMkBZvG+4W5cOJ+KmvJunzCQLBamdNH+OqFobZru6vz8bbcp1LqP9b4R5HC LZJCWz1ELHPRYe2dZaHpq5hdPcic8LfwwVzVEX8s0znlPJMA5z3Xqr//k9j5DdCbToLl FQXQVJUUvqcWokoIymRkcq6bipAV4mWD9DsbMm0UXSkQFNL2mqDpP89gaoKHKyLLai7Q CU5VQp7hXC38YAOaDZ+cw5KsRy+A/yPcEr0RhhhAds/A5m4Ul6DTuSN3q5VackJNRHsl 39vw== X-Gm-Message-State: AKGB3mJ/AIxopkR5cr9FOrYVupflw0qmy/KsIxJf4xWHX3Qbid+CHiC8 oqzWOMkrV3sjnwGHtVG33pxubQ== X-Received: by 10.28.85.193 with SMTP id j184mr12462536wmb.56.1515500905527; Tue, 09 Jan 2018 04:28:25 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x127sm12740919wmb.10.2018.01.09.04.28.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 04:28:24 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 797233E025C; Tue, 9 Jan 2018 12:22:53 +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: Tue, 9 Jan 2018 12:22:50 +0000 Message-Id: <20180109122252.17670-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180109122252.17670-1-alex.bennee@linaro.org> References: <20180109122252.17670-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::241 Subject: [Qemu-devel] [PATCH v2 18/20] 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 --- 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 bb68d77f72..3647f6ca03 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1663,6 +1663,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 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 @@ -6992,79 +7023,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 aa9e30d254..41338184d5 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -326,6 +326,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);