Skip to contentSkip to conversation

Alpha improvments, round 3

PATCH New Richard Henderson 1 participant 6 messages Dec 14, 2009

lore
Share & tools
lore
#2 lore raw

PATCH 2/5 target-alpha: Implement fp branch/cmov inline.

In reply to Richard Henderson

The old fcmov implementation had a typo:
- tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
which moved the condition, not the second source, to the destination.

But it's also easy to implement the simplified fp comparison inline.

---
 target-alpha/helper.h    |    7 --
 target-alpha/op_helper.c |   31 -------
 target-alpha/translate.c |  197 ++++++++++++++++++++++++++--------------------
 3 files changed, 110 insertions(+), 125 deletions(-)
target-alpha/helper.h +0 -7
index 4eb3b6f..bedd3c0 100644
@@ -77,13 +77,6 @@ DEF_HELPER_2(cmpgeq, i64, i64, i64)
 DEF_HELPER_2(cmpgle, i64, i64, i64)
 DEF_HELPER_2(cmpglt, i64, i64, i64)
 
-DEF_HELPER_1(cmpfeq, i64, i64)
-DEF_HELPER_1(cmpfne, i64, i64)
-DEF_HELPER_1(cmpflt, i64, i64)
-DEF_HELPER_1(cmpfle, i64, i64)
-DEF_HELPER_1(cmpfgt, i64, i64)
-DEF_HELPER_1(cmpfge, i64, i64)
-
 DEF_HELPER_2(cpys, i64, i64, i64)
 DEF_HELPER_2(cpysn, i64, i64, i64)
 DEF_HELPER_2(cpyse, i64, i64, i64)
target-alpha/op_helper.c +0 -31
index d7f4fb2..8eba5ec 100644
@@ -884,37 +884,6 @@ uint64_t helper_cmpglt(uint64_t a, uint64_t b)
         return 0;
 }
 
-uint64_t helper_cmpfeq (uint64_t a)
-{
-    return !(a & 0x7FFFFFFFFFFFFFFFULL);
-}
-
-uint64_t helper_cmpfne (uint64_t a)
-{
-    return (a & 0x7FFFFFFFFFFFFFFFULL);
-}
-
-uint64_t helper_cmpflt (uint64_t a)
-{
-    return (a & 0x8000000000000000ULL) && (a & 0x7FFFFFFFFFFFFFFFULL);
-}
-
-uint64_t helper_cmpfle (uint64_t a)
-{
-    return (a & 0x8000000000000000ULL) || !(a & 0x7FFFFFFFFFFFFFFFULL);
-}
-
-uint64_t helper_cmpfgt (uint64_t a)
-{
-    return !(a & 0x8000000000000000ULL) && (a & 0x7FFFFFFFFFFFFFFFULL);
-}
-
-uint64_t helper_cmpfge (uint64_t a)
-{
-    return !(a & 0x8000000000000000ULL) || !(a & 0x7FFFFFFFFFFFFFFFULL);
-}
-
-
 /* Floating point format conversion */
 uint64_t helper_cvtts (uint64_t a)
 {
target-alpha/translate.c +111 -88

277 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#3 lore raw

PATCH 3/5 target-alpha: Fix generic ctz64.

In reply to Richard Henderson
---
 host-utils.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
host-utils.h +1 -1
index e335c5c..0ddc176 100644
@@ -164,7 +164,7 @@ static inline int ctz64(uint64_t val)
 {
 #if QEMU_GNUC_PREREQ(3, 4)
     if (val)
-        return __builtin_ctz(val);
+        return __builtin_ctzll(val);
     else
         return 64;
 #else
Signature · 1 line
1.6.5.2
#0 lore raw

cover Alpha improvments, round 3

The first is the IMB patch, adjusted for Aurelien's comments.

The third is a bug in a generic header; I'm not sure what the proper tagging is for that sort of thing.

The rest are new bugs found in the Alpha backend via the gcc testsuite. We're down to a handfull of failures over native there. I hope to post an approach to the rounding mode issue shortly.

r~

Richard Henderson (5):
target-alpha: Add placeholders for missing userspace PALcalls.
target-alpha: Implement fp branch/cmov inline.
target-alpha: Fix generic ctz64.
target-alpha: Fix cvtlq.
target-alpha: Fix float32_to_s vs zero exponent.

 host-utils.h             |    2 +-
 hw/alpha_palcode.c       |   32 +++++++-
 target-alpha/helper.h    |    7 --
 target-alpha/op_helper.c |   79 ++++++++----------
 target-alpha/translate.c |  197 ++++++++++++++++++++++++++--------------------
 5 files changed, 176 insertions(+), 141 deletions(-)
#1 lore raw

PATCH 1/5 target-alpha: Add placeholders for missing userspace PALcalls.

---
 hw/alpha_palcode.c |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)
hw/alpha_palcode.c +30 -2
index edec018..2a694dc 100644
@@ -1061,6 +1061,16 @@ void call_pal (CPUState *env, int palcode)
     target_long ret;
 
     switch (palcode) {
+    case 0x80:
+        /* BPT */
+        qemu_log("BPT\n");
+        /* FIXME: Sends SIGTRAP, si_code=TRAP_BRKPT.  */
+        exit(1);
+    case 0x81:
+        /* BUGCHK */
+        qemu_log("BUGCHK\n");
+        /* FIXME: Sends SIGTRAP, si_code=SI_FAULT.  */
+        exit(1);
     case 0x83:
         /* CALLSYS */
         qemu_log("CALLSYS n " TARGET_FMT_ld "\n", env->ir[0]);
@@ -1075,6 +1085,14 @@ void call_pal (CPUState *env, int palcode)
             env->ir[IR_V0] = -ret;
         }
         break;
+    case 0x86:
+        /* IMB */
+        qemu_log("IMB\n");
+	/* ??? We can probably elide the code using page_unprotect that is
+	   checking for self-modifying code.  Instead we could simply call
+	   tb_flush here.  Until we work out the changes required to turn
+	   off the extra write protection, this can be a no-op.  */
+        break;
     case 0x9E:
         /* RDUNIQUE */
         qemu_log("RDUNIQUE: " TARGET_FMT_lx "\n", env->unique);
@@ -1085,9 +1103,19 @@ void call_pal (CPUState *env, int palcode)
         qemu_log("WRUNIQUE: " TARGET_FMT_lx "\n", env->ir[IR_A0]);
         /* Handled in the translator for usermode.  */
         abort();
+    case 0xAA:
+        /* GENTRAP */
+        qemu_log("GENTRAP: " TARGET_FMT_lx "\n", env->ir[IR_A0]);
+        /* FIXME: This is supposed to send a signal:
+           SIGFPE:
+             GEN_INTOVF, GEN_INTDIV, GEN_FLTOVF, GEN_FLTDIV,
+             GEN_FLTUND, GEN_FLTINV, GEN_FLTINE, GEN_ROPRAND
+           SIGTRAP:
+             others
+           with various settings of si_code.  */
+        exit(1);
     default:
-        qemu_log("%s: unhandled palcode %02x\n",
-                    __func__, palcode);
+        qemu_log("%s: unhandled palcode %02x\n", __func__, palcode);
         exit(1);
     }
 }
