Skip to contentSkip to conversation

[5281] Use the new concat_i32_i64 op for std and stda

Qemu-devel Blue Swirl 3 participants 10 messages Sep 21, 2008 – Sep 22, 2008

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

Revision: 5281

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5281
Author:   blueswir1
Date:     2008-09-21 14:49:09 +0000 (Sun, 21 Sep 2008)

Log Message:
-----------
Use the new concat_i32_i64 op for std and stda

Modified Paths:
--------------
trunk/target-sparc/helper.h
trunk/target-sparc/op_helper.c
trunk/target-sparc/translate.c

Modified: trunk/target-sparc/helper.h
===================================================================

target-sparc/helper.h +0 -1
@@ -44,7 +44,6 @@
 DEF_HELPER(void, helper_flush, (target_ulong addr))
 DEF_HELPER(target_ulong, helper_udiv, (target_ulong a, target_ulong b))
 DEF_HELPER(target_ulong, helper_sdiv, (target_ulong a, target_ulong b))
-DEF_HELPER(uint64_t, helper_pack64, (target_ulong high, target_ulong low))
 DEF_HELPER(void, helper_stdf, (target_ulong addr, int mem_idx))
 DEF_HELPER(void, helper_lddf, (target_ulong addr, int mem_idx))
 DEF_HELPER(void, helper_ldqf, (target_ulong addr, int mem_idx))

Modified: trunk/target-sparc/op_helper.c
===================================================================

target-sparc/op_helper.c +0 -5
@@ -2281,11 +2281,6 @@
     }
 }
 
-uint64_t helper_pack64(target_ulong high, target_ulong low)
-{
-    return ((uint64_t)high << 32) | (uint64_t)(low & 0xffffffff);
-}
-
 void helper_stdf(target_ulong addr, int mem_idx)
 {
     helper_check_align(addr, 7);

Modified: trunk/target-sparc/translate.c
===================================================================

target-sparc/translate.c +19 -15
@@ -1715,13 +1715,14 @@
 
 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
 {
-    TCGv r_temp, r_asi, r_size;
+    TCGv r_low, r_asi, r_size;
 
-    r_temp = tcg_temp_new(TCG_TYPE_TL);
-    gen_movl_reg_TN(rd + 1, r_temp);
-    tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
-                       r_temp);
-    tcg_temp_free(r_temp);
+    gen_movl_reg_TN(rd + 1, cpu_tmp0);
+    r_low = tcg_temp_new(TCG_TYPE_I32);
+    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
+    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
+    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
+    tcg_temp_free(r_low);
     r_asi = gen_get_asi(insn, addr);
     r_size = tcg_const_i32(8);
     tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
@@ -1817,12 +1818,14 @@
 
 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
 {
-    TCGv r_temp, r_asi, r_size;
+    TCGv r_low, r_asi, r_size;
 
-    r_temp = tcg_temp_new(TCG_TYPE_TL);
-    gen_movl_reg_TN(rd + 1, r_temp);
-    tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
-    tcg_temp_free(r_temp);
+    gen_movl_reg_TN(rd + 1, cpu_tmp0);
+    r_low = tcg_temp_new(TCG_TYPE_I32);
+    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
+    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
+    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
+    tcg_temp_free(r_low);
     r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
     r_size = tcg_const_i32(8);
     tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
@@ -4482,10 +4485,11 @@
                         tcg_gen_helper_0_2(helper_check_align, cpu_addr,
                                            r_const); // XXX remove
                         tcg_temp_free(r_const);
-                        r_low = tcg_temp_new(TCG_TYPE_TL);
-                        gen_movl_reg_TN(rd + 1, r_low);
-                        tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
-                                           r_low);
+                        gen_movl_reg_TN(rd + 1, cpu_tmp0);
+                        r_low = tcg_temp_new(TCG_TYPE_I32);
+                        tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
+                        tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_val);
+                        tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
                         tcg_temp_free(r_low);
                         tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
                     }
#1 lore raw
Quoted 5 lines · Blue Swirl

