qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Richard Henderson" <rth@twiddle.net>,
	patches@linaro.org, "Max Filippov" <jcmvbkbc@gmail.com>,
	"Richard Sandiford" <rdsandiford@googlemail.com>,
	"Paul Brook" <paul@codesourcery.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"Blue Swirl" <blauwirbel@gmail.com>,
	"Christophe Lyon" <christophe.lyon@st.com>,
	"Anthony Liguori" <aliguori@amazon.com>,
	"Stefan Weil" <sw@weilnetz.de>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Guan Xuetao" <gxt@mprc.pku.edu.cn>,
	"Andreas Färber" <afaerber@suse.de>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Avi Kivity" <avi.kivity@gmail.com>
Subject: [Qemu-devel] [PATCH 4/6] softfloat: Implement uint64_to_float64() and uint64_to_float32()
Date: Tue, 25 Nov 2014 14:17:35 +0000	[thread overview]
Message-ID: <1416925057-692-5-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1416925057-692-1-git-send-email-peter.maydell@linaro.org>

Reimplement from scratch the uint64_to_float64() and uint64_to_float32()
conversion functions.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 fpu/softfloat.c         | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/fpu/softfloat.h |  2 ++
 2 files changed, 49 insertions(+)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index f79669f..3ab75a3 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -1302,6 +1302,35 @@ float32 int64_to_float32(int64_t a STATUS_PARAM)
 
 }
 
+float32 uint64_to_float32(uint64_t a STATUS_PARAM)
+{
+    int shiftcount;
+
+    if (a == 0) {
+        return float32_zero;
+    }
+
+    /* Determine (left) shift needed to put first set bit into bit posn 23
+     * (since packFloat32() expects the binary point between bits 23 and 22);
+     * this is the fast case for smallish numbers.
+     */
+    shiftcount = countLeadingZeros64(a) - 40;
+    if (shiftcount >= 0) {
+        return packFloat32(0, 0x95 - shiftcount, a << shiftcount);
+    }
+    /* Otherwise we need to do a round-and-pack. roundAndPackFloat32()
+     * expects the binary point between bits 30 and 29, hence the + 7.
+     */
+    shiftcount += 7;
+    if (shiftcount < 0) {
+        shift64RightJamming(a, -shiftcount, &a);
+    } else {
+        a <<= shiftcount;
+    }
+
+    return roundAndPackFloat32(0, 0x9c - shiftcount, a STATUS_VAR);
+}
+
 /*----------------------------------------------------------------------------
 | Returns the result of converting the 64-bit two's complement integer `a'
 | to the double-precision floating-point format.  The conversion is performed
@@ -1321,6 +1350,24 @@ float64 int64_to_float64(int64_t a STATUS_PARAM)
 
 }
 
+float64 uint64_to_float64(uint64_t a STATUS_PARAM)
+{
+    int exp = 0x43C;
+    int shiftcount;
+
+    if (a == 0) {
+        return float64_zero;
+    }
+
+    shiftcount = countLeadingZeros64(a) - 1;
+    if (shiftcount < 0) {
+        shift64RightJamming(a, -shiftcount, &a);
+    } else {
+        a <<= shiftcount;
+    }
+    return roundAndPackFloat64(0, exp - shiftcount, a STATUS_VAR);
+}
+
 /*----------------------------------------------------------------------------
 | Returns the result of converting the 64-bit two's complement integer `a'
 | to the extended double-precision floating-point format.  The conversion
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
index 772f9a1..50c2fec 100644
--- a/include/fpu/softfloat.h
+++ b/include/fpu/softfloat.h
@@ -274,6 +274,8 @@ floatx80 int32_to_floatx80(int32_t STATUS_PARAM);
 float128 int32_to_float128(int32_t STATUS_PARAM);
 float32 int64_to_float32(int64_t STATUS_PARAM);
 float64 int64_to_float64(int64_t STATUS_PARAM);
+float32 uint64_to_float32(uint64_t STATUS_PARAM);
+float64 uint64_to_float64(uint64_t STATUS_PARAM);
 floatx80 int64_to_floatx80(int64_t STATUS_PARAM);
 float128 int64_to_float128(int64_t STATUS_PARAM);
 float128 uint64_to_float128(uint64_t STATUS_PARAM);
-- 
1.9.1

  parent reply	other threads:[~2014-11-25 14:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-25 14:17 [Qemu-devel] [PATCH 0/6] relicense QEMU softfloat from 2b to to 2a Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 1/6] softfloat: Apply patch corresponding to rebasing to softfloat-2a Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 2/6] softfloat: Revert remaining portions of commits 75d62a5856 and 3430b0be36f Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 3/6] softfloat: Revert remaining parts of commits b645bb4885 and 5a6932d51d Peter Maydell
2014-11-25 14:17 ` Peter Maydell [this message]
2014-11-25 14:17 ` [Qemu-devel] [PATCH 5/6] softfloat: reimplement SNAN_BIT_IS_ONE support Peter Maydell
2014-12-11 16:41   ` Maciej W. Rozycki
2014-12-11 18:02     ` Peter Maydell
2014-11-25 14:17 ` [Qemu-devel] [PATCH 6/6] softfloat: Clarify license status Peter Maydell
2014-12-05 11:15 ` [Qemu-devel] [PATCH 0/6] relicense QEMU softfloat from 2b to to 2a Peter Maydell
2014-12-17 14:06   ` Peter Maydell
2015-01-05 11:03     ` Peter Maydell
2015-01-07  6:13 ` Paolo Bonzini
2015-01-07 10:34   ` Peter Maydell
2015-01-07 11:04     ` Paolo Bonzini
2015-01-07 16:23       ` Peter Maydell
2015-01-07 16:29         ` Paolo Bonzini
2015-01-07 16:34           ` Peter Maydell
2015-01-07 16:49             ` Paolo Bonzini
2015-01-12 12:53     ` Peter Maydell
2015-01-12 12:55       ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1416925057-692-5-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=aurelien@aurel32.net \
    --cc=avi.kivity@gmail.com \
    --cc=blauwirbel@gmail.com \
    --cc=christophe.lyon@st.com \
    --cc=gxt@mprc.pku.edu.cn \
    --cc=jcmvbkbc@gmail.com \
    --cc=patches@linaro.org \
    --cc=paul@codesourcery.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rdsandiford@googlemail.com \
    --cc=rth@twiddle.net \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).