Skip to contentSkip to conversation

softfloat-native removal and i386 improvements

PATCH Superseded Aurelien Jarno 4 participants 24 messages May 15, 2011 – May 29, 2011 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/11 target-ppc: remove old CONFIG_SOFTFLOAT #ifdef

In reply to Aurelien Jarno

target-ppc has been switched to softfloat only long ago, but a few #ifdef CONFIG_SOFTFLOAT have been forgotten. Remove them.

---
 target-ppc/helper.h    |    2 --
 target-ppc/op_helper.c |   11 -----------
 target-ppc/translate.c |    2 --
 3 files changed, 0 insertions(+), 15 deletions(-)
target-ppc/helper.h +0 -2
index 51c99c8..470e42f 100644
@@ -51,9 +51,7 @@ DEF_HELPER_FLAGS_1(cntlzw32, TCG_CALL_CONST | TCG_CALL_PURE, i32, i32)
 DEF_HELPER_FLAGS_2(brinc, TCG_CALL_CONST | TCG_CALL_PURE, tl, tl, tl)
 
 DEF_HELPER_0(float_check_status, void)
-#ifdef CONFIG_SOFTFLOAT
 DEF_HELPER_0(reset_fpstatus, void)
-#endif
 DEF_HELPER_2(compute_fprf, i32, i64, i32)
 DEF_HELPER_2(store_fpscr, void, i64, i32)
 DEF_HELPER_1(fpscr_clrbit, void, i32)
target-ppc/op_helper.c +0 -11
index 85803f1..2cc9bff 100644
@@ -972,7 +972,6 @@ void helper_store_fpscr (uint64_t arg, uint32_t mask)
 
 void helper_float_check_status (void)
 {
-#ifdef CONFIG_SOFTFLOAT
     if (env->exception_index == POWERPC_EXCP_PROGRAM &&
         (env->error_code & POWERPC_EXCP_FP)) {
         /* Differred floating-point exception after target FPR update */
@@ -990,22 +989,12 @@ void helper_float_check_status (void)
             float_inexact_excp();
         }
     }
-#else
-    if (env->exception_index == POWERPC_EXCP_PROGRAM &&
-        (env->error_code & POWERPC_EXCP_FP)) {
-        /* Differred floating-point exception after target FPR update */
-        if (msr_fe0 != 0 || msr_fe1 != 0)
-            helper_raise_exception_err(env->exception_index, env->error_code);
-    }
-#endif
 }
 
-#ifdef CONFIG_SOFTFLOAT
 void helper_reset_fpstatus (void)
 {
     set_float_exception_flags(0, &env->fp_status);
 }
-#endif
 
 /* fadd - fadd. */
 uint64_t helper_fadd (uint64_t arg1, uint64_t arg2)
target-ppc/translate.c +0 -2
index 9b3f90c..59aef85 100644
@@ -215,9 +215,7 @@ struct opc_handler_t {
 
 static inline void gen_reset_fpstatus(void)
 {
-#ifdef CONFIG_SOFTFLOAT
     gen_helper_reset_fpstatus();
-#endif
 }
 
 static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
Signature · 1 line
1.7.2.3
#17 lore raw

PATCH 7/11 softfloat: add float*_is_zero_or_denormal()

In reply to Aurelien Jarno

float*_is_zero_or_denormal() is available for float32, but not for float64, floatx80 and float128. Fix that.

---
 fpu/softfloat.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
fpu/softfloat.h +15 -0
index 129fc39..8fa4af6 100644
@@ -448,6 +448,11 @@ INLINE int float64_is_any_nan(float64 a)
     return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL);
 }
 
+INLINE int float64_is_zero_or_denormal(float64 a)
+{
+    return (float64_val(a) & 0x7ff0000000000000LL) == 0;
+}
+
 INLINE float64 float64_set_sign(float64 a, int sign)
 {
     return make_float64((float64_val(a) & 0x7fffffffffffffffULL)
@@ -537,6 +542,11 @@ INLINE int floatx80_is_zero(floatx80 a)
     return (a.high & 0x7fff) == 0 && a.low == 0;
 }
 
+INLINE int floatx80_is_zero_or_denormal(floatx80 a)
+{
+    return (a.high & 0x7fff) == 0;
+}
+
 INLINE int floatx80_is_any_nan(floatx80 a)
 {
     return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1);
@@ -625,6 +635,11 @@ INLINE int float128_is_zero(float128 a)
     return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0;
 }
 
