commit eb326c39503ff265dc83e8792e87e6308d9dfd71 Author: Richard Henderson Date: Fri Dec 18 11:51:35 2009 -0800 tcg-x86_64: Implement setcond and movcond. Implement conditional moves in the x86_64 backend. Signed-off-by: Richard Henderson diff --git a/tcg/x86_64/tcg-target.c b/tcg/x86_64/tcg-target.c index 2339091..1f86946 100644 --- a/tcg/x86_64/tcg-target.c +++ b/tcg/x86_64/tcg-target.c @@ -491,9 +491,8 @@ static void tcg_out_jxx(TCGContext *s, int opc, int label_index) } } -static void tcg_out_brcond(TCGContext *s, int cond, - TCGArg arg1, TCGArg arg2, int const_arg2, - int label_index, int rexw) +static void tcg_out_cond(TCGContext *s, int cond, TCGArg arg1, + TCGArg arg2, int const_arg2, int rexw) { if (const_arg2) { if (arg2 == 0) { @@ -508,9 +507,51 @@ static void tcg_out_brcond(TCGContext *s, int cond, } else { tcg_out_modrm(s, 0x01 | (ARITH_CMP << 3) | rexw, arg2, arg1); } +} + +static void tcg_out_brcond(TCGContext *s, int cond, + TCGArg arg1, TCGArg arg2, int const_arg2, + int label_index, int rexw) +{ + tcg_out_cond(s, cond, arg1, arg2, const_arg2, rexw); tcg_out_jxx(s, tcg_cond_to_jcc[cond], label_index); } +static void tcg_out_setcond(TCGContext *s, int cond, TCGArg dest, + TCGArg arg1, TCGArg arg2, int const_arg2, int rexw) +{ + int use_xor = (dest != arg1 && (const_arg2 || dest != arg2)); + + if (use_xor) + tcg_out_movi(s, TCG_TYPE_I32, dest, 0); + tcg_out_cond(s, cond, arg1, arg2, const_arg2, rexw); + /* setcc */ + tcg_out_modrm(s, 0x90 | tcg_cond_to_jcc[cond] | P_EXT | P_REXB, 0, dest); + if (!use_xor) + tgen_arithi32(s, ARITH_AND, dest, 0xff); +} + +static void tcg_out_movcond(TCGContext *s, int cond, TCGArg dest, + TCGArg cmp1, TCGArg cmp2, int const_cmp2, + TCGArg vtrue, TCGArg vfalse, int rexw) +{ + if (vtrue == vfalse) { + tcg_out_mov(s, dest, vtrue); + return; + } + if (dest == vtrue) { + cond = tcg_invert_cond(cond); + vtrue = vfalse; + vfalse = dest; + } + + tcg_out_cond(s, cond, cmp1, cmp2, const_cmp2, rexw); + if (dest != vfalse) + tcg_out_mov(s, dest, vfalse); + /* cmovcc */ + tcg_out_modrm(s, 0x40 | tcg_cond_to_jcc[cond] | P_EXT | rexw, dest, vtrue); +} + #if defined(CONFIG_SOFTMMU) #include "../../softmmu_defs.h" @@ -1197,6 +1238,24 @@ static inline void tcg_out_op(TCGContext *s, int opc, const TCGArg *args, tcg_out_modrm(s, 0x8b, args[0], args[1]); break; + case INDEX_op_setcond_i32: + tcg_out_setcond(s, args[3], args[0], args[1], args[2], + const_args[2], 0); + break; + case INDEX_op_setcond_i64: + tcg_out_setcond(s, args[3], args[0], args[1], args[2], + const_args[2], P_REXW); + break; + + case INDEX_op_movcond_i32: + tcg_out_movcond(s, args[5], args[0], args[1], args[2], + const_args[2], args[3], args[4], 0); + break; + case INDEX_op_movcond_i64: + tcg_out_movcond(s, args[5], args[0], args[1], args[2], + const_args[2], args[3], args[4], P_REXW); + break; + case INDEX_op_qemu_ld8u: tcg_out_qemu_ld(s, args, 0); break; @@ -1376,6 +1435,12 @@ static const TCGTargetOpDef x86_64_op_defs[] = { { INDEX_op_ext16u_i64, { "r", "r"} }, { INDEX_op_ext32u_i64, { "r", "r"} }, + { INDEX_op_setcond_i32, { "r", "r", "ri" } }, + { INDEX_op_setcond_i64, { "r", "r", "re" } }, + + { INDEX_op_movcond_i32, { "r", "r", "ri", "r", "r" } }, + { INDEX_op_movcond_i64, { "r", "r", "re", "r", "r" } }, + { INDEX_op_qemu_ld8u, { "r", "L" } }, { INDEX_op_qemu_ld8s, { "r", "L" } }, { INDEX_op_qemu_ld16u, { "r", "L" } },