[v2,15/24] target-sparc: Directly implement easy ldd/std asis
diff mbox

Message ID 1456261920-29900-16-git-send-email-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson Feb. 23, 2016, 9:11 p.m. UTC
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 target-sparc/translate.c | 111 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 98 insertions(+), 13 deletions(-)

Patch
diff mbox

diff --git a/target-sparc/translate.c b/target-sparc/translate.c
index 008b07b..5fd096f 100644
--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -1976,6 +1976,7 @@  typedef enum {
     GET_ASI_HELPER,
     GET_ASI_EXCP,
     GET_ASI_DIRECT,
+    GET_ASI_DTWINX,
 } ASIType;
 
 typedef struct {
@@ -2034,18 +2035,26 @@  static DisasASI get_asi(DisasContext *dc, int insn, TCGMemOp memop)
         switch (asi) {
         case ASI_N:  /* Nucleus */
         case ASI_NL: /* Nucleus LE */
+        case ASI_TWINX_N:
+        case ASI_TWINX_NL:
             mem_idx = MMU_NUCLEUS_IDX;
             break;
         case ASI_AIUP:  /* As if user primary */
         case ASI_AIUPL: /* As if user primary LE */
+        case ASI_TWINX_AIUP:
+        case ASI_TWINX_AIUP_L:
             mem_idx = MMU_USER_IDX;
             break;
         case ASI_AIUS:  /* As if user secondary */
         case ASI_AIUSL: /* As if user secondary LE */
+        case ASI_TWINX_AIUS:
+        case ASI_TWINX_AIUS_L:
             mem_idx = MMU_USER_SECONDARY_IDX;
             break;
         case ASI_S:  /* Secondary */
         case ASI_SL: /* Secondary LE */
+        case ASI_TWINX_S:
+        case ASI_TWINX_SL:
             if (mem_idx == MMU_USER_IDX) {
                 mem_idx = MMU_USER_SECONDARY_IDX;
             } else if (mem_idx == MMU_KERNEL_IDX) {
@@ -2054,6 +2063,8 @@  static DisasASI get_asi(DisasContext *dc, int insn, TCGMemOp memop)
             break;
         case ASI_P:  /* Primary */
         case ASI_PL: /* Primary LE */
+        case ASI_TWINX_P:
+        case ASI_TWINX_PL:
             break;
         }
         switch (asi) {
@@ -2069,6 +2080,18 @@  static DisasASI get_asi(DisasContext *dc, int insn, TCGMemOp memop)
         case ASI_PL:
             type = GET_ASI_DIRECT;
             break;
+        case ASI_TWINX_N:
+        case ASI_TWINX_NL:
+        case ASI_TWINX_AIUP:
+        case ASI_TWINX_AIUP_L:
+        case ASI_TWINX_AIUS:
+        case ASI_TWINX_AIUS_L:
+        case ASI_TWINX_P:
+        case ASI_TWINX_PL:
+        case ASI_TWINX_S:
+        case ASI_TWINX_SL:
+            type = GET_ASI_DTWINX;
+            break;
         }
         /* The little-endian asis all have bit 3 set.  */
         if (asi & 8) {
@@ -2088,6 +2111,9 @@  static void gen_ld_asi(DisasContext *dc, TCGv dst, TCGv addr,
     switch (da.type) {
     case GET_ASI_EXCP:
         break;
+    case GET_ASI_DTWINX: /* Reserved for ldda.  */
+        gen_exception(dc, TT_ILL_INSN);
+        break;
     case GET_ASI_DIRECT:
         tcg_gen_qemu_ld_tl(dst, addr, da.mem_idx, da.memop);
         break;
@@ -2124,6 +2150,9 @@  static void gen_st_asi(DisasContext *dc, TCGv src, TCGv addr,
     switch (da.type) {
     case GET_ASI_EXCP:
         break;
+    case GET_ASI_DTWINX: /* Reserved for stda.  */
+        gen_exception(dc, TT_ILL_INSN);
+        break;
     case GET_ASI_DIRECT:
         tcg_gen_qemu_st_tl(src, addr, da.mem_idx, da.memop);
         break;
@@ -2289,32 +2318,57 @@  static void gen_stf_asi(DisasContext *dc, TCGv addr,
     }
 }
 
-static void gen_ldda_asi(DisasContext *dc, TCGv hi, TCGv addr,
-                         int insn, int rd)
+static void gen_ldda_asi(DisasContext *dc, TCGv addr, int insn, int rd)
 {
     DisasASI da = get_asi(dc, insn, MO_TEQ);
+    TCGv_i64 hi = gen_dest_gpr(dc, rd);
+    TCGv_i64 lo = gen_dest_gpr(dc, rd + 1);
 
     switch (da.type) {
     case GET_ASI_EXCP:
+        return;
+
+    case GET_ASI_DTWINX:
+        gen_check_align(addr, 15);
+        tcg_gen_qemu_ld_i64(hi, addr, da.mem_idx, da.memop);
+        tcg_gen_addi_tl(addr, addr, 8);
+        tcg_gen_qemu_ld_i64(lo, addr, da.mem_idx, da.memop);
         break;
+
+    case GET_ASI_DIRECT:
+        {
+            TCGv_i64 tmp = tcg_temp_new_i64();
+
+            tcg_gen_qemu_ld_i64(tmp, addr, da.mem_idx, da.memop);
+
+            /* Note that LE ldda acts as if each 32-bit register
+               result is byte swapped.  Having just performed one
+               64-bit bswap, we need now to swap the writebacks.  */
+            if ((da.memop & MO_BSWAP) == MO_TE) {
+                tcg_gen_extr32_i64(lo, hi, tmp);
+            } else {
+                tcg_gen_extr32_i64(hi, lo, tmp);
+            }
+            tcg_temp_free_i64(tmp);
+        }
+        break;
+
     default:
         {
             TCGv_i32 r_asi = tcg_const_i32(da.asi);
-            TCGv_i64 tmp;
 
             save_state(dc);
             gen_helper_ldda_asi(cpu_env, addr, r_asi);
             tcg_temp_free_i32(r_asi);
 
-            tmp = gen_dest_gpr(dc, rd);
-            tcg_gen_ld_i64(tmp, cpu_env, offsetof(CPUSPARCState, qt0.high));
-            gen_store_gpr(dc, rd, tmp);
-            tmp = gen_dest_gpr(dc, rd + 1);
-            tcg_gen_ld_i64(tmp, cpu_env, offsetof(CPUSPARCState, qt0.low));
-            gen_store_gpr(dc, rd + 1, tmp);
+            tcg_gen_ld_i64(hi, cpu_env, offsetof(CPUSPARCState, qt0.high));
+            tcg_gen_ld_i64(lo, cpu_env, offsetof(CPUSPARCState, qt0.low));
         }
         break;
     }
+
+    gen_store_gpr(dc, rd, hi);
+    gen_store_gpr(dc, rd + 1, lo);
 }
 
 static void gen_stda_asi(DisasContext *dc, TCGv hi, TCGv addr,
@@ -2326,6 +2380,31 @@  static void gen_stda_asi(DisasContext *dc, TCGv hi, TCGv addr,
     switch (da.type) {
     case GET_ASI_EXCP:
         break;
+
+    case GET_ASI_DTWINX:
+        gen_check_align(addr, 15);
+        tcg_gen_qemu_st_i64(hi, addr, da.mem_idx, da.memop);
+        tcg_gen_addi_tl(addr, addr, 8);
+        tcg_gen_qemu_st_i64(lo, addr, da.mem_idx, da.memop);
+        break;
+
+    case GET_ASI_DIRECT:
+        {
+            TCGv_i64 t64 = tcg_temp_new_i64();
+
+            /* Note that LE stda acts as if each 32-bit register result is
+               byte swapped.  We will perform one 64-bit LE store, so now
+               we must swap the order of the construction.  */
+            if ((da.memop & MO_BSWAP) == MO_TE) {
+                tcg_gen_concat32_i64(t64, lo, hi);
+            } else {
+                tcg_gen_concat32_i64(t64, hi, lo);
+            }
+            tcg_gen_qemu_st_i64(t64, addr, da.mem_idx, da.memop);
+            tcg_temp_free_i64(t64);
+        }
+        break;
+
     default:
         {
             TCGv_i32 r_asi = tcg_const_i32(da.asi);
@@ -2365,17 +2444,19 @@  static void gen_casx_asi(DisasContext *dc, TCGv addr, TCGv val2,
 }
 
 #elif !defined(CONFIG_USER_ONLY)
-static void gen_ldda_asi(DisasContext *dc, TCGv hi, TCGv addr,
-                         int insn, int rd)
+static void gen_ldda_asi(DisasContext *dc, TCGv addr, int insn, int rd)
 {
     DisasASI da = get_asi(dc, insn, MO_TEQ);
     TCGv_i64 t64 = tcg_temp_new_i64();
-    TCGv lo;
+    TCGv lo, hi;
 
     switch (da.type) {
     case GET_ASI_EXCP:
         tcg_temp_free_i64(t64);
         return;
+    case GET_ASI_DIRECT:
+        tcg_gen_qemu_ld_i64(t64, addr, da.mem_idx, da.memop);
+        break;
     default:
         {
             TCGv_i32 r_asi = tcg_const_i32(da.asi);
@@ -2391,6 +2472,7 @@  static void gen_ldda_asi(DisasContext *dc, TCGv hi, TCGv addr,
         break;
     }
 
+    hi = gen_dest_gpr(dc, rd);
     lo = gen_dest_gpr(dc, rd + 1);
     tcg_gen_extr_i64_i32(lo, hi, t64);
     tcg_temp_free_i64(t64);
@@ -2410,6 +2492,9 @@  static void gen_stda_asi(DisasContext *dc, TCGv hi, TCGv addr,
     switch (da.type) {
     case GET_ASI_EXCP:
         break;
+    case GET_ASI_DIRECT:
+        tcg_gen_qemu_st_i64(t64, addr, da.mem_idx, da.memop);
+        break;
     default:
         {
             TCGv_i32 r_asi = tcg_const_i32(da.asi);
@@ -4898,7 +4983,7 @@  static void disas_sparc_insn(DisasContext * dc, unsigned int insn)
                     if (rd & 1) {
                         goto illegal_insn;
                     }
-                    gen_ldda_asi(dc, cpu_val, cpu_addr, insn, rd);
+                    gen_ldda_asi(dc, cpu_addr, insn, rd);
                     goto skip_move;
                 case 0x19:      /* ldsba, load signed byte alternate */
                     gen_ld_asi(dc, cpu_val, cpu_addr, insn, MO_SB);