Skip to contentSkip to conversation

SPARC64: Implement sparcv9 ldfa/stfa instructions

PATCH Applied Tsuneo Saito 4 participants 15 messages Jul 14, 2011

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/8 SPARC64: Implement ldfa/lddfa/ldqfa instructions properly

In reply to Tsuneo Saito

This patch implements sparcv9 ldfa/lddfa/ldqfa instructions with non block-load ASIs.

---
 target-sparc/op_helper.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
target-sparc/op_helper.c +11 -5
index fd0cfbd..a75ac4f 100644
@@ -3331,7 +3331,7 @@ void helper_ldda_asi(target_ulong addr, int asi, int rd)
 void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
 {
     unsigned int i;
-    target_ulong val;
+    CPU_DoubleU u;
 
     helper_check_align(addr, 3);
     addr = asi_address_mask(env, asi, addr);
@@ -3371,17 +3371,23 @@ void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
         break;
     }
 
-    val = helper_ld_asi(addr, asi, size, 0);
     switch(size) {
     default:
     case 4:
-        *((uint32_t *)&env->fpr[rd]) = val;
+        *((uint32_t *)&env->fpr[rd]) = helper_ld_asi(addr, asi, size, 0);
         break;
     case 8:
-        *((int64_t *)&DT0) = val;
+        u.ll = helper_ld_asi(addr, asi, size, 0);
+        *((uint32_t *)&env->fpr[rd++]) = u.l.upper;
+        *((uint32_t *)&env->fpr[rd++]) = u.l.lower;
         break;
     case 16:
-        // XXX
+        u.ll = helper_ld_asi(addr, asi, 8, 0);
+        *((uint32_t *)&env->fpr[rd++]) = u.l.upper;
+        *((uint32_t *)&env->fpr[rd++]) = u.l.lower;
+        u.ll = helper_ld_asi(addr + 8, asi, 8, 0);
+        *((uint32_t *)&env->fpr[rd++]) = u.l.upper;
+        *((uint32_t *)&env->fpr[rd++]) = u.l.lower;
         break;
     }
 }
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH v2 2/8 SPARC64: fp_disabled checks on ldfa/lddfa/ldqfa

In reply to Tsuneo Saito

ldfa/lddfa/ldqfa instructions should raise fp_disabled exceptions if %pstate.PEF==0 or %fprs.FEF==0.

---
 target-sparc/translate.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
target-sparc/translate.c +9 -0
index f32a674..1e7e68d 100644
@@ -4484,10 +4484,16 @@ static void disas_sparc_insn(DisasContext * dc)
                 case 0x2d: /* V9 prefetch, no effect */
                     goto skip_move;
                 case 0x30: /* V9 ldfa */
+                    if (gen_trap_ifnofpu(dc, cpu_cond)) {
+                        goto jmp_insn;
+                    }
                     save_state(dc, cpu_cond);
                     gen_ldf_asi(cpu_addr, insn, 4, rd);
                     goto skip_move;
                 case 0x33: /* V9 lddfa */
+                    if (gen_trap_ifnofpu(dc, cpu_cond)) {
+                        goto jmp_insn;
+                    }
                     save_state(dc, cpu_cond);
                     gen_ldf_asi(cpu_addr, insn, 8, DFPREG(rd));
                     goto skip_move;
@@ -4495,6 +4501,9 @@ static void disas_sparc_insn(DisasContext * dc)
                     goto skip_move;
                 case 0x32: /* V9 ldqfa */
                     CHECK_FPU_FEATURE(dc, FLOAT128);
+                    if (gen_trap_ifnofpu(dc, cpu_cond)) {
+                        goto jmp_insn;
+                    }
                     save_state(dc, cpu_cond);
                     gen_ldf_asi(cpu_addr, insn, 16, QFPREG(rd));
                     goto skip_move;
Signature · 1 line
1.7.5.4
#0 lore raw

v2 cover SPARC64: Implement sparcv9 ldfa/stfa instructions

This patch series implements sparcv9 stfa/ldfa instructions that implementations seem to be left unfinished.
This patch also adds fp_disabled exception checks on stfa/ldfa as they are FP instructions.

v2:
* checked by checkpatch.pl.
* added UA2007 block-transfer ASIs.
* added JPS1 little-endian block-transfer ASIs that seem forgotten.

 target-sparc/op_helper.c |   75 ++++++++++++++++++++++++++++++---------------
 target-sparc/translate.c |   20 +++++++++++-
 2 files changed, 68 insertions(+), 27 deletions(-)
Signature · 1 line
1.7.5.4
#3 lore raw