+    r_low = tcg_temp_new(TCG_TYPE_I32);
+    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
+    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
+    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
+    tcg_temp_free(r_low);

It's more efficient to not use concat_i32_i64 on 64-bit targets. See patch below. I'll let you decide if you want to apply or ignore it.

helper.h +0 -1
Index: target-sparc/helper.h
===================================================================
@@ -44,7 +44,6 @@ DEF_HELPER(void, helper_restore, (void))
 DEF_HELPER(void, helper_flush, (target_ulong addr))
 DEF_HELPER(target_ulong, helper_udiv, (target_ulong a, target_ulong b))
 DEF_HELPER(target_ulong, helper_sdiv, (target_ulong a, target_ulong b))
-DEF_HELPER(uint64_t, helper_pack64, (target_ulong high, target_ulong low))
 DEF_HELPER(void, helper_stdf, (target_ulong addr, int mem_idx))
 DEF_HELPER(void, helper_lddf, (target_ulong addr, int mem_idx))
 DEF_HELPER(void, helper_ldqf, (target_ulong addr, int mem_idx))
op_helper.c +0 -5
Index: target-sparc/op_helper.c
===================================================================
@@ -2281,11 +2281,6 @@ target_ulong helper_sdiv(target_ulong a,
     }
 }
 
-uint64_t helper_pack64(target_ulong high, target_ulong low)
-{
-    return ((uint64_t)high << 32) | (uint64_t)(low & 0xffffffff);
-}
-
 void helper_stdf(target_ulong addr, int mem_idx)
 {
     helper_check_align(addr, 7);
translate.c +28 -5
Index: target-sparc/translate.c
===================================================================
@@ -1619,6 +1619,31 @@ static inline void gen_clear_float_excep
     tcg_gen_helper_0_0(helper_clear_float_exceptions);
 }
 
+/* May clobber low.  */
+static void gen_pack64(TCGv dest, TCGv high, TCGv low)
+{
+#ifdef TARGET_SPARC64
+#if HOST_LONG_BITS == 64
+    tcg_gen_shli_i64(dest, high, 32);
+    tcg_gen_ext32u_i64(low, low);
+    tcg_gen_or_i64(dest, dest, low);
+# else
+    /* We could omit the truncation if we assumed that 64-bit TCG variables
+       can be used in 32-bit ops.  Hopefully TCG will be smart enough to
+       eliminate the copy.  */
+    TCGv low32 = tcg_temp_new(TCG_TYPE_I32);
+    TCGv high32 = tcg_temp_new(TCG_TYPE_I32);
+    tcg_gen_trunc_i64_i32(low32, low);
+    tcg_gen_trunc_i64_i32(high32, high);
+    tcg_gen_concat_i32_i64(dest, low32, high32);
+    tcg_temp_free(high32);
+    tcg_temp_free(low32);
+# endif
+#else /* !TARGET_SPARC64 */
+    tcg_gen_concat_i32_i64(dest, low, high);
+#endif
+}
+
 /* asi moves */
 #ifdef TARGET_SPARC64
 static inline TCGv gen_get_asi(int insn, TCGv r_addr)
@@ -1719,8 +1744,7 @@ static inline void gen_stda_asi(TCGv hi,
 
     r_temp = tcg_temp_new(TCG_TYPE_TL);
     gen_movl_reg_TN(rd + 1, r_temp);
-    tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi,
-                       r_temp);
+    gen_pack64(cpu_tmp64, hi, r_temp);
     tcg_temp_free(r_temp);
     r_asi = gen_get_asi(insn, addr);
     r_size = tcg_const_i32(8);
@@ -1821,7 +1845,7 @@ static inline void gen_stda_asi(TCGv hi,
 
     r_temp = tcg_temp_new(TCG_TYPE_TL);
     gen_movl_reg_TN(rd + 1, r_temp);
-    tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, hi, r_temp);
+    gen_pack64(cpu_tmp64, hi, r_temp);
     tcg_temp_free(r_temp);
     r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
     r_size = tcg_const_i32(8);