+INLINE int float128_is_zero_or_denormal(float128 a)
+{
+    return (a.high & 0x7fff000000000000LL) == 0;
+}
+
 INLINE int float128_is_any_nan(float128 a)
 {
     return ((a.high >> 48) & 0x7fff) == 0x7fff &&
Signature · 1 line
1.7.2.3
#22 lore raw

PATCH 11/11 target-i386: use floatx80_log2() to implement helper_fyl2x*()

In reply to Aurelien Jarno

Use the new floatx80_log2() softfloat function to implement both helper_fyl2x() and helper_fyl2xp1().

---
 target-i386/op_helper.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
target-i386/op_helper.c +10 -10
index eccb957..b021a00 100644
@@ -3972,12 +3972,11 @@ void helper_f2xm1(void)
 
 void helper_fyl2x(void)
 {
-    double fptemp = floatx80_to_double(ST0);
+    floatx80 temp;
 
-    if (fptemp>0.0){
-        fptemp = log(fptemp)/log(2.0);    /* log2(ST) */
-        fptemp *= floatx80_to_double(ST1);
-        ST1 = double_to_floatx80(fptemp);
+    if (! floatx80_is_neg(ST0)) {
+        temp = floatx80_log2(ST0, &env->fp_status);
+        ST1 = floatx80_mul(ST1, temp, &env->fp_status);
         fpop();
     } else {
         env->fpus &= (~0x4700);
@@ -4153,12 +4152,13 @@ void helper_fprem(void)
 
 void helper_fyl2xp1(void)
 {
-    double fptemp = floatx80_to_double(ST0);
+    floatx80 temp;
 
-    if ((fptemp+1.0)>0.0) {
-        fptemp = log(fptemp+1.0) / log(2.0); /* log2(ST+1.0) */
-        fptemp *= floatx80_to_double(ST1);
-        ST1 = double_to_floatx80(fptemp);
+    temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
+    if (!floatx80_is_neg(temp)) {
+        temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
+        temp = floatx80_log2(temp, &env->fp_status);
+        ST1 = floatx80_mul(ST1, temp, &env->fp_status);
         fpop();
     } else {
         env->fpus &= (~0x4700);
Signature · 1 line
1.7.2.3
#8 lore raw

PATCH 4/11 softfloat: always enable floatx80 and float128 support

In reply to Aurelien Jarno

Now that softfloat-native is gone, there is no real point on not always enabling floatx80 and float128 support.

---
 cpu-all.h                  |    2 -
 fpu/softfloat-specialize.h |    7 -----
 fpu/softfloat.c            |   62 --------------------------------------------
 fpu/softfloat.h            |   47 ---------------------------------
 4 files changed, 0 insertions(+), 118 deletions(-)
cpu-all.h +0 -2
index fc252ba..880f570 100644
@@ -137,7 +137,6 @@ typedef union {
     uint64_t ll;
 } CPU_DoubleU;
 
-#if defined(FLOATX80)
 typedef union {
      floatx80 d;
      struct {
@@ -145,7 +144,6 @@ typedef union {
          uint16_t upper;
      } l;
 } CPU_LDoubleU;
-#endif
 
 typedef union {
     float128 q;
fpu/softfloat-specialize.h +0 -7
index 9d68aae..c7d35a1 100644
@@ -523,8 +523,6 @@ static float64 propagateFloat64NaN( float64 a, float64 b STATUS_PARAM)
     }
 }
 
-#ifdef FLOATX80
-
 /*----------------------------------------------------------------------------
 | Returns 1 if the extended double-precision floating-point value `a' is a
 | quiet NaN; otherwise returns 0. This slightly differs from the same
@@ -681,10 +679,6 @@ static floatx80 propagateFloatx80NaN( floatx80 a, floatx80 b STATUS_PARAM)
     }
 }
 
-#endif
-
-#ifdef FLOAT128
-
 /*----------------------------------------------------------------------------
 | Returns 1 if the quadruple-precision floating-point value `a' is a quiet
 | NaN; otherwise returns 0.
@@ -820,4 +814,3 @@ static float128 propagateFloat128NaN( float128 a, float128 b STATUS_PARAM)
     }
 }
 
-#endif
fpu/softfloat.c +0 -62

220 lines not on this page · raw message

fpu/softfloat.h +0 -47

144 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#12 lore raw

PATCH 6/11 target-i386: use floatx80 constants in helper_fld*_ST0()

In reply to Aurelien Jarno

Instead of using a table which doesn't correspond to anything from physical in the CPU, use directly the constants in helper_fld*_ST0().

---
 target-i386/op_helper.c |   27 ++++++++-------------------
 1 files changed, 8 insertions(+), 19 deletions(-)
target-i386/op_helper.c +8 -19
index 4d309ab..cec0c76 100644
@@ -99,17 +99,6 @@ static const uint8_t rclb_table[32] = {
 #define floatx80_l2e make_floatx80( 0x3fff, 0xb8aa3b295c17f0bcLL )
 #define floatx80_l2t make_floatx80( 0x4000, 0xd49a784bcd1b8afeLL )
 
-static const floatx80 f15rk[7] =
-{
-    floatx80_zero,
-    floatx80_one,
-    floatx80_pi,
-    floatx80_lg2,
-    floatx80_ln2,
-    floatx80_l2e,
-    floatx80_l2t,
-};
-
 /* broken thread support */
 
 static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
@@ -3816,42 +3805,42 @@ void helper_fabs_ST0(void)
 
 void helper_fld1_ST0(void)
 {
-    ST0 = f15rk[1];
+    ST0 = floatx80_one;
 }
 
 void helper_fldl2t_ST0(void)
 {
-    ST0 = f15rk[6];
+    ST0 = floatx80_l2t;
 }
 
 void helper_fldl2e_ST0(void)
 {
-    ST0 = f15rk[5];
+    ST0 = floatx80_l2e;
 }
 
 void helper_fldpi_ST0(void)
 {
-    ST0 = f15rk[2];
+    ST0 = floatx80_pi;
 }
 
 void helper_fldlg2_ST0(void)
 {
-    ST0 = f15rk[3];
+    ST0 = floatx80_lg2;
 }
 
 void helper_fldln2_ST0(void)
 {
-    ST0 = f15rk[4];
+    ST0 = floatx80_ln2;
 }
 
 void helper_fldz_ST0(void)
 {
-    ST0 = f15rk[0];
+    ST0 = floatx80_zero;
 }
 
 void helper_fldz_FT0(void)
 {
-    FT0 = f15rk[0];
+    FT0 = floatx80_zero;
 }
 
 uint32_t helper_fnstsw(void)
Signature · 1 line
1.7.2.3
#19 lore raw

PATCH 8/11 target-i386: cleanup helper_fxam_ST0()

In reply to Aurelien Jarno

Rewrite helper_fxam_ST0() using only softfloat functions.

---
 target-i386/op_helper.c |   30 ++++++++++++------------------
 1 files changed, 12 insertions(+), 18 deletions(-)
target-i386/op_helper.c +12 -18
index cec0c76..8ba2b5f 100644
@@ -4241,29 +4241,23 @@ void helper_fcos(void)
 
 void helper_fxam_ST0(void)
 {
-    CPU_LDoubleU temp;
-    int expdif;
-
-    temp.d = ST0;
-
     env->fpus &= (~0x4700);  /* (C3,C2,C1,C0) <-- 0000 */
-    if (SIGND(temp))
+
+    if (floatx80_is_neg(ST0)) {
         env->fpus |= 0x200; /* C1 <-- 1 */
+    }
 
     /* XXX: test fptags too */
-    expdif = EXPD(temp);
-    if (expdif == MAXEXPD) {
-        if (MANTD(temp) == 0x8000000000000000ULL)
-            env->fpus |=  0x500 /*Infinity*/;
-        else
-            env->fpus |=  0x100 /*NaN*/;
-    } else if (expdif == 0) {
-        if (MANTD(temp) == 0)
-            env->fpus |=  0x4000 /*Zero*/;
-        else
-            env->fpus |= 0x4400 /*Denormal*/;
+    if (floatx80_is_infinity(ST0)) {
+        env->fpus |=  0x500; /* (C3,C2,C0) <-- 011 */
+    } else if (floatx80_is_any_nan(ST0)) {
+        env->fpus |=  0x100; /* (C3,C2,C0) <-- 001 */
+    } else if (floatx80_is_zero(ST0)) {
+        env->fpus |= 0x4000; /* (C3,C2,C0) <-- 100 */
+    } else if (floatx80_is_zero_or_denormal(ST0)) {
+        env->fpus |= 0x4400; /* (C3,C2,C0) <-- 110 */
     } else {
-        env->fpus |= 0x400;
+        env->fpus |=  0x400; /* (C3,C2,C0) <-- 010 */
     }
 }
 
Signature · 1 line
1.7.2.3
#0 lore raw

cover softfloat-native removal and i386 improvements

This patch series finally removes softfloat-native as it is not used by default in any target. In then laters improves the target-i386 code as it does not need to be compatible with softfloat-native anymore.

Aurelien Jarno (11):
target-ppc: remove old CONFIG_SOFTFLOAT #ifdef target-mips/gdbstub: remove old CONFIG_SOFTFLOAT #ifdef
softfloat-native: remove
softfloat: always enable floatx80 and float128 support
target-i386: remove old code handling float64
target-i386: use floatx80 constants in helper_fld*_ST0()
softfloat: add float*_is_zero_or_denormal()
target-i386: cleanup helper_fxam_ST0()
target-i386: add support for FPU exceptions
softfloat: add floatx80_log2() function
target-i386: use floatx80_log2() to implement helper_fyl2x*()

 Makefile.target            |    3 +-
 configure                  |    2 -
 cpu-all.h                  |    7 +-
 fpu/softfloat-native.c     |  540 --------------------------------------------
 fpu/softfloat-native.h     |  531 -------------------------------------------
 fpu/softfloat-specialize.h |    7 -
 fpu/softfloat.c            |  120 +++++-----
 fpu/softfloat.h            |   77 ++-----
 gdbstub.c                  |    2 -
 target-i386/cpu.h          |   37 ++--
 target-i386/exec.h         |  144 +------------
 target-i386/helper.c       |   41 +++-
 target-i386/machine.c      |  104 +---------
 target-i386/op_helper.c    |  337 +++++++++++-----------------
 target-ppc/helper.h        |    2 -
 target-ppc/op_helper.c     |   11 -
 target-ppc/translate.c     |    2 -
 17 files changed, 271 insertions(+), 1696 deletions(-)
 delete mode 100644 fpu/softfloat-native.c
 delete mode 100644 fpu/softfloat-native.h
Signature · 1 line
1.7.2.3
#3 lore raw

PATCH 2/11 target-mips/gdbstub: remove old CONFIG_SOFTFLOAT #ifdef

target-mips has been switched to softfloat only long ago, but a few #ifdef CONFIG_SOFTFLOAT have been forgotten. Remove them.

---
 gdbstub.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
gdbstub.c +0 -2
index 0838948..7cd7bf5 100644
@@ -1105,10 +1105,8 @@ static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)
             env->active_fpu.fcr31 = tmp & 0xFF83FFFF;
             /* set rounding mode */
             RESTORE_ROUNDING_MODE;
-#ifndef CONFIG_SOFTFLOAT
             /* no floating point exception for native float */
             SET_FP_ENABLE(env->active_fpu.fcr31, 0);
-#endif
             break;
         case 71: env->active_fpu.fcr0 = tmp; break;
         }
Signature · 1 line
1.7.2.3
#10 lore raw

PATCH 5/11 target-i386: remove old code handling float64

In reply to Aurelien Jarno

Now that target-i386 uses softfloat, floatx80 is always available and there is no need anymore to have code handling both float64 and floax80.

---
 target-i386/cpu.h       |   22 +---
 target-i386/exec.h      |  132 +-----------------------
 target-i386/helper.c    |    5 -
 target-i386/machine.c   |  101 ------------------
 target-i386/op_helper.c |  266 +++++++++++++++++++----------------------------
 5 files changed, 115 insertions(+), 411 deletions(-)
target-i386/cpu.h +4 -18
index 715828f..fe65886 100644
@@ -532,16 +532,6 @@ enum {
     CC_OP_NB,
 };
 
-#ifdef FLOATX80
-#define USE_X86LDOUBLE
-#endif
-
-#ifdef USE_X86LDOUBLE
-typedef floatx80 CPU86_LDouble;
-#else
-typedef float64 CPU86_LDouble;
-#endif
-
 typedef struct SegmentCache {
     uint32_t selector;
     target_ulong base;
@@ -594,11 +584,7 @@ typedef union {
 #define MMX_Q(n) q
 
 typedef union {
-#ifdef USE_X86LDOUBLE
-    CPU86_LDouble d __attribute__((aligned(16)));
-#else
-    CPU86_LDouble d;
-#endif
+    floatx80 d __attribute__((aligned(16)));
     MMXReg mmx;
 } FPReg;
 
@@ -654,7 +640,7 @@ typedef struct CPUX86State {
 
     /* emulator internal variables */
     float_status fp_status;
-    CPU86_LDouble ft0;
+    floatx80 ft0;
 
     float_status mmx_status; /* for 3DNow! float ops */
     float_status sse_status;
@@ -865,8 +851,8 @@ static inline void cpu_x86_set_cpl(CPUX86State *s, int cpl)
 
 /* op_helper.c */
 /* used for debug or cpu save/restore */
-void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, CPU86_LDouble f);
-CPU86_LDouble cpu_set_fp80(uint64_t mant, uint16_t upper);
+void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f);
+floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper);
 
 /* cpu-exec.c */
 /* the following helpers are only usable in user mode simulation as
target-i386/exec.h +4 -128

170 lines not on this page · raw message

target-i386/helper.c +0 -5
index 89df997..5c4b288 100644
@@ -403,15 +403,10 @@ void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
                     fptag,
                     env->mxcsr);
         for(i=0;i<8;i++) {
-#if defined(USE_X86LDOUBLE)
             CPU_LDoubleU u;
             u.d = env->fpregs[i].d;
             cpu_fprintf(f, "FPR%d=%016" PRIx64 " %04x",
                         i, u.l.lower, u.l.upper);
-#else
-            cpu_fprintf(f, "FPR%d=%016" PRIx64,
-                        i, env->fpregs[i].mmx.q);
-#endif
             if ((i & 1) == 1)
                 cpu_fprintf(f, "\n");
             else
target-i386/machine.c +0 -101

120 lines not on this page · raw message

target-i386/op_helper.c +107 -159

712 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#21 lore raw

PATCH 10/11 softfloat: add floatx80_log2() function

In reply to Aurelien Jarno

Based on the same algorithm as float32_log2() and float64_log2().

---
 fpu/softfloat.c |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fpu/softfloat.h |    1 +
 2 files changed, 59 insertions(+), 0 deletions(-)
fpu/softfloat.c +58 -0
index b11e6dd..87e3645 100644
@@ -4543,6 +4543,64 @@ floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM )
 }
 
 /*----------------------------------------------------------------------------
+| Returns the binary log of the extended-precision floating-point value `a'.
+| The operation is performed according to the IEC/IEEE Standard for Binary
+| Floating-Point Arithmetic.
+*----------------------------------------------------------------------------*/
+floatx80 floatx80_log2( floatx80 a STATUS_PARAM )
+{
+    flag aSign, zSign;
+    int32_t aExp;
+    uint64_t aSig0, aSig1, zSig0, zSig1, i;
+    floatx80 z;
+
+    aSig0 = 0;
+    aSig1 = extractFloatx80Frac( a );
+    aExp = extractFloatx80Exp( a );
+    aSign = extractFloatx80Sign( a );
+
+    if ( aExp == 0 ) {
+        if ( (aSig1 << 1) == 0 ) {
+            return packFloatx80( 1, 0x7FFF, 0 );
+        }
+        normalizeFloatx80Subnormal( aSig1, &aExp, &aSig1 );
+    }
+    if ( aSign ) {
+        float_raise( float_flag_invalid STATUS_VAR);
+        z.low = floatx80_default_nan_low;
+        z.high = floatx80_default_nan_high;
+        return z;
+    }
+    if ( aExp == 0x7FFF ) {
+        if ( aSig1 ) {
+            return propagateFloatx80NaN( a, a STATUS_VAR );
+        }
+        return a;
+    }
+
+    aExp -= 0x3FFF;
+    zSign = aExp < 0;
+    zSig0 = (int64_t)aExp >> 1;
+    zSig1 = (int64_t)aExp << 63;
+    for (i = 1LL << 62; i > 0; i >>= 1) {
+        mul64To128( aSig1, aSig1, &aSig0, &aSig1 );
+        if ( aSig0 & LIT64 ( 0x8000000000000000 ) ) {
+            aSig1 = aSig0;
+            zSig1 |= i;
+        } else {
+            aSig1 = (aSig0 << 1) | (aSig1 >> 63);
+        }
+    }
+
+    if ( zSign ) {
+        zSig1 = -zSig1;
+        zSig0 = ~zSig0 + (zSig1 ? 0 : 1);
+    }
+    return normalizeRoundAndPackFloatx80( STATUS(floatx80_rounding_precision),
+                                          zSign, 0x403f, zSig0, zSig1 STATUS_VAR );
+}
+
+/*----------------------------------------------------------------------------
 | Returns 1 if the extended double-precision floating-point value `a' is equal
 | to the corresponding value `b', and 0 otherwise.  The invalid exception is
 | raised if either operand is a NaN.  Otherwise, the comparison is performed
fpu/softfloat.h +1 -0
index 8fa4af6..03ce60d 100644
@@ -500,6 +500,7 @@ floatx80 floatx80_mul( floatx80, floatx80 STATUS_PARAM );
 floatx80 floatx80_div( floatx80, floatx80 STATUS_PARAM );
 floatx80 floatx80_rem( floatx80, floatx80 STATUS_PARAM );
 floatx80 floatx80_sqrt( floatx80 STATUS_PARAM );
+floatx80 floatx80_log2( floatx80 STATUS_PARAM );
 int floatx80_eq( floatx80, floatx80 STATUS_PARAM );
 int floatx80_le( floatx80, floatx80 STATUS_PARAM );
 int floatx80_lt( floatx80, floatx80 STATUS_PARAM );
Signature · 1 line
1.7.2.3
#6 lore raw

PATCH 3/11 softfloat-native: remove

In reply to Aurelien Jarno

Remove softfloat-native support, all targets are now using softfloat instead.

---
 Makefile.target        |    3 +-
 configure              |    2 -
 cpu-all.h              |    5 +-
 fpu/softfloat-native.c |  540 ------------------------------------------------
 fpu/softfloat-native.h |  531 -----------------------------------------------
 fpu/softfloat.h        |   14 --
 6 files changed, 2 insertions(+), 1093 deletions(-)
Makefile.target +1 -2
index 2e281a4..ed3f95a 100644
@@ -71,8 +71,7 @@ all: $(PROGS) stap
 # cpu emulator library
 libobj-y = exec.o translate-all.o cpu-exec.o translate.o
 libobj-y += tcg/tcg.o
-libobj-$(CONFIG_SOFTFLOAT) += fpu/softfloat.o
-libobj-$(CONFIG_NOSOFTFLOAT) += fpu/softfloat-native.o
+libobj-y += fpu/softfloat.o
 libobj-y += op_helper.o helper.o
 ifeq ($(TARGET_BASE_ARCH), i386)
 libobj-y += cpuid.o
configure +0 -2
index d7dba5d..96bb01f 100755
@@ -3382,8 +3382,6 @@ if test ! -z "$gdb_xml_files" ; then
   echo "TARGET_XML_FILES=$list" >> $config_target_mak
 fi
 
-echo "CONFIG_SOFTFLOAT=y" >> $config_target_mak
-
 if test "$target_user_only" = "yes" -a "$bflt" = "yes"; then
   echo "TARGET_HAS_BFLT=y" >> $config_target_mak
 fi
cpu-all.h +1 -4
index 54df1d3..fc252ba 100644
@@ -123,8 +123,7 @@ typedef union {
    endian ! */
 typedef union {
     float64 d;
-#if defined(HOST_WORDS_BIGENDIAN) \
-    || (defined(__arm__) && !defined(__VFP_FP__) && !defined(CONFIG_SOFTFLOAT))
+#if defined(HOST_WORDS_BIGENDIAN)
     struct {
         uint32_t upper;
         uint32_t lower;
@@ -148,7 +147,6 @@ typedef union {
 } CPU_LDoubleU;
 #endif
 
-#if defined(CONFIG_SOFTFLOAT)
 typedef union {
     float128 q;
 #if defined(HOST_WORDS_BIGENDIAN)
@@ -175,7 +173,6 @@ typedef union {
     } ll;
 #endif
 } CPU_QuadU;
-#endif
 
 /* CPU memory access without any memory or io remapping */
 
fpu/softfloat-native.c deleted +0 -540

540 lines not on this page · raw message

fpu/softfloat-native.h deleted +0 -531

531 lines not on this page · raw message

fpu/softfloat.h +0 -14
index 5eff085..dd0252a 100644
@@ -81,16 +81,9 @@ typedef int64_t int64;
 | input or output the `floatx80' type will be defined.  The same applies to
 | the `FLOAT128' macro and the quadruple-precision format `float128'.
 *----------------------------------------------------------------------------*/
-#ifdef CONFIG_SOFTFLOAT
 /* bit exact soft float support */
 #define FLOATX80
 #define FLOAT128
-#else
-/* native float support */
-#if (defined(__i386__) || defined(__x86_64__)) && !defined(CONFIG_BSD)
-#define FLOATX80
-#endif
-#endif /* !CONFIG_SOFTFLOAT */
 
 #define STATUS_PARAM , float_status *status
 #define STATUS(field) status->field
@@ -106,7 +99,6 @@ enum {
     float_relation_unordered =  2
 };
 
-#ifdef CONFIG_SOFTFLOAT
 /*----------------------------------------------------------------------------
 | Software IEC/IEEE floating-point types.
 *----------------------------------------------------------------------------*/
@@ -698,10 +690,4 @@ INLINE int float128_is_any_nan(float128 a)
 
 #endif
 
-#else /* CONFIG_SOFTFLOAT */
-
-#include "softfloat-native.h"
-
-#endif /* !CONFIG_SOFTFLOAT */
-
 #endif /* !SOFTFLOAT_H */
Signature · 1 line
1.7.2.3
#20 lore raw

PATCH 9/11 target-i386: add support for FPU exceptions

In reply to Aurelien Jarno

This patch adds support for FPU exceptions. It keeps the exception in the softfloat status, and copy them back to env->fpus when needed by oring them. When loading a new value to env->fpus, it starts with a clean softfloat status.

---
 target-i386/cpu.h       |   15 +++++++++++++++
 target-i386/exec.h      |   12 ------------
 target-i386/helper.c    |   36 ++++++++++++++++++++++++++++++++++++
 target-i386/machine.c   |    3 ++-
 target-i386/op_helper.c |   32 ++++++++++++++++----------------
 5 files changed, 69 insertions(+), 29 deletions(-)
target-i386/cpu.h +15 -0
index fe65886..d216356 100644
@@ -121,6 +121,19 @@
 #define VIP_MASK                0x00100000
 #define ID_MASK                 0x00200000
 
+/* FPU flags */
+#define FPUS_IE (1 << 0)
+#define FPUS_DE (1 << 1)
+#define FPUS_ZE (1 << 2)
+#define FPUS_OE (1 << 3)
+#define FPUS_UE (1 << 4)
+#define FPUS_PE (1 << 5)
+#define FPUS_SF (1 << 6)
+#define FPUS_SE (1 << 7)
+#define FPUS_B  (1 << 15)
+
+#define FPUC_EM 0x3f
+
 /* hidden flags - used internally by qemu to represent additional cpu
    states. Only the CPL, INHIBIT_IRQ, SMM and SVMI are not
    redundant. We avoid using the IOPL_MASK, TF_MASK and VM_MASK bit
@@ -877,6 +890,8 @@ void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
 
 /* helper.c */
+void cpu_x86_set_fpus(CPUX86State *s, uint16_t val);
+void cpu_x86_update_fpus(CPUX86State *s);
 int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
                              int is_write, int mmu_idx, int is_softmmu);
 #define cpu_handle_mmu_fault cpu_x86_handle_mmu_fault
target-i386/exec.h +0 -12
index 9bd080e..e14d0d9 100644
@@ -144,18 +144,6 @@ static inline void helper_fstt(floatx80 f, target_ulong ptr)
     stw(ptr + 8, temp.l.upper);
 }
 
-#define FPUS_IE (1 << 0)
-#define FPUS_DE (1 << 1)
-#define FPUS_ZE (1 << 2)
-#define FPUS_OE (1 << 3)
-#define FPUS_UE (1 << 4)
-#define FPUS_PE (1 << 5)
-#define FPUS_SF (1 << 6)
-#define FPUS_SE (1 << 7)
-#define FPUS_B  (1 << 15)
-
-#define FPUC_EM 0x3f
-
 static inline uint32_t compute_eflags(void)
 {
     return env->eflags | helper_cc_compute_all(CC_OP) | (DF & DF_MASK);
target-i386/helper.c +36 -0
index 5c4b288..23646d3 100644
@@ -396,6 +396,7 @@ void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
         for(i = 0; i < 8; i++) {
             fptag |= ((!env->fptags[i]) << i);
         }
+        cpu_x86_update_fpus(env);
         cpu_fprintf(f, "FCW=%04x FSW=%04x [ST=%d] FTW=%02x MXCSR=%08x\n",
                     env->fpuc,
                     (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11,
@@ -1238,6 +1239,41 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
     return 1;
 }
 
+void cpu_x86_set_fpus(CPUX86State *s, uint16_t val)
+{
+    set_float_exception_flags(0, &s->fp_status);
+    s->fpus = val;
+}
+
+void cpu_x86_update_fpus(CPUX86State *s)
+{
+    int xcpt = get_float_exception_flags(&s->fp_status);
+
+    if (xcpt) {
+        if (xcpt & float_flag_invalid) {
+            s->fpus |= FPUS_IE;
+        }
+        if (xcpt & float_flag_input_denormal) {
+            s->fpus |= FPUS_DE;
+        }
+        if (xcpt & float_flag_divbyzero) {
+            s->fpus |= FPUS_ZE;
+        }
+        if (xcpt & float_flag_overflow) {
+            s->fpus |= FPUS_OE;
+        }
+        if (xcpt & float_flag_underflow) {
+            s->fpus |= FPUS_UE;
+        }
+        if (xcpt & float_flag_inexact) {
+            s->fpus |= FPUS_PE;
+        }
+        if (s->fpus & (~s->fpuc & FPUC_EM)) {
+            s->fpus |= FPUS_SE | FPUS_B;
+        }
+    }
+}
+
 CPUX86State *cpu_x86_init(const char *cpu_model)
 {
     CPUX86State *env;
target-i386/machine.c +2 -1
index bbeae88..82c5c01 100644
@@ -241,6 +241,7 @@ static void cpu_pre_save(void *opaque)
     int i;
 
     /* FPU */
+    cpu_x86_update_fpus(env);
     env->fpus_vmstate = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
     env->fptag_vmstate = 0;
     for(i = 0; i < 8; i++) {
@@ -257,7 +258,7 @@ static int cpu_post_load(void *opaque, int version_id)
 
     /* XXX: restore FPU round state */
     env->fpstt = (env->fpus_vmstate >> 11) & 7;
-    env->fpus = env->fpus_vmstate & ~0x3800;
+    cpu_x86_set_fpus(env, env->fpus_vmstate & ~0x3800);
     env->fptag_vmstate ^= 0xff;
     for(i = 0; i < 8; i++) {
         env->fptags[i] = (env->fptag_vmstate >> i) & 1;
target-i386/op_helper.c +16 -16
index 8ba2b5f..eccb957 100644
@@ -3447,18 +3447,8 @@ static inline floatx80 double_to_floatx80(double a)
     return float64_to_floatx80(u.f64, &env->fp_status);
 }
 
-static void fpu_set_exception(int mask)
-{
-    env->fpus |= mask;
-    if (env->fpus & (~env->fpuc & FPUC_EM))
-        env->fpus |= FPUS_SE | FPUS_B;
-}
-
 static inline floatx80 helper_fdiv(floatx80 a, floatx80 b)
 {
-    if (floatx80_is_zero(b)) {
-        fpu_set_exception(FPUS_ZE);
-    }
     return floatx80_div(a, b, &env->fp_status);
 }
 
@@ -3845,6 +3835,7 @@ void helper_fldz_FT0(void)
 
 uint32_t helper_fnstsw(void)
 {
+    cpu_x86_update_fpus(env);
     return (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
 }
 
@@ -3897,18 +3888,19 @@ void helper_fldcw(uint32_t val)
 
 void helper_fclex(void)
 {
-    env->fpus &= 0x7f00;
+    cpu_x86_set_fpus(env, env->fpus & 0x7f00);
 }
 
 void helper_fwait(void)
 {
+    cpu_x86_update_fpus(env);
     if (env->fpus & FPUS_SE)
         fpu_raise_exception();
 }
 
 void helper_fninit(void)
 {
-    env->fpus = 0;
+    cpu_x86_set_fpus(env, 0);
     env->fpstt = 0;
     env->fpuc = 0x37f;
     env->fptags[0] = 1;
@@ -4208,7 +4200,13 @@ void helper_fscale(void)
     if (floatx80_is_any_nan(ST1)) {
         ST0 = ST1;
     } else {
-        int n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status);
+        int n, x;
+
+        /* The float to int conversion should not generate any exception. */
+        x = get_float_exception_flags(&env->fp_status);
+        n = floatx80_to_int32_round_to_zero(ST1, &env->fp_status);
+        set_float_exception_flags(x, &env->fp_status);
+
         ST0 = floatx80_scalbn(ST0, n, &env->fp_status);
     }
 }
@@ -4267,6 +4265,7 @@ void helper_fstenv(target_ulong ptr, int data32)
     uint64_t mant;
     CPU_LDoubleU tmp;
 
+    cpu_x86_update_fpus(env);
     fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
     fptag = 0;
     for (i=7; i>=0; i--) {
@@ -4324,7 +4323,7 @@ void helper_fldenv(target_ulong ptr, int data32)
         fptag = lduw(ptr + 4);
     }
     env->fpstt = (fpus >> 11) & 7;
-    env->fpus = fpus & ~0x3800;
+    cpu_x86_set_fpus(env, fpus & ~0x3800);
     for(i = 0;i < 8; i++) {
         env->fptags[i] = ((fptag & 3) == 3);
         fptag >>= 2;
@@ -4346,7 +4345,7 @@ void helper_fsave(target_ulong ptr, int data32)
     }
 
     /* fninit */
-    env->fpus = 0;
+    cpu_x86_set_fpus(env, 0);
     env->fpstt = 0;
     env->fpuc = 0x37f;
     env->fptags[0] = 1;
@@ -4385,6 +4384,7 @@ void helper_fxsave(target_ulong ptr, int data64)
         raise_exception(EXCP0D_GPF);
     }
 
+    cpu_x86_update_fpus(env);
     fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
     fptag = 0;
     for(i = 0; i < 8; i++) {
@@ -4450,7 +4450,7 @@ void helper_fxrstor(target_ulong ptr, int data64)
     fpus = lduw(ptr + 2);
     fptag = lduw(ptr + 4);
     env->fpstt = (fpus >> 11) & 7;
-    env->fpus = fpus & ~0x3800;
+    cpu_x86_set_fpus(env, fpus & ~0x3800);
     fptag ^= 0xff;
     for(i = 0;i < 8; i++) {
         env->fptags[i] = ((fptag >> i) & 1);
Signature · 1 line
1.7.2.3
#4 lore raw

Re: [Qemu-devel] [PATCH 02/11] target-mips/gdbstub: remove old CONFIG_SOFTFLOAT #ifdef

In reply to Aurelien Jarno
Quoted 7 lines · Aurelien Jarno

target-mips has been switched to softfloat only long ago, but a few #ifdef CONFIG_SOFTFLOAT have been forgotten. Remove them.

-#ifndef CONFIG_SOFTFLOAT
            /* no floating point exception for native float */ SET_FP_ENABLE(env->active_fpu.fcr31, 0); -#endif

Shouldn't the whole of this section be removed? This is an #ifndef, not a #ifdef...

-- PMM

#5 lore raw

Re: [Qemu-devel] [PATCH 02/11] target-mips/gdbstub: remove old CONFIG_SOFTFLOAT #ifdef

Quoted 4 lines · Peter Maydell
Quoted 2 lines · Aurelien Jarno

target-mips has been switched to softfloat only long ago, but a few #ifdef CONFIG_SOFTFLOAT have been forgotten. Remove them.

Quoted 8 lines
Quoted 4 lines

-#ifndef CONFIG_SOFTFLOAT
            /* no floating point exception for native float */ SET_FP_ENABLE(env->active_fpu.fcr31, 0); -#endif

Shouldn't the whole of this section be removed? This is an #ifndef, not a #ifdef...

Yes good catch, it's a mistake from my side. I have fixed it locally, I'll send it at the same time of the next version of the series.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#13 lore raw

Re: [Qemu-devel] [PATCH 06/11] target-i386: use floatx80 constants in helper_fld*_ST0()

In reply to Aurelien Jarno

Am 15.05.2011 um 16:13 schrieb Aurelien Jarno:

Quoted 32 lines

Instead of using a table which doesn't correspond to anything from physical in the CPU, use directly the constants in helper_fld*_ST0().

---
target-i386/op_helper.c | 27 ++++++++-------------------

1 files changed, 8 insertions(+), 19 deletions(-)
target-i386/op_helper.c +0 -11
index 4d309ab..cec0c76 100644
@@ -99,17 +99,6 @@ static const uint8_t rclb_table[32] = {
 #define floatx80_l2e make_floatx80( 0x3fff, 0xb8aa3b295c17f0bcLL )
 #define floatx80_l2t make_floatx80( 0x4000, 0xd49a784bcd1b8afeLL )
 
-static const floatx80 f15rk[7] =
-{
-    floatx80_zero,
-    floatx80_one,
-    floatx80_pi,
-    floatx80_lg2,
-    floatx80_ln2,
-    floatx80_l2e,
-    floatx80_l2t,
-};
-
 /* broken thread support */
 
 static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;

target-i386/op_helper.c void helper_fabs_ST0(void) · line 3809

Quoted 6 lines
target-i386/op_helper.c +1 -1
@@ -3816,42 +3805,42 @@ void helper_fabs_ST0(void)
 
 void helper_fld1_ST0(void)
 {
-    ST0 = f15rk[1];
+    ST0 = floatx80_one;
 }

A backport of this using floatx_... compiles okay.
BeOS R5 boots fine; didn't have any special float tests at hand, so I ran an OpenGL teapot demo which I assume is software-rendered.

Andreas

Quoted 46 lines
target-i386/op_helper.c +7 -7
 void helper_fldl2t_ST0(void)
 {
-    ST0 = f15rk[6];
+    ST0 = floatx80_l2t;
 }
 
 void helper_fldl2e_ST0(void)
 {
-    ST0 = f15rk[5];
+    ST0 = floatx80_l2e;
 }
 
 void helper_fldpi_ST0(void)
 {
-    ST0 = f15rk[2];
+    ST0 = floatx80_pi;
 }
 
 void helper_fldlg2_ST0(void)
 {
-    ST0 = f15rk[3];
+    ST0 = floatx80_lg2;
 }
 
 void helper_fldln2_ST0(void)
 {
-    ST0 = f15rk[4];
+    ST0 = floatx80_ln2;
 }
 
 void helper_fldz_ST0(void)
 {
-    ST0 = f15rk[0];
+    ST0 = floatx80_zero;
 }
 
 void helper_fldz_FT0(void)
 {
-    FT0 = f15rk[0];
+    FT0 = floatx80_zero;
 }
 
 uint32_t helper_fnstsw(void)
Signature · 1 line
1.7.2.3
#23 lore raw

Re: [Qemu-devel] [PATCH 11/11] target-i386: use floatx80_log2() to implement helper_fyl2x*()

In reply to Aurelien Jarno

target-i386/op_helper.c void helper_fprem(void) · line 4161

Quoted 5 lines · Aurelien Jarno
target-i386/op_helper.c +5 -0
+    temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
+    if (!floatx80_is_neg(temp)) {
+        temp = floatx80_add(ST0, floatx80_one, &env->fp_status);
+        temp = floatx80_log2(temp, &env->fp_status);
+        ST1 = floatx80_mul(ST1, temp, &env->fp_status);

While this is probably better than the existing code, you really should be using a different series expansion than for log2. This expansion will be wildly inaccurate for inputs near zero.

r~

#11 lore raw

Re: [Qemu-devel] [PATCH 05/11] target-i386: remove old code handling float64

In reply to Aurelien Jarno
Quoted 4 lines · Aurelien Jarno

Now that target-i386 uses softfloat, floatx80 is always available and there is no need anymore to have code handling both float64 and floax80.

This patch is OK in terms of how it leaves the code, but I think some parts of it are out of sequence with the rest of the patchset.

For instance:

target-i386/cpu.h enum { · line 537

Quoted 3 lines
target-i386/cpu.h +0 -3
-#ifdef FLOATX80
-#define USE_X86LDOUBLE
-#endif

We've already removed the FLOATX80 define in a previous patch, so if we don't delete the x86 use of it until this patch then the behaviour will briefly flip-flop as you go through the patch stack, which could be bad for bisection.

target-i386/op_helper.c static const uint8_t rclb_table[32] = { · line 106

Quoted 9 lines
target-i386/op_helper.c +0 -9
-#if defined(CONFIG_SOFTFLOAT)
-# define floatx_lg2 make_floatx80( 0x3ffd, 0x9a209a84fbcff799LL )
-# define floatx_l2e make_floatx80( 0x3fff, 0xb8aa3b295c17f0bcLL )
-# define floatx_l2t make_floatx80( 0x4000, 0xd49a784bcd1b8afeLL )
-#else
-# define floatx_lg2 (0.30102999566398119523L)
-# define floatx_l2e (1.44269504088896340739L)
-# define floatx_l2t (3.32192809488736234781L)
-#endif

Similarly, this #ifdeffery should have gone away when we took out CONFIG_SOFTFLOAT, not later.

(Also the patch was a bit of a pig to review because it combines several distinct mostly-mechanical transformations.)

-- PMM

Reviewed-by on v1 6/11
#14 lore raw

Re: [Qemu-devel] [PATCH 06/11] target-i386: use floatx80 constants in helper_fld*_ST0()

In reply to Aurelien Jarno
Quoted 2 lines · Aurelien Jarno

Instead of using a table which doesn't correspond to anything from physical in the CPU, use directly the constants in helper_fld*_ST0().

Actually I rather suspect there is effectively a table in the CPU indexed by the last 3 bits of the FLD* opcode... It would be possible to implement this group of insns in QEMU with a single helper function that took the index into the array, but since the array seems to be causing weird compilation problems we might as well stick with the lots-of-helpers approach, at which point this is a sensible cleanup.

#15 lore raw

Re: [Qemu-devel] [PATCH 06/11] target-i386: use floatx80 constants in helper_fld*_ST0()

In reply to Peter Maydell

Am 20.05.2011 um 12:32 schrieb Peter Maydell:

Quoted 11 lines · Aurelien Jarno
Quoted 2 lines

Instead of using a table which doesn't correspond to anything from physical in the CPU, use directly the constants in helper_fld*_ST0().

Actually I rather suspect there is effectively a table in the CPU indexed by the last 3 bits of the FLD* opcode... It would be possible to implement this group of insns in QEMU with a single helper function that took the index into the array, but since the array seems to be causing weird compilation problems we might as well stick with the lots-of-helpers approach, at which point this is a sensible cleanup.

In OpenBIOS we once ran into a similar error on ppc64 where a cast would've resulted in the truncation of a static pointer ... could this be an alignment issue here, that it's being truncated by the floatx80 cast? I tried using __attribute__((packed)) on the floatx80 type without luck. Or maybe the constant width is being handled weird, with LL being 128 bits rather than the expected 64 bits? ;)

I wasn't specifically asking for the table to be removed, just for some working solution.

Andreas

#16 lore raw

Re: [Qemu-devel] [PATCH 06/11] target-i386: use floatx80 constants in helper_fld*_ST0()

Am 21.05.11 11:35, schrieb Andreas Färber:

Quoted 14 lines

Am 20.05.2011 um 12:32 schrieb Peter Maydell:

Quoted 11 lines · Aurelien Jarno
Quoted 2 lines

Instead of using a table which doesn't correspond to anything from physical in the CPU, use directly the constants in helper_fld*_ST0().

Actually I rather suspect there is effectively a table in the CPU indexed by the last 3 bits of the FLD* opcode... It would be possible to implement this group of insns in QEMU with a single helper function that took the index into the array, but since the array seems to be causing weird compilation problems we might as well stick with the lots-of-helpers approach, at which point this is a sensible cleanup.

Quoted 2 lines

In OpenBIOS we once ran into a similar error on ppc64 where a cast would've resulted in the truncation of a static pointer ... could this be an alignment issue here, that it's being truncated by the floatx80 cast? I tried using __attribute__((packed)) on the floatx80 type without luck. Or maybe the constant width is being handled weird, with LL being 128 bits rather than the expected 64 bits? ;)

Some more info:

The issue only pops up with -std=c99 or -std=gnu99, with both gcc 3.4.3 and 4.3.2. That's reproducible on Darwin gcc 4.0.1 and 4.2 as well.

The following trivial sample program triggers it, there's no magic Solaris headers involved:

#include <inttypes.h>
// on OpenSolaris:
// typedef unsigned short uint16_t;
// typedef unsigned long long uint64_t;

typedef struct {
    uint64_t low;
    uint16_t high;
} floatx80;

#define make_floatx80(exp, mant) ((floatx80) { mant, exp })

#define floatx80_l2t make_floatx80( 0x4000, 0xd49a784bcd1b8afeLL )

static const floatx80 mine[1] = {
    floatx80_l2t,
};

int main(void)
{
}

Any thoughts?

Andreas