PATCH v2 3/8 SPARC64: Implement stfa/stdfa/stqfa instrcutions properly

This patch implements sparcv9 stfa/stdfa/stqfa instructions with non block-store ASIs.

---
 target-sparc/op_helper.c |   15 +++++++++++----
 target-sparc/translate.c |    2 --
 2 files changed, 11 insertions(+), 6 deletions(-)
target-sparc/op_helper.c +11 -4
index a75ac4f..fe71829 100644
@@ -3396,6 +3396,7 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
 {
     unsigned int i;
     target_ulong val = 0;
+    CPU_DoubleU u;
 
     helper_check_align(addr, 3);
     addr = asi_address_mask(env, asi, addr);
@@ -3440,16 +3441,22 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
     switch(size) {
     default:
     case 4:
-        val = *((uint32_t *)&env->fpr[rd]);
+        helper_st_asi(addr, *(uint32_t *)&env->fpr[rd], asi, size);
         break;
     case 8:
-        val = *((int64_t *)&DT0);
+        u.l.upper = *(uint32_t *)&env->fpr[rd++];
+        u.l.lower = *(uint32_t *)&env->fpr[rd++];
+        helper_st_asi(addr, u.ll, asi, size);
         break;
     case 16:
-        // XXX
+        u.l.upper = *(uint32_t *)&env->fpr[rd++];
+        u.l.lower = *(uint32_t *)&env->fpr[rd++];
+        helper_st_asi(addr, u.ll, asi, 8);
+        u.l.upper = *(uint32_t *)&env->fpr[rd++];
+        u.l.lower = *(uint32_t *)&env->fpr[rd++];
+        helper_st_asi(addr + 8, u.ll, asi, 8);
         break;
     }
-    helper_st_asi(addr, val, asi, size);
 }
 
 target_ulong helper_cas_asi(target_ulong addr, target_ulong val1,
target-sparc/translate.c +0 -2
index 1e7e68d..a5a8eaf 100644
@@ -4742,12 +4742,10 @@ static void disas_sparc_insn(DisasContext * dc)
                         r_const = tcg_const_i32(7);
                         gen_helper_check_align(cpu_addr, r_const);
                         tcg_temp_free_i32(r_const);
-                        gen_op_load_fpr_QT0(QFPREG(rd));
                         gen_stf_asi(cpu_addr, insn, 16, QFPREG(rd));
                     }
                     break;
                 case 0x37: /* V9 stdfa */
-                    gen_op_load_fpr_DT0(DFPREG(rd));
                     gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
                     break;
                 case 0x3c: /* V9 casa */
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH v2 4/8 SPARC64: fp_disabled checks on stfa/stdfa/stqfa

In reply to Tsuneo Saito

stfa/stdfa/stqfa instructions should raise fp_disabled exceptions if %pstate.PEF==0 or %fprs.FEF==0.

---
 target-sparc/translate.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
target-sparc/translate.c +9 -0
index a5a8eaf..5f92dbb 100644
@@ -4732,6 +4732,9 @@ static void disas_sparc_insn(DisasContext * dc)
                 switch (xop) {
 #ifdef TARGET_SPARC64
                 case 0x34: /* V9 stfa */
+                    if (gen_trap_ifnofpu(dc, cpu_cond)) {
+                        goto jmp_insn;
+                    }
                     gen_stf_asi(cpu_addr, insn, 4, rd);
                     break;
                 case 0x36: /* V9 stqfa */
@@ -4739,6 +4742,9 @@ static void disas_sparc_insn(DisasContext * dc)
                         TCGv_i32 r_const;
 
                         CHECK_FPU_FEATURE(dc, FLOAT128);
+                        if (gen_trap_ifnofpu(dc, cpu_cond)) {
+                            goto jmp_insn;
+                        }
                         r_const = tcg_const_i32(7);
                         gen_helper_check_align(cpu_addr, r_const);
                         tcg_temp_free_i32(r_const);
@@ -4746,6 +4752,9 @@ static void disas_sparc_insn(DisasContext * dc)
                     }
                     break;
                 case 0x37: /* V9 stdfa */
+                    if (gen_trap_ifnofpu(dc, cpu_cond)) {
+                        goto jmp_insn;
+                    }
                     gen_stf_asi(cpu_addr, insn, 8, DFPREG(rd));
                     break;
                 case 0x3c: /* V9 casa */
Signature · 1 line
1.7.5.4
#9 lore raw

PATCH v2 6/8 SPARC64: Add UA2007 ASI_BLK_AIU[PS]L? ASIs for stfa

In reply to Tsuneo Saito