@@ -4484,8 +4508,7 @@ static void disas_sparc_insn(DisasContex
                         tcg_temp_free(r_const);
                         r_low = tcg_temp_new(TCG_TYPE_TL);
                         gen_movl_reg_TN(rd + 1, r_low);
-                        tcg_gen_helper_1_2(helper_pack64, cpu_tmp64, cpu_val,
-                                           r_low);
+                        gen_pack64(cpu_tmp64, cpu_val, r_low);
                         tcg_temp_free(r_low);
                         tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
                     }
author
#2 lore raw
Quoted 10 lines · Paul Brook

Review

Quoted 5 lines · Blue Swirl
(quoted diff) +5 -0
+    r_low = tcg_temp_new(TCG_TYPE_I32);
+    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
+    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
+    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
+    tcg_temp_free(r_low);

It's more efficient to not use concat_i32_i64 on 64-bit targets.
See patch below. I'll let you decide if you want to apply or ignore it.

Good point. How about adding instead a concat_i64_i64 starting from this piece:

Quoted 3 lines
 +    tcg_gen_shli_i64(dest, high, 32);
 +    tcg_gen_ext32u_i64(low, low);
 +    tcg_gen_or_i64(dest, dest, low);

and also add defines for concat_tl_i64? That would be both clean and efficient.

I think ldd on i386 would benefit from a reverse operation (64 to two 32/64 bit words).

author
#3 lore raw
Quoted 13 lines · Blue Swirl
Quoted 10 lines · Paul Brook

Review

Quoted 5 lines · Blue Swirl
(quoted diff) +5 -0
+    r_low = tcg_temp_new(TCG_TYPE_I32);
+    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
+    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
+    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
+    tcg_temp_free(r_low);

It's more efficient to not use concat_i32_i64 on 64-bit targets.
See patch below. I'll let you decide if you want to apply or ignore it.

Quoted 8 lines

Good point. How about adding instead a concat_i64_i64 starting from this piece:

Quoted 3 lines
 +    tcg_gen_shli_i64(dest, high, 32);
 +    tcg_gen_ext32u_i64(low, low);
 +    tcg_gen_or_i64(dest, dest, low);

and also add defines for concat_tl_i64? That would be both clean and efficient.

Like these patches?

tcg/tcg-op.h +10 -0
Index: qemu/tcg/tcg-op.h
===================================================================
@@ -1412,6 +1412,14 @@
 #endif
 }
 
+static inline void tcg_gen_concat_i64_i64(TCGv dest, TCGv low, TCGv high)
+{
+    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
+    tcg_gen_shli_i64(tmp, high, 32);
+    tcg_gen_or_i64(dest, low, tmp);
+    tcg_temp_free(tmp);
+}
+
 /***************************************/
 /* QEMU specific operations. Their type depend on the QEMU CPU
    type. */
@@ -1664,6 +1672,7 @@
 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
 #define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
 #define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
+#define tcg_gen_concat_tl_i64 tcg_gen_concat_i64_i64
 #define tcg_const_tl tcg_const_i64
 #else
 #define TCG_TYPE_TL TCG_TYPE_I32
@@ -1715,6 +1724,7 @@
 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
 #define tcg_gen_ext32u_tl tcg_gen_mov_i32
 #define tcg_gen_ext32s_tl tcg_gen_mov_i32
+#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
 #define tcg_const_tl tcg_const_i32
 #endif
 
