From patchwork Tue Dec 31 13:35:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22835 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 20400218CC for ; Tue, 31 Dec 2013 13:36:21 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id v10sf37332815pde.0 for ; Tue, 31 Dec 2013 05:36:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=Rv9JfkK9W71mOYTBiyG+Jk6n8j8nNlHMpEp9SKt1KQg=; b=bcAc0mQKgbbewEuKOD+4trlk66/U+b93QI58XAjSbp4DuzXTdSIWtAzzsCnPaKpl+G N3zIrTb4gK8xyrT/XJHjIfF61s74kpGyS6dAGh5vH33zdDsGPZ/sPzLEZI42GjOwFYqU V7M8IiCM+0zIA60WPFHur5kPX8TjngQP7TbwIUZXv1N9TkETGam6tyRonBL2n5t20/Az UbposWE42jJjsBiwfpNr7v4EpIzEhhkac+9rA01KDowLiNfB8BUQ6GT0v6+T8bzpVt9K W6KWlsfMk03+VnUlZPqzI3sQhJudAkkSIEHeSqd9AfH+879InJ25imzMlBsDggUxPsjT 3lpQ== X-Gm-Message-State: ALoCoQnj4kmQDXpkqNY28JDnryu0TXhvjJkP8o+9zPPCLLwfml317Qh1DcVox7sNcVDFNzTBHonX X-Received: by 10.66.136.166 with SMTP id qb6mr5645472pab.44.1388496980304; Tue, 31 Dec 2013 05:36:20 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.120.5 with SMTP id ky5ls3864864qeb.26.gmail; Tue, 31 Dec 2013 05:36:20 -0800 (PST) X-Received: by 10.58.237.201 with SMTP id ve9mr177233vec.69.1388496980187; Tue, 31 Dec 2013 05:36:20 -0800 (PST) Received: from mail-ve0-f174.google.com (mail-ve0-f174.google.com [209.85.128.174]) by mx.google.com with ESMTPS id sp7si7376668vdc.138.2013.12.31.05.36.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:20 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.174; Received: by mail-ve0-f174.google.com with SMTP id pa12so6393298veb.19 for ; Tue, 31 Dec 2013 05:36:20 -0800 (PST) X-Received: by 10.52.249.105 with SMTP id yt9mr164034vdc.67.1388496980097; Tue, 31 Dec 2013 05:36:20 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.59.13.131 with SMTP id ey3csp664818ved; Tue, 31 Dec 2013 05:36:19 -0800 (PST) X-Received: by 10.204.118.131 with SMTP id v3mr10636957bkq.30.1388496977973; Tue, 31 Dec 2013 05:36:17 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id re6si11098806bkb.75.2013.12.31.05.36.16 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 31 Dec 2013 05:36:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1VxzUE-0000w5-JG; Tue, 31 Dec 2013 13:35:58 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexander Graf , Michael Matz , Claudio Fontana , Dirk Mueller , Laurent Desnogues , kvmarm@lists.cs.columbia.edu, Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Christoffer Dall , Will Newton , Peter Crosthwaite , Tom Musta , Aurelien Jarno Subject: [PATCH 07/22] softfloat: Add float32_to_uint64() Date: Tue, 31 Dec 2013 13:35:43 +0000 Message-Id: <1388496958-3542-8-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1388496958-3542-1-git-send-email-peter.maydell@linaro.org> References: <1388496958-3542-1-git-send-email-peter.maydell@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Tom Musta This patch adds the float32_to_uint64() routine, which converts a 32-bit floating point number to an unsigned 64 bit number. This contribution can be licensed under either the softfloat-2a or -2b license. V2: Reduced patch to just this single routine per feedback from Peter Maydell. V4: Now passing sign to roundAndPackUint64() Signed-off-by: Tom Musta Message-id: 1387397961-4894-3-git-send-email-tommusta@gmail.com PMM notes: * signed NaNs again * not convinced about handling of negative-but-round-to-zero inputs --- fpu/softfloat.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/fpu/softfloat.h | 1 + 2 files changed, 46 insertions(+) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 1af6ca5..af37164 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -1558,6 +1558,51 @@ int64 float32_to_int64( float32 a STATUS_PARAM ) /*---------------------------------------------------------------------------- | Returns the result of converting the single-precision floating-point value +| `a' to the 64-bit unsigned integer format. The conversion is +| performed according to the IEC/IEEE Standard for Binary Floating-Point +| Arithmetic---which means in particular that the conversion is rounded +| according to the current rounding mode. If `a' is a NaN, the largest +| unsigned integer is returned. Otherwise, if the conversion overflows, the +| largest unsigned integer is returned. If the 'a' is negative, zero is +| returned. +*----------------------------------------------------------------------------*/ + +uint64 float32_to_uint64(float32 a STATUS_PARAM) +{ + flag aSign; + int_fast16_t aExp, shiftCount; + uint32_t aSig; + uint64_t aSig64, aSigExtra; + a = float32_squash_input_denormal(a STATUS_VAR); + + aSig = extractFloat32Frac(a); + aExp = extractFloat32Exp(a); + aSign = extractFloat32Sign(a); + if (aSign) { + if (aExp) { + float_raise(float_flag_invalid STATUS_VAR); + } else if (aSig) { /* negative denormalized */ + float_raise(float_flag_inexact STATUS_VAR); + } + return 0; + } + shiftCount = 0xBE - aExp; + if (aExp) { + aSig |= 0x00800000; + } + if (shiftCount < 0) { + float_raise(float_flag_invalid STATUS_VAR); + return (int64_t)LIT64(0xFFFFFFFFFFFFFFFF); + } + + aSig64 = aSig; + aSig64 <<= 40; + shift64ExtraRightJamming(aSig64, 0, shiftCount, &aSig64, &aSigExtra); + return roundAndPackUint64(aSign, aSig64, aSigExtra STATUS_VAR); +} + +/*---------------------------------------------------------------------------- +| Returns the result of converting the single-precision floating-point value | `a' to the 64-bit two's complement integer format. The conversion is | performed according to the IEC/IEEE Standard for Binary Floating-Point | Arithmetic, except that the conversion is always rounded toward zero. If diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 3790b10..c49e836 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -291,6 +291,7 @@ int32 float32_to_int32_round_to_zero( float32 STATUS_PARAM ); uint32 float32_to_uint32( float32 STATUS_PARAM ); uint32 float32_to_uint32_round_to_zero( float32 STATUS_PARAM ); int64 float32_to_int64( float32 STATUS_PARAM ); +uint64 float32_to_uint64(float32 STATUS_PARAM); int64 float32_to_int64_round_to_zero( float32 STATUS_PARAM ); float64 float32_to_float64( float32 STATUS_PARAM ); floatx80 float32_to_floatx80( float32 STATUS_PARAM );