Signature · 1 line
1.6.5.2
#4 lore raw

PATCH 4/5 target-alpha: Fix cvtlq.

In reply to Richard Henderson

We were missing the 0xc0000000 mask, leading to incorrect results.

---
 target-alpha/op_helper.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
target-alpha/op_helper.c +3 -1
index 8eba5ec..ff120ad 100644
@@ -954,7 +954,9 @@ uint64_t helper_cvtqg (uint64_t a)
 
 uint64_t helper_cvtlq (uint64_t a)
 {
-    return (int64_t)((int32_t)((a >> 32) | ((a >> 29) & 0x3FFFFFFF)));
+    int32_t lo = a >> 29;
+    int32_t hi = a >> 32;
+    return (lo & 0x3FFFFFFF) | (hi & 0xc0000000);
 }
 
 static inline uint64_t __helper_cvtql(uint64_t a, int s, int v)
Signature · 1 line
1.6.5.2
#5 lore raw

PATCH 5/5 target-alpha: Fix float32_to_s vs zero exponent.

In reply to Richard Henderson

There was a bug in float32_to_s that incorrectly mapped a zero exponent to 0x38. This meant 0.0f != 0. At the same time, fix a generic type punning bug in helper_memory_to_s and helper_s_to_memory.

---
 target-alpha/op_helper.c |   44 ++++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)
target-alpha/op_helper.c +32 -12
index ff120ad..b2abf6c 100644
@@ -625,37 +625,57 @@ uint64_t helper_sqrtg (uint64_t a)
 
 
 /* S floating (single) */
+
+/* Taken from linux/arch/alpha/kernel/traps.c, s_mem_to_reg.  */
+static inline uint64_t float32_to_s_int(uint32_t fi)
+{
+    uint32_t frac = fi & 0x7fffff;
+    uint32_t sign = fi >> 31;
+    uint32_t exp_msb = (fi >> 30) & 1;
+    uint32_t exp_low = (fi >> 23) & 0x7f;
+    uint32_t exp;
+
+    exp = (exp_msb << 10) | exp_low;
+    if (exp_msb) {
+        if (exp_low == 0x7f)
+            exp = 0x7ff;
+    } else {
+        if (exp_low != 0x00)
+            exp |= 0x380;
+    }
+
+    return (((uint64_t)sign << 63)
+            | ((uint64_t)exp << 52)
+            | ((uint64_t)frac << 29));
+}
+
 static inline uint64_t float32_to_s(float32 fa)
 {
     CPU_FloatU a;
-    uint64_t r;
-
     a.f = fa;
+    return float32_to_s_int(a.l);
+}
 
-    r = (((uint64_t)(a.l & 0xc0000000)) << 32) | (((uint64_t)(a.l & 0x3fffffff)) << 29);
-    if (((a.l & 0x7f800000) != 0x7f800000) && (!(a.l & 0x40000000)))
-        r |= 0x7ll << 59;
-    return r;
+static inline uint32_t s_to_float32_int(uint64_t a)
+{
+    return ((a >> 32) & 0xc0000000) | ((a >> 29) & 0x3fffffff);
 }
 
 static inline float32 s_to_float32(uint64_t a)
 {
     CPU_FloatU r;
-    r.l = ((a >> 32) & 0xc0000000) | ((a >> 29) & 0x3fffffff);
+    r.l = s_to_float32_int(a);
     return r.f;
 }
 
 uint32_t helper_s_to_memory (uint64_t a)
 {
-    /* Memory format is the same as float32 */
-    float32 fa = s_to_float32(a);
-    return *(uint32_t*)(&fa);
+    return s_to_float32_int(a);
 }
 
 uint64_t helper_memory_to_s (uint32_t a)
 {
-    /* Memory format is the same as float32 */
-    return float32_to_s(*(float32*)(&a));
+    return float32_to_s_int(a);
 }
 
 uint64_t helper_adds (uint64_t a, uint64_t b)
Signature · 1 line
1.6.5.2