All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Mayer" <l_indien@magic.fr>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] softfloat missing functions
Date: Mon, 19 Mar 2007 08:58:26 +0100	[thread overview]
Message-ID: <1174291106.24702.9.camel@rapid> (raw)

[-- Attachment #1: Type: text/plain, Size: 905 bytes --]

Some functions are missing from the softfloat API. Those are:
float32 uint32_to_float32( unsigned int STATUS_PARAM);
float64 uint64_to_float64( uint64_t v STATUS_PARAM);
unsigned int float32_to_uint32( float32 a STATUS_PARAM);
unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM);
unsigned int float64_to_uint32( float64 STATUS_PARAM );
unsigned int float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
uint64_t float64_to_uint64( float64 STATUS_PARAM );
uint64_t float64_to_uint64_round_to_zero( float64 STATUS_PARAM );

As I need those function to emulate some PowerPC operations, here's a
proposal for their implementation.
Note that float64_to_uint64 functions are not correct, as they won't
return results between INT64_MAX and UINT64_MAX. Hope someone may know
the proper solution for this.
Please comment and help me fix this.

-- 
J. Mayer <l_indien@magic.fr>
Never organized

[-- Attachment #2: qemu_softfloat.diff --]
[-- Type: text/x-patch, Size: 7949 bytes --]

Index: fpu/softfloat-native.c
===================================================================
RCS file: /sources/qemu/qemu/fpu/softfloat-native.c,v
retrieving revision 1.6
diff -u -d -d -p -r1.6 softfloat-native.c
--- fpu/softfloat-native.c	28 Oct 2006 19:27:11 -0000	1.6
+++ fpu/softfloat-native.c	19 Mar 2007 07:30:45 -0000
@@ -59,6 +59,11 @@ float32 int32_to_float32(int v STATUS_PA
     return (float32)v;
 }
 
+float32 uint32_to_float32(unsigned int v STATUS_PARAM)
+{
+    return (float32)v;
+}
+
 float64 int32_to_float64(int v STATUS_PARAM)
 {
     return (float64)v;
@@ -78,6 +83,10 @@ float64 int64_to_float64( int64_t v STAT
 {
     return (float64)v;
 }
+float64 uint64_to_float64( uint64_t v STATUS_PARAM)
+{
+    return (float64)v;
+}
 #ifdef FLOATX80
 floatx80 int64_to_floatx80( int64_t v STATUS_PARAM)
 {
@@ -132,6 +141,37 @@ floatx80 float32_to_floatx80( float32 a 
 }
 #endif
 
+unsigned int float32_to_uint32( float32 a STATUS_PARAM)
+{
+    int64_t v;
+    unsigned int res;
+
+    v = llrintf(a);
+    if (v < 0) {
+        res = 0;
+    } else if (v > 0xffffffff) {
+        res = 0xffffffff;
+    } else {
+        res = v;
+    }
+    return res;
+}
+unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM)
+{
+    int64_t v;
+    unsigned int res;
+
+    v = (int64_t)a;
+    if (v < 0) {
+        res = 0;
+    } else if (v > 0xffffffff) {
+        res = 0xffffffff;
+    } else {
+        res = v;
+    }
+    return res;
+}
+
 /*----------------------------------------------------------------------------
 | Software IEC/IEEE single-precision operations.
 *----------------------------------------------------------------------------*/
@@ -218,6 +258,63 @@ float128 float64_to_float128( float64 a 
 }
 #endif
 
+unsigned int float64_to_uint32( float64 a STATUS_PARAM)
+{
+    int64_t v;
+    unsigned int res;
+
+    v = llrint(a);
+    if (v < 0) {
+        res = 0;
+    } else if (v > 0xffffffff) {
+        res = 0xffffffff;
+    } else {
+        res = v;
+    }
+    return res;
+}
+unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM)
+{
+    int64_t v;
+    unsigned int res;
+
+    v = (int64_t)a;
+    if (v < 0) {
+        res = 0;
+    } else if (v > 0xffffffff) {
+        res = 0xffffffff;
+    } else {
+        res = v;
+    }
+    return res;
+}
+uint64_t float64_to_uint64 (float64 a STATUS_PARAM)
+{
+    uint64_t res;
+    int64_t v;
+
+    v = llrint(a);
+    if (v < 0) {
+        res = 0;
+    } else {
+        res = v;
+    }
+    return res;
+}
+uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM)
+{
+    uint64_t res;
+    int64_t v;
+
+    v = (int64_t)a;
+    if (v < 0) {
+        res = 0;
+    } else {
+        res = v;
+    }
+    return res;
+}
+
 /*----------------------------------------------------------------------------
 | Software IEC/IEEE double-precision operations.
 *----------------------------------------------------------------------------*/
Index: fpu/softfloat-native.h
===================================================================
RCS file: /sources/qemu/qemu/fpu/softfloat-native.h,v
retrieving revision 1.8
diff -u -d -d -p -r1.8 softfloat-native.h
--- fpu/softfloat-native.h	28 Oct 2006 19:27:11 -0000	1.8
+++ fpu/softfloat-native.h	19 Mar 2007 07:30:45 -0000
@@ -99,6 +99,7 @@ void set_floatx80_rounding_precision(int
 | Software IEC/IEEE integer-to-floating-point conversion routines.
 *----------------------------------------------------------------------------*/
 float32 int32_to_float32( int STATUS_PARAM);
+float32 uint32_to_float32( unsigned int STATUS_PARAM);
 float64 int32_to_float64( int STATUS_PARAM);
 #ifdef FLOATX80
 floatx80 int32_to_floatx80( int STATUS_PARAM);
@@ -108,6 +109,7 @@ float128 int32_to_float128( int STATUS_P
 #endif
 float32 int64_to_float32( int64_t STATUS_PARAM);
 float64 int64_to_float64( int64_t STATUS_PARAM);
+float64 uint64_to_float64( uint64_t v STATUS_PARAM);
 #ifdef FLOATX80
 floatx80 int64_to_floatx80( int64_t STATUS_PARAM);
 #endif
@@ -120,6 +122,8 @@ float128 int64_to_float128( int64_t STAT
 *----------------------------------------------------------------------------*/
 int float32_to_int32( float32  STATUS_PARAM);
 int float32_to_int32_round_to_zero( float32  STATUS_PARAM);
+unsigned int float32_to_uint32( float32 a STATUS_PARAM);
+unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM);
 int64_t float32_to_int64( float32  STATUS_PARAM);
 int64_t float32_to_int64_round_to_zero( float32  STATUS_PARAM);
 float64 float32_to_float64( float32  STATUS_PARAM);
@@ -200,8 +204,12 @@ INLINE float32 float32_chs(float32 a)
 *----------------------------------------------------------------------------*/
 int float64_to_int32( float64 STATUS_PARAM );
 int float64_to_int32_round_to_zero( float64 STATUS_PARAM );
+unsigned int float64_to_uint32( float64 STATUS_PARAM );
+unsigned int float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
 int64_t float64_to_int64( float64 STATUS_PARAM );
 int64_t float64_to_int64_round_to_zero( float64 STATUS_PARAM );
+uint64_t float64_to_uint64( float64 STATUS_PARAM );
+uint64_t float64_to_uint64_round_to_zero( float64 STATUS_PARAM );
 float32 float64_to_float32( float64 STATUS_PARAM );
 #ifdef FLOATX80
 floatx80 float64_to_floatx80( float64 STATUS_PARAM );
Index: fpu/softfloat.c
===================================================================
RCS file: /sources/qemu/qemu/fpu/softfloat.c,v
retrieving revision 1.4
diff -u -d -d -p -r1.4 softfloat.c
--- fpu/softfloat.c	28 Oct 2006 19:27:11 -0000	1.4
+++ fpu/softfloat.c	19 Mar 2007 07:30:46 -0000
@@ -1183,6 +1183,13 @@ float64 int64_to_float64( int64 a STATUS
 
 }
 
+float64 uint64_to_float64( uint64 a STATUS_PARAM )
+{
+    if ( a == 0 ) return 0;
+    return normalizeRoundAndPackFloat64( 0, 0x43C, a STATUS_VAR );
+
+}
+
 #ifdef FLOATX80
 
 /*----------------------------------------------------------------------------
@@ -5282,6 +5289,36 @@ unsigned int float64_to_uint32_round_to_
     return res;
 }
 
+uint64_t float64_to_uint64 (float64 a STATUS_PARAM)
+{
+    uint64_t res;
+    int64_t v;
+
+    v = float64_to_int64(a STATUS_VAR);
+    if (v < 0) {
+        res = 0;
+        float_raise( float_flag_invalid STATUS_VAR);
+    } else {
+        res = v;
+    }
+    return res;
+}
+
+uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM)
+{
+    uint64_t res;
+    int64_t v;
+
+    v = float64_to_int64_round_to_zero(a STATUS_VAR);
+    if (v < 0) {
+        res = 0;
+        float_raise( float_flag_invalid STATUS_VAR);
+    } else {
+        res = v;
+    }
+    return res;
+}
+
 #define COMPARE(s, nan_exp)                                                  \
 INLINE int float ## s ## _compare_internal( float ## s a, float ## s b,      \
                                       int is_quiet STATUS_PARAM )            \
Index: fpu/softfloat.h
===================================================================
RCS file: /sources/qemu/qemu/fpu/softfloat.h,v
retrieving revision 1.5
diff -u -d -d -p -r1.5 softfloat.h
--- fpu/softfloat.h	28 Oct 2006 19:27:11 -0000	1.5
+++ fpu/softfloat.h	19 Mar 2007 07:30:46 -0000
@@ -194,6 +194,7 @@ float128 int32_to_float128( int STATUS_P
 #endif
 float32 int64_to_float32( int64_t STATUS_PARAM );
 float64 int64_to_float64( int64_t STATUS_PARAM );
+float64 uint64_to_float64( uint64_t STATUS_PARAM );
 #ifdef FLOATX80
 floatx80 int64_to_floatx80( int64_t STATUS_PARAM );
 #endif
@@ -258,6 +259,8 @@ unsigned int float64_to_uint32( float64 
 unsigned int float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
 int64_t float64_to_int64( float64 STATUS_PARAM );
 int64_t float64_to_int64_round_to_zero( float64 STATUS_PARAM );
+uint64_t float64_to_uint64 (float64 a STATUS_PARAM);
+uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM);
 float32 float64_to_float32( float64 STATUS_PARAM );
 #ifdef FLOATX80
 floatx80 float64_to_floatx80( float64 STATUS_PARAM );

             reply	other threads:[~2007-03-19  8:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-19  7:58 J. Mayer [this message]
2007-03-19 20:37 ` [Qemu-devel] [PATCH] softfloat missing functions Julian Seward
2007-03-19 21:10   ` J. Mayer
2007-03-19 22:53     ` Julian Seward
2007-03-19 23:13       ` J. Mayer

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=1174291106.24702.9.camel@rapid \
    --to=l_indien@magic.fr \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.