Received: from eggs.gnu.org ([2001:4830:134:3::10]:34617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKxoI-0001Sc-Ui for qemu-devel@nongnu.org; Sat, 14 Sep 2013 17:55:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VKxoD-00046M-41 for qemu-devel@nongnu.org; Sat, 14 Sep 2013 17:55:22 -0400 Received: from mail-pd0-x22e.google.com ([2607:f8b0:400e:c02::22e]:56962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VKxoC-00046C-Og for qemu-devel@nongnu.org; Sat, 14 Sep 2013 17:55:16 -0400 Received: by mail-pd0-f174.google.com with SMTP id y13so2639308pdi.33 for ; Sat, 14 Sep 2013 14:55:15 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Sat, 14 Sep 2013 14:54:31 -0700 Message-Id: <1379195690-6509-15-git-send-email-rth@twiddle.net> In-Reply-To: <1379195690-6509-1-git-send-email-rth@twiddle.net> References: <1379195690-6509-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH v4 14/33] tcg-aarch64: Handle zero as first argument to sub List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, claudio.fontana@gmail.com In order to properly handle neg, as generated by TCG generic code. Signed-off-by: Richard Henderson --- tcg/aarch64/tcg-target.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tcg/aarch64/tcg-target.c b/tcg/aarch64/tcg-target.c index 5b4eeee..08a0cc4 100644 --- a/tcg/aarch64/tcg-target.c +++ b/tcg/aarch64/tcg-target.c @@ -114,6 +114,7 @@ static inline void patch_reloc(uint8_t *code_ptr, int type, #define TCG_CT_CONST_IS32 0x100 #define TCG_CT_CONST_AIMM 0x200 #define TCG_CT_CONST_LIMM 0x400 +#define TCG_CT_CONST_ZERO 0x800 /* parse target specific constraints */ static int target_parse_constraint(TCGArgConstraint *ct, @@ -147,6 +148,9 @@ static int target_parse_constraint(TCGArgConstraint *ct, case 'L': /* Valid for logical immediate. */ ct->ct |= TCG_CT_CONST_LIMM; break; + case 'Z': /* zero */ + ct->ct |= TCG_CT_CONST_ZERO; + break; default: return -1; } @@ -198,6 +202,9 @@ static int tcg_target_const_match(tcg_target_long val, if ((ct & TCG_CT_CONST_LIMM) && is_limm(val)) { return 1; } + if ((ct & TCG_CT_CONST_ZERO) && val == 0) { + return 1; + } return 0; } @@ -1186,6 +1193,10 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGArg a2 = args[2]; int c2 = const_args[2]; + /* Some operands are defined with "rZ" constraint, a register or + the zero register. These need not actually test args[I] == 0. */ +#define REG0(I) (const_args[I] ? TCG_REG_XZR : (TCGReg)args[I]) + switch (opc) { case INDEX_op_exit_tb: tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_X0, a0); @@ -1255,9 +1266,16 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, /* FALLTHRU */ case INDEX_op_sub_i64: if (c2) { - tcg_out_addsubi(s, ext, a0, a1, -a2); + /* Arithmetic immediate instructions use Xn|sp, and thus + we cannot encode the zero register if tcg optimization + is turned off and both A1 and A2 are constants. */ + if (const_args[1]) { + tcg_out_movi(s, ext ? TCG_TYPE_I64 : TCG_TYPE_I32, a0, -a2); + } else { + tcg_out_addsubi(s, ext, a0, a1, -a2); + } } else { - tcg_fmt_Rdnm(s, INSN_SUB, ext, a0, a1, a2); + tcg_fmt_Rdnm(s, INSN_SUB, ext, a0, REG0(1), a2); } break; @@ -1481,6 +1499,8 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, /* Opcode not implemented. */ tcg_abort(); } + +#undef REG0 } static const TCGTargetOpDef aarch64_op_defs[] = { @@ -1518,8 +1538,8 @@ static const TCGTargetOpDef aarch64_op_defs[] = { { INDEX_op_add_i32, { "r", "r", "rwA" } }, { INDEX_op_add_i64, { "r", "r", "rA" } }, - { INDEX_op_sub_i32, { "r", "r", "rwA" } }, - { INDEX_op_sub_i64, { "r", "r", "rA" } }, + { INDEX_op_sub_i32, { "r", "rZ", "rwA" } }, + { INDEX_op_sub_i64, { "r", "rZ", "rA" } }, { INDEX_op_mul_i32, { "r", "r", "r" } }, { INDEX_op_mul_i64, { "r", "r", "r" } }, { INDEX_op_and_i32, { "r", "r", "rwL" } }, -- 1.8.3.1