From patchwork Wed Feb 21 11:05:19 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: 129026 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp497406ljc; Wed, 21 Feb 2018 03:13:31 -0800 (PST) X-Google-Smtp-Source: AH8x22555NYTz9r3vE86XkNhOMCms5C7KGZikMupA7ICp/INYWgg267FPMZgOwWX4r5KFMj+l5qy X-Received: by 2002:a25:65c4:: with SMTP id z187-v6mr1979290ybb.270.1519211611401; Wed, 21 Feb 2018 03:13:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519211611; cv=none; d=google.com; s=arc-20160816; b=JVTfj0X4GPOCws8v0vi+0Ttn4tWfySU0+bsEC6tmOQnwkQW0yDop7bfHGZKA2dNKfe XuEUwUeWXg9yc/vj1co2Wuy9/UmCC9OUPw1gvq3pdxCQIox4O3qjQcvXrajKns7FnnQm QfV4+kgnqIsrQtSWrFV8VY2lscNXNlWlfaGCiMGH+o1yNGa7yNqhpruSZz8L6i7byFHq Qe/uVDzn30d8nfWmj1AjXUnXatpTRIZYwxkK10O8tbR+AIUTNoa4Q4PSXVrwbBsZvn2G hiQgJ86woQrO8K/Ads+0oz3BaWbMbkuw6T4z4cqdEy6kz5EQ0yHJVLnPQ5ujzG3G6czC 3qrg== 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=iQKLE+gYstVMNpyf46wR6ckSx7XPdTfzR3aJa3Ouhi4=; b=fNW2upLNRyPSUMqGUsvLaFcVtWOzagUao1zEQFlQG2MrpGoU0q9dD1a/memSYgBzUY 2hgx2uVGy5XIyfAPZAgv3LxS/070FMe1bGMzLfvMtbhjbv+VNHJ10t0OQbT9G4XFnS5V kCPt+/2AZ6DXZOycHGtLSzZgbANX3KBB8GdIsxW96N512ELnCsqRvxY/IIj78rTAgrZt cikqG3o5d68IefVT1CN7uXco2njErm2KWlLx3tf0GP9u9MWJhFLe2QFA7QCMzZZgElQX y4V9/13khchpgN1W/nnNh+t07lSROqMg5EnDxF8qk2ZrvM4J4jhSmKjo48CEbfLiavuQ TfVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JG4k+i9y; 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 x188si3767704ywf.271.2018.02.21.03.13.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 21 Feb 2018 03:13:31 -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=JG4k+i9y; 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]:60079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoSL4-0001bj-K6 for patch@linaro.org; Wed, 21 Feb 2018 06:13:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoSDe-000420-Ew for qemu-devel@nongnu.org; Wed, 21 Feb 2018 06:05:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoSDd-0006ka-By for qemu-devel@nongnu.org; Wed, 21 Feb 2018 06:05:50 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:34347) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eoSDd-0006k7-4y for qemu-devel@nongnu.org; Wed, 21 Feb 2018 06:05:49 -0500 Received: by mail-wr0-x242.google.com with SMTP id m5so3302538wrg.1 for ; Wed, 21 Feb 2018 03:05:49 -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=iQKLE+gYstVMNpyf46wR6ckSx7XPdTfzR3aJa3Ouhi4=; b=JG4k+i9yVU+7Ib2CquIMcUKomZc0jfH2QcOOcyDVvEWrq155/uNpNPkl957YrkobzD PafIsI4uvqcrCi8FYaB+PqODAKslxBUm3/1s+COnMb8PV1ZXLMkeGkNp3MOXe33l5uig mR7O1vz21QPE4LBm8EIzFhvIQB3YwpgN8eJSM= 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=iQKLE+gYstVMNpyf46wR6ckSx7XPdTfzR3aJa3Ouhi4=; b=Kcq5Yd26dNHjdb266hBGTCnyUmA8RtHI4H7tXXi2A+2eeDw1TwFgXFgLf754qGwFqO lAf2XQ9D5afUeSu3ezyd93yDb03VYh5TxVU/zvr22PYPjY8Tj2M4VrouPnDj1b8EMJpg Cj/hBgrQkuvhHqSXsTBnxZI+a6eJ0OPO95iLLG2JEO26JL1ICYyOB1lR5DLkL2UwOuLC miCGDQTqzXLq6lWRC8odEHgemW1fmph8hvOtUKwXwiW3tFGLDK88d/AOXboByJj8Aiot UJdcEkir2Fxm6r4siVd29cRdHUbao59YSIQMHYxekrgiQ7cUOisd0uW8nFkJQdEhPz5R f1cA== X-Gm-Message-State: APf1xPAlCnz8AcyJnQNVauVp+SFC5qkR54Lss708iIPWGx+1kCQxJu3y 0hhgbU96c4uxkOnnqnOJ1KmOJw== X-Received: by 10.223.147.198 with SMTP id 64mr2735660wrp.250.1519211148041; Wed, 21 Feb 2018 03:05:48 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id s125sm6927285wmf.4.2018.02.21.03.05.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 03:05:40 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id AD8603E0CCF; Wed, 21 Feb 2018 11:05:24 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Wed, 21 Feb 2018 11:05:19 +0000 Message-Id: <20180221110523.859-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180221110523.859-1-alex.bennee@linaro.org> References: <20180221110523.859-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::242 Subject: [Qemu-devel] [PULL 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 -- 2.15.1 diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 4313d3a602..a07b8556b0 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1663,6 +1663,39 @@ 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 (unlikely(is_nan(a.cls))) { + return return_nan(a, 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 @@ -6986,79 +7019,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);