target-sparc/translate.c +6 -18
Index: qemu/target-sparc/translate.c
===================================================================
@@ -1715,14 +1715,10 @@
 
 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
 {
-    TCGv r_low, r_asi, r_size;
+    TCGv r_asi, r_size;
 
     gen_movl_reg_TN(rd + 1, cpu_tmp0);
-    r_low = tcg_temp_new(TCG_TYPE_I32);
-    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
-    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
-    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
-    tcg_temp_free(r_low);
+    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
     r_asi = gen_get_asi(insn, addr);
     r_size = tcg_const_i32(8);
     tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
@@ -1818,14 +1814,10 @@
 
 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
 {
-    TCGv r_low, r_asi, r_size;
+    TCGv r_asi, r_size;
 
     gen_movl_reg_TN(rd + 1, cpu_tmp0);
-    r_low = tcg_temp_new(TCG_TYPE_I32);
-    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
-    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
-    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
-    tcg_temp_free(r_low);
+    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
     r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
     r_size = tcg_const_i32(8);
     tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
@@ -4477,7 +4469,7 @@
                     if (rd & 1)
                         goto illegal_insn;
                     else {
-                        TCGv r_low, r_const;
+                        TCGv r_const;
 
                         save_state(dc, cpu_cond);
                         gen_address_mask(dc, cpu_addr);
@@ -4486,11 +4478,7 @@
                                            r_const); // XXX remove
                         tcg_temp_free(r_const);
                         gen_movl_reg_TN(rd + 1, cpu_tmp0);
-                        r_low = tcg_temp_new(TCG_TYPE_I32);
-                        tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
-                        tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_val);
-                        tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
-                        tcg_temp_free(r_low);
+                        tcg_gen_concat_i32_i64(cpu_tmp64, cpu_tmp0, cpu_val);
                         tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
                     }
                     break;
#4 lore raw

tcg/tcg-op.h line 1421

Quoted 9 lines

Like these patches?

tcg/tcg-op.h +7 -0
+static inline void tcg_gen_concat_i64_i64(TCGv dest, TCGv low, TCGv high)
+{
+    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
+    tcg_gen_shli_i64(tmp, high, 32);
+    tcg_gen_or_i64(dest, low, tmp);
+    tcg_temp_free(tmp);
+}

This should use concat_i32_i64 on 32-bit hosts.

Ok with that change, the rename I suggested in my previous mail, and if you add documentation to tcg/README.

Paul

author
#5 lore raw
Quoted 12 lines · Paul Brook

Review

Quoted 9 lines

Like these patches?

(quoted diff) +7 -0
+static inline void tcg_gen_concat_i64_i64(TCGv dest, TCGv low, TCGv high)
+{
+    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
+    tcg_gen_shli_i64(tmp, high, 32);
+    tcg_gen_or_i64(dest, low, tmp);
+    tcg_temp_free(tmp);
+}

This should use concat_i32_i64 on 32-bit hosts.

Quoted 2 lines

Ok with that change, the rename I suggested in my previous mail, and if you add documentation to tcg/README.

Updated. I'll run a couple of tests.

tcg/tcg-op.h +14 -0
Index: qemu/tcg/tcg-op.h
===================================================================
@@ -1412,6 +1412,18 @@
 #endif
 }
 
+static inline void tcg_gen_concat32_i64(TCGv dest, TCGv low, TCGv high)
+{
+#if TCG_TARGET_REG_BITS == 32
+    tcg_gen_concat_i32_i64(dest, low, high);
+#else
+    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
+    tcg_gen_shli_i64(tmp, high, 32);
+    tcg_gen_or_i64(dest, low, tmp);
+    tcg_temp_free(tmp);
+#endif
+}
+
 /***************************************/
 /* QEMU specific operations. Their type depend on the QEMU CPU
    type. */
@@ -1664,6 +1676,7 @@
 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i64
 #define tcg_gen_ext32u_tl tcg_gen_ext32u_i64
 #define tcg_gen_ext32s_tl tcg_gen_ext32s_i64
+#define tcg_gen_concat_tl_i64 tcg_gen_concat32_i64
 #define tcg_const_tl tcg_const_i64
 #else
 #define TCG_TYPE_TL TCG_TYPE_I32
@@ -1715,6 +1728,7 @@
 #define tcg_gen_ext16s_tl tcg_gen_ext16s_i32
 #define tcg_gen_ext32u_tl tcg_gen_mov_i32
 #define tcg_gen_ext32s_tl tcg_gen_mov_i32
+#define tcg_gen_concat_tl_i64 tcg_gen_concat_i32_i64
 #define tcg_const_tl tcg_const_i32
 #endif
 