Support UA2007 block store ASIs for stfa instructions.

---
 target-sparc/op_helper.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
target-sparc/op_helper.c +5 -1
index b76ffb6..4faa709 100644
@@ -3424,6 +3424,10 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
         }
 
         return;
+    case 0x16: /* UA2007 Block load primary, user privilege */
+    case 0x17: /* UA2007 Block load secondary, user privilege */
+    case 0x1e: /* UA2007 Block load primary LE, user privilege */
+    case 0x1f: /* UA2007 Block load secondary LE, user privilege */
     case 0x70: // Block store primary, user privilege
     case 0x71: // Block store secondary, user privilege
         if (rd & 7) {
@@ -3433,7 +3437,7 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
         helper_check_align(addr, 0x3f);
         for (i = 0; i < 16; i++) {
             val = *(uint32_t *)&env->fpr[rd++];
-            helper_st_asi(addr, val, asi & 0x1f, 4);
+            helper_st_asi(addr, val, asi & 0x19, 4);
             addr += 4;
         }
 
Signature · 1 line
1.7.5.4
#8 lore raw

PATCH v2 5/8 SPARC64: Add UA2007 ASI_BLK_AIU[PS]L? ASIs for ldfa

In reply to Tsuneo Saito

Support UA2007 block load ASIs for ldfa instructions.

---
 target-sparc/op_helper.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
target-sparc/op_helper.c +5 -1
index fe71829..b76ffb6 100644
@@ -3353,6 +3353,10 @@ void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
         }
 
         return;
