@@ -1669,6 +1669,12 @@ static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
tcg_out_st32(s, COND_AL, arg, arg1, arg2);
}
+static inline int tcg_out_sti(TCGContext *s, TCGType type, tcg_target_long val,
+ int arg1, tcg_target_long arg2)
+{
+ return 0;
+}
+
static void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val)
{
if (val > 0)
@@ -285,6 +285,12 @@ static inline void tcg_out_st(TCGContext *s, TCGType type, int ret,
tcg_abort();
}
+static inline int tcg_out_sti(TCGContext *s, TCGType type, tcg_target_long val,
+ int arg1, tcg_target_long arg2)
+{
+ return 0;
+}
+
static inline void tcg_out_arith(TCGContext *s, int t, int r1, int r2, int op)
{
tcg_out32(s, op | INSN_T(t) | INSN_R1(r1) | INSN_R2(r2));
@@ -276,6 +276,15 @@ static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
tcg_out_modrm_offset(s, 0x89, arg, arg1, arg2);
}
+static inline int tcg_out_sti(TCGContext *s, TCGType type, tcg_target_long val,
+ int arg1, tcg_target_long arg2)
+{
+ /* movl */
+ tcg_out_modrm_offset(s, 0xc7, 0, arg1, arg2);
+ tcg_out32(s, val);
+ return 1;
+}
+
static inline void tgen_arithi(TCGContext *s, int c, int r0, int32_t val, int cf)
{
if (!cf && ((c == ARITH_ADD && val == 1) || (c == ARITH_SUB && val == -1))) {
@@ -958,6 +958,15 @@ static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1,
tcg_out_ldst (s, arg, arg1, arg2, STW, STWX);
}
+static inline int tcg_out_sti(TCGContext *s, TCGType type, tcg_target_long val,
+ int arg1, tcg_target_long arg2)
+{
+ /* movl */
+ tcg_out_modrm_offset(s, 0xc7, 0, arg1, arg2);
+ tcg_out32(s, val);
+ return 1;
+}
+
static void ppc_addi (TCGContext *s, int rt, int ra, tcg_target_long si)
{
if (!si && rt == ra)
@@ -917,6 +917,15 @@ static void tcg_out_st (TCGContext *s, TCGType type, int arg, int arg1,
tcg_out_ldsta (s, arg, arg1, arg2, STD, STDX);
}
+static inline int tcg_out_sti(TCGContext *s, TCGType type, tcg_target_long val,
+ int arg1, tcg_target_long arg2)
+{
+ /* movl */
+ tcg_out_modrm_offset(s, 0xc7, 0, arg1, arg2);
+ tcg_out32(s, val);
+ return 1;
+}
+
static void ppc_addi32 (TCGContext *s, int rt, int ra, tcg_target_long si)
{
if (!si && rt == ra)
@@ -392,6 +392,15 @@ static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
tcg_out_ldst(s, arg, arg1, arg2, STX);
}
+static inline int tcg_out_sti(TCGContext *s, TCGType type, tcg_target_long val,
+ int arg1, tcg_target_long arg2)
+{
+ /* movl */
+ tcg_out_modrm_offset(s, 0xc7, 0, arg1, arg2);
+ tcg_out32(s, val);
+ return 1;
+}
+
static inline void tcg_out_sety(TCGContext *s, tcg_target_long val)
{
if (val == 0 || val == -1)
@@ -1385,12 +1385,14 @@ static void temp_save(TCGContext *s, int temp, TCGRegSet allocated_regs)
ts->val_type = TEMP_VAL_MEM;
break;
case TEMP_VAL_CONST:
- reg = tcg_reg_alloc(s, tcg_target_available_regs[ts->type],
- allocated_regs);
if (!ts->mem_allocated)
temp_allocate_frame(s, temp);
- tcg_out_movi(s, ts->type, reg, ts->val);
- tcg_out_st(s, ts->type, reg, ts->mem_reg, ts->mem_offset);
+ if (!tcg_out_sti(s, ts->type, ts->val, ts->mem_reg, ts->mem_offset)) {
+ reg = tcg_reg_alloc(s, tcg_target_available_regs[ts->type],
+ allocated_regs);
+ tcg_out_movi(s, ts->type, reg, ts->val);
+ tcg_out_st(s, ts->type, reg, ts->mem_reg, ts->mem_offset);
+ }
ts->val_type = TEMP_VAL_MEM;
break;
case TEMP_VAL_MEM:
@@ -395,6 +395,22 @@ static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
tcg_out_modrm_offset(s, 0x89 | P_REXW, arg, arg1, arg2); /* movq */
}
+static inline int tcg_out_sti(TCGContext *s, TCGType type, tcg_target_long val,
+ int arg1, tcg_target_long arg2)
+{
+ if (type == TCG_TYPE_I32) {
+ tcg_out_modrm_offset(s, 0xc7, 0, arg1, arg2); /* movl */
+ tcg_out32(s, val);
+ } else {
+ if ((int32_t) val != val) {
+ return 0;
+ }
+ tcg_out_modrm_offset(s, 0xc7 | P_REXW, 0, arg1, arg2); /* movq */
+ tcg_out32(s, val);
+ }
+ return 1;
+}
+
static inline void tgen_arithi32(TCGContext *s, int c, int r0, int32_t val)
{
if ((c == ARITH_ADD && val == 1) || (c == ARITH_SUB && val == -1)) {
Currently only implemented for x86/x86_64. It may also be implemented for targets that keep one register for TCG internal use. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net> --- tcg/arm/tcg-target.c | 6 ++++++ tcg/hppa/tcg-target.c | 6 ++++++ tcg/i386/tcg-target.c | 9 +++++++++ tcg/ppc/tcg-target.c | 9 +++++++++ tcg/ppc64/tcg-target.c | 9 +++++++++ tcg/sparc/tcg-target.c | 9 +++++++++ tcg/tcg.c | 10 ++++++---- tcg/x86_64/tcg-target.c | 16 ++++++++++++++++ 8 files changed, 70 insertions(+), 4 deletions(-)