tcg/README +4 -0
Index: qemu/tcg/README
===================================================================
@@ -269,6 +269,10 @@
 Construct t0 (64-bit) taking the low half from t1 (32 bit) and the high half
 from t2 (32 bit).
 
+* concat32_i64 t0, t1, t2
+Construct t0 (64-bit) taking the low half from t1 (64 bit) and the high half
+from t2 (64 bit).
+
 ********* Load/Store
 
 * ld_i32/i64 t0, t1, offset
target-sparc/translate.c +6 -18
Index: qemu/target-sparc/translate.c
===================================================================
@@ -1715,14 +1715,10 @@
 
 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
 {
-    TCGv r_low, r_asi, r_size;
+    TCGv r_asi, r_size;
 
     gen_movl_reg_TN(rd + 1, cpu_tmp0);
-    r_low = tcg_temp_new(TCG_TYPE_I32);
-    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
-    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
-    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
-    tcg_temp_free(r_low);
+    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
     r_asi = gen_get_asi(insn, addr);
     r_size = tcg_const_i32(8);
     tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
@@ -1818,14 +1814,10 @@
 
 static inline void gen_stda_asi(TCGv hi, TCGv addr, int insn, int rd)
 {
-    TCGv r_low, r_asi, r_size;
+    TCGv r_asi, r_size;
 
     gen_movl_reg_TN(rd + 1, cpu_tmp0);
-    r_low = tcg_temp_new(TCG_TYPE_I32);
-    tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
-    tcg_gen_trunc_tl_i32(cpu_tmp32, hi);
-    tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
-    tcg_temp_free(r_low);
+    tcg_gen_concat_tl_i64(cpu_tmp64, cpu_tmp0, hi);
     r_asi = tcg_const_i32(GET_FIELD(insn, 19, 26));
     r_size = tcg_const_i32(8);
     tcg_gen_helper_0_4(helper_st_asi, addr, cpu_tmp64, r_asi, r_size);
@@ -4477,7 +4469,7 @@
                     if (rd & 1)
                         goto illegal_insn;
                     else {
-                        TCGv r_low, r_const;
+                        TCGv r_const;
 
                         save_state(dc, cpu_cond);
                         gen_address_mask(dc, cpu_addr);
@@ -4486,11 +4478,7 @@
                                            r_const); // XXX remove
                         tcg_temp_free(r_const);
                         gen_movl_reg_TN(rd + 1, cpu_tmp0);
-                        r_low = tcg_temp_new(TCG_TYPE_I32);
-                        tcg_gen_trunc_tl_i32(r_low, cpu_tmp0);
-                        tcg_gen_trunc_tl_i32(cpu_tmp32, cpu_val);
-                        tcg_gen_concat_i32_i64(cpu_tmp64, r_low, cpu_tmp32);
-                        tcg_temp_free(r_low);
+                        tcg_gen_concat_i32_i64(cpu_tmp64, cpu_tmp0, cpu_val);
                         tcg_gen_qemu_st64(cpu_tmp64, cpu_addr, dc->mem_idx);
                     }
                     break;
#6 lore raw
Quoted 11 lines · Blue Swirl
Quoted 10 lines · Paul Brook
Quoted 9 lines

Like these patches?

tcg/tcg-op.h +7 -0
+static inline void tcg_gen_concat_i64_i64(TCGv dest, TCGv low, TCGv high)
+{
+    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
+    tcg_gen_shli_i64(tmp, high, 32);
+    tcg_gen_or_i64(dest, low, tmp);
+    tcg_temp_free(tmp);
+}
Quoted 6 lines
Quoted 4 lines

This should use concat_i32_i64 on 32-bit hosts.

Ok with that change, the rename I suggested in my previous mail, and if you add documentation to tcg/README.

Updated. I'll run a couple of tests.

I noticed I could also use the complement ("split"?) to those instructions in the mips backend. Maybe the same is true for sparc.

Thiemo

author
#7 lore raw
Quoted 17 lines · Thiemo Seufer
Quoted 16 lines · Blue Swirl
Quoted 14 lines · Paul Brook

tcg/tcg-op.h line 1425

Quoted 9 lines

Like these patches?

tcg/tcg-op.h +7 -0
+static inline void tcg_gen_concat_i64_i64(TCGv dest, TCGv low, TCGv high)
+{
+    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
+    tcg_gen_shli_i64(tmp, high, 32);
+    tcg_gen_or_i64(dest, low, tmp);
+    tcg_temp_free(tmp);
+}

This should use concat_i32_i64 on 32-bit hosts.

Ok with that change, the rename I suggested in my previous mail, and if you add documentation to tcg/README.

Quoted 6 lines
Quoted 1 line

Updated. I'll run a couple of tests.

I noticed I could also use the complement ("split"?) to those
instructions in the mips backend. Maybe the same is true for sparc.

Currently I'm using the following:

                        tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
                        tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
                        gen_movl_TN_reg(rd + 1, cpu_tmp0);
                        tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
                        tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
                        tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);