+    case 0x16: /* UA2007 Block load primary, user privilege */
+    case 0x17: /* UA2007 Block load secondary, user privilege */
+    case 0x1e: /* UA2007 Block load primary LE, user privilege */
+    case 0x1f: /* UA2007 Block load secondary LE, user privilege */
     case 0x70: // Block load primary, user privilege
     case 0x71: // Block load secondary, user privilege
         if (rd & 7) {
@@ -3361,7 +3365,7 @@ void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
         }
         helper_check_align(addr, 0x3f);
         for (i = 0; i < 16; i++) {
-            *(uint32_t *)&env->fpr[rd++] = helper_ld_asi(addr, asi & 0x1f, 4,
+            *(uint32_t *)&env->fpr[rd++] = helper_ld_asi(addr, asi & 0x19, 4,
                                                          0);
             addr += 4;
         }
Signature · 1 line
1.7.5.4
#12 lore raw

PATCH v2 7/8 SPARC64: Add JPS1 ASI_BLK_AIU[PS]L ASIs for ldfa and stfa

In reply to Tsuneo Saito

Support JPS1 little endian block transfer ASIs.

---
 target-sparc/op_helper.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
target-sparc/op_helper.c +4 -0
index 4faa709..2a28d5f 100644
@@ -3359,6 +3359,8 @@ void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
     case 0x1f: /* UA2007 Block load secondary LE, user privilege */
     case 0x70: // Block load primary, user privilege
     case 0x71: // Block load secondary, user privilege
+    case 0x78: /* JPS1 Block load primary LE, user privilege */
+    case 0x79: /* JPS1 Block load secondary LE, user privilege */
         if (rd & 7) {
             raise_exception(TT_ILL_INSN);
             return;
@@ -3430,6 +3432,8 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
     case 0x1f: /* UA2007 Block load secondary LE, user privilege */
     case 0x70: // Block store primary, user privilege
     case 0x71: // Block store secondary, user privilege
+    case 0x78: /* JPS1 Block load primary LE, user privilege */
+    case 0x79: /* JPS1 Block load secondary LE, user privilege */
         if (rd & 7) {
             raise_exception(TT_ILL_INSN);
             return;
Signature · 1 line
1.7.5.4
#13 lore raw

PATCH v2 8/8 SPARC64: C99 comment fix for block-transfer ASIs

In reply to Tsuneo Saito

Fixed C99 comments on block-tranfer ASIs.

---
 target-sparc/op_helper.c |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)
target-sparc/op_helper.c +14 -14
index 2a28d5f..15af27b 100644
@@ -3337,10 +3337,10 @@ void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
     addr = asi_address_mask(env, asi, addr);
 
     switch (asi) {
-    case 0xf0: // Block load primary
-    case 0xf1: // Block load secondary
-    case 0xf8: // Block load primary LE
-    case 0xf9: // Block load secondary LE
+    case 0xf0: /* UA2007/JPS1 Block load primary */
+    case 0xf1: /* UA2007/JPS1 Block load secondary */
+    case 0xf8: /* UA2007/JPS1 Block load primary LE */
+    case 0xf9: /* UA2007/JPS1 Block load secondary LE */
         if (rd & 7) {
             raise_exception(TT_ILL_INSN);
             return;
@@ -3357,8 +3357,8 @@ void helper_ldf_asi(target_ulong addr, int asi, int size, int rd)
     case 0x17: /* UA2007 Block load secondary, user privilege */
     case 0x1e: /* UA2007 Block load primary LE, user privilege */
     case 0x1f: /* UA2007 Block load secondary LE, user privilege */
-    case 0x70: // Block load primary, user privilege
-    case 0x71: // Block load secondary, user privilege
+    case 0x70: /* JPS1 Block load primary, user privilege */
+    case 0x71: /* JPS1 Block load secondary, user privilege */
     case 0x78: /* JPS1 Block load primary LE, user privilege */
     case 0x79: /* JPS1 Block load secondary LE, user privilege */
         if (rd & 7) {
@@ -3408,12 +3408,12 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
     addr = asi_address_mask(env, asi, addr);
 
     switch (asi) {
-    case 0xe0: // UA2007 Block commit store primary (cache flush)
-    case 0xe1: // UA2007 Block commit store secondary (cache flush)
-    case 0xf0: // Block store primary
-    case 0xf1: // Block store secondary
-    case 0xf8: // Block store primary LE
-    case 0xf9: // Block store secondary LE
+    case 0xe0: /* UA2007/JPS1 Block commit store primary (cache flush) */
+    case 0xe1: /* UA2007/JPS1 Block commit store secondary (cache flush) */
+    case 0xf0: /* UA2007/JPS1 Block store primary */
+    case 0xf1: /* UA2007/JPS1 Block store secondary */
+    case 0xf8: /* UA2007/JPS1 Block store primary LE */
+    case 0xf9: /* UA2007/JPS1 Block store secondary LE */
         if (rd & 7) {
             raise_exception(TT_ILL_INSN);
             return;
@@ -3430,8 +3430,8 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
     case 0x17: /* UA2007 Block load secondary, user privilege */
     case 0x1e: /* UA2007 Block load primary LE, user privilege */
     case 0x1f: /* UA2007 Block load secondary LE, user privilege */
-    case 0x70: // Block store primary, user privilege
-    case 0x71: // Block store secondary, user privilege
+    case 0x70: /* JPS1 Block store primary, user privilege */
+    case 0x71: /* JPS1 Block store secondary, user privilege */
     case 0x78: /* JPS1 Block load primary LE, user privilege */
     case 0x79: /* JPS1 Block load secondary LE, user privilege */
         if (rd & 7) {
Signature · 1 line
1.7.5.4
#5 lore raw

Re: [Qemu-devel] [PATCH v2 4/8] SPARC64: fp_disabled checks on stfa/stdfa/stqfa

In reply to Tsuneo Saito
Quoted 2 lines · Tsuneo Saito

stfa/stdfa/stqfa instructions should raise fp_disabled exceptions if %pstate.PEF==0 or %fprs.FEF==0.

Not really related to this patch but I happened to notice it:
we generate a trap if dc->fpu_enabled is clear. That flag is set with:

        dc->fpu_enabled = cpu_fpu_enabled(env);

which looks at the CPUState passed into gen_intermediate_code_internal.

I think it should be pulling the fpu-enabled state out of the tb->flags instead. Otherwise you'll have problems if you have a TB with (1) a trap-if-no-fpu insn (2) a change of the fpu-enabled state (3) a load/store that faults.

-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH v2 4/8] SPARC64: fp_disabled checks on stfa/stdfa/stqfa

Quoted 9 lines · Peter Maydell
Quoted 2 lines · Tsuneo Saito

stfa/stdfa/stqfa instructions should raise fp_disabled exceptions if %pstate.PEF==0 or %fprs.FEF==0.

Not really related to this patch but I happened to notice it:
we generate a trap if dc->fpu_enabled is clear. That flag is set with:
       dc->fpu_enabled = cpu_fpu_enabled(env);
which looks at the CPUState passed into gen_intermediate_code_internal.

Quoted 4 lines

I think it should be pulling the fpu-enabled state out of the tb->flags instead. Otherwise you'll have problems if you have a TB with (1) a trap-if-no-fpu insn (2) a change of the fpu-enabled state (3) a load/store that faults.

Nice catch, this also affects Sparc32.

Applied
#14 lore raw
In reply to Tsuneo Saito

Thanks, applied all.

Quoted 19 lines · Tsuneo Saito

This patch series implements sparcv9 stfa/ldfa instructions that implementations seem to be left unfinished.
This patch also adds fp_disabled exception checks on stfa/ldfa as they are FP instructions.

v2:
 * checked by checkpatch.pl.
 * added UA2007 block-transfer ASIs.
 * added JPS1 little-endian block-transfer ASIs that seem forgotten.

 target-sparc/op_helper.c |   75 ++++++++++++++++++++++++++++++--------------- target-sparc/translate.c |   20 +++++++++++-

 2 files changed, 68 insertions(+), 27 deletions(-)

--
1.7.5.4

#7 lore raw

Re: [Qemu-devel] [PATCH v2 4/8] SPARC64: fp_disabled checks on stfa/stdfa/stqfa

In reply to Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 2 lines · Tsuneo Saito

stfa/stdfa/stqfa instructions should raise fp_disabled exceptions if %pstate.PEF==0 or %fprs.FEF==0.

Not really related to this patch but I happened to notice it:
we generate a trap if dc->fpu_enabled is clear. That flag is set with:
       dc->fpu_enabled = cpu_fpu_enabled(env);
which looks at the CPUState passed into gen_intermediate_code_internal.

Quoted 4 lines

I think it should be pulling the fpu-enabled state out of the tb->flags instead. Otherwise you'll have problems if you have a TB with (1) a trap-if-no-fpu insn (2) a change of the fpu-enabled state (3) a load/store that faults.

I applied a patch to fix this and similar bug with AM bit.

#10 lore raw

Re: [Qemu-devel] [PATCH v2 6/8] SPARC64: Add UA2007 ASI_BLK_AIU[PS]L? ASIs for stfa

In reply to Tsuneo Saito
Quoted 12 lines · Tsuneo Saito

Support UA2007 block store ASIs for stfa instructions.

---
 target-sparc/op_helper.c |    6 +++++-

 1 files changed, 5 insertions(+), 1 deletions(-)
target-sparc/op_helper.c +0 -0
index b76ffb6..4faa709 100644

target-sparc/op_helper.c void helper_stf_asi(target_ulong addr, int asi, int size, int rd) · line 3430

Quoted 7 lines
target-sparc/op_helper.c +4 -0
@@ -3424,6 +3424,10 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
         }
 
         return;
+    case 0x16: /* UA2007 Block load primary, user privilege */
+    case 0x17: /* UA2007 Block load secondary, user privilege */
+    case 0x1e: /* UA2007 Block load primary LE, user privilege */
+    case 0x1f: /* UA2007 Block load secondary LE, user privilege */

shouldn't these be added to the list in is_translating_asi() ?

Quoted 17 lines

    case 0x70: // Block store primary, user privilege case 0x71: // Block store secondary, user privilege if (rd & 7) {

target-sparc/op_helper.c +1 -2
@@ -3433,7 +3437,7 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
         helper_check_align(addr, 0x3f);
         for (i = 0; i < 16; i++) {
             val = *(uint32_t *)&env->fpr[rd++];
-            helper_st_asi(addr, val, asi & 0x1f, 4);
+            helper_st_asi(addr, val, asi & 0x19, 4);
             addr += 4;
         }
 
--

1.7.5.4

Signature · 4 lines
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/
#11 lore raw

Re: [Qemu-devel] [PATCH v2 6/8] SPARC64: Add UA2007 ASI_BLK_AIU[PS]L? ASIs for stfa

At Thu, 14 Jul 2011 22:46:30 +0200,

Quoted 15 lines · Artyom Tarasenko
Quoted 14 lines · Tsuneo Saito

Support UA2007 block store ASIs for stfa instructions.

---
 target-sparc/op_helper.c |    6 +++++-

 1 files changed, 5 insertions(+), 1 deletions(-)
target-sparc/op_helper.c +0 -0
index b76ffb6..4faa709 100644
@@ -3424,6 +3424,10 @@ void helper_stf_asi(target_ulong addr, int asi, int size, int rd)
         }
 
Quoted 7 lines

target-sparc/op_helper.c void helper_stf_asi(target_ulong addr, int asi, int size, int rd) · line 3430

Quoted 5 lines
target-sparc/op_helper.c +4 -0
         return;
+    case 0x16: /* UA2007 Block load primary, user privilege */
+    case 0x17: /* UA2007 Block load secondary, user privilege */
+    case 0x1e: /* UA2007 Block load primary LE, user privilege */
+    case 0x1f: /* UA2007 Block load secondary LE, user privilege */

shouldn't these be added to the list in is_translating_asi() ?

Ah yes, that's right!

----
Tsuneo Saito <[email protected]>