On a 32 bit host a much more efficient method could be used if wrapped in an op.

#8 lore raw
Quoted 32 lines · Blue Swirl
Quoted 14 lines · Thiemo Seufer
Quoted 13 lines · Blue Swirl
Quoted 12 lines · Paul Brook

tcg/tcg-op.h line 1425

Quoted 9 lines

Like these patches?

+static inline void tcg_gen_concat_i64_i64(TCGv dest, TCGv low, TCGv high) +{

tcg/tcg-op.h +5 -0
+    TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
+    tcg_gen_shli_i64(tmp, high, 32);
+    tcg_gen_or_i64(dest, low, tmp);
+    tcg_temp_free(tmp);
+}

This should use concat_i32_i64 on 32-bit hosts.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Ok with that change, the rename I suggested in my previous mail,
and if you add documentation to tcg/README.

Updated. I'll run a couple of tests.

I noticed I could also use the complement ("split"?) to those
instructions in the mips backend. Maybe the same is true for sparc.

Currently I'm using the following:

                        tcg_gen_trunc_i64_tl(cpu_tmp0, cpu_tmp64);
                        tcg_gen_andi_tl(cpu_tmp0, cpu_tmp0, 0xffffffffULL);
                        gen_movl_TN_reg(rd + 1, cpu_tmp0);
                        tcg_gen_shri_i64(cpu_tmp64, cpu_tmp64, 32);
                        tcg_gen_trunc_i64_tl(cpu_val, cpu_tmp64);
                        tcg_gen_andi_tl(cpu_val, cpu_val, 0xffffffffULL);
Quoted 2 lines

On a 32 bit host a much more efficient method could be used if wrapped in an op.

Which bits would be more efficient?

Note that the final andi is superfluous.

Paul

#9 lore raw
In reply to Blue Swirl
Quoted 5 lines
Quoted 2 lines

It's more efficient to not use concat_i32_i64 on 64-bit targets.
See patch below. I'll let you decide if you want to apply or ignore it.

Good point. How about adding instead a concat_i64_i64 starting from this piece:

I'd call it concat32_i64 (c.f. extu_i32_i64 v.s. ext32u_i64).

Quoted 6 lines
Quoted 3 lines
 +    tcg_gen_shli_i64(dest, high, 32);
 +    tcg_gen_ext32u_i64(low, low);
 +    tcg_gen_or_i64(dest, dest, low);

and also add defines for concat_tl_i64? That would be both clean and efficient.

Sounds reasonable. The cheat for tl->i64 on 32-bit hosts is ok if it's confined to tcg-opc.h.

Quoted 2 lines

I think ldd on i386 would benefit from a reverse operation (64 to two 32/64 bit words).

64 to 32 should be much easier for TCG to optimize automatically. It's just a a series of copies, and can often be implemented without requiring any extra temporaries. The 32 to 64 case is a trickier because you generally need additional temporaries for type correctness and have to propagate all the zeros through the 64-bit logical or.

Paul