From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NN3im-0002WM-Mn for qemu-devel@nongnu.org; Tue, 22 Dec 2009 07:20:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NN3ih-0002Rs-3d for qemu-devel@nongnu.org; Tue, 22 Dec 2009 07:20:11 -0500 Received: from [199.232.76.173] (port=51151 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NN3ig-0002Rk-Tb for qemu-devel@nongnu.org; Tue, 22 Dec 2009 07:20:06 -0500 Received: from mail-px0-f189.google.com ([209.85.216.189]:54548) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NN3ig-0003ID-Fm for qemu-devel@nongnu.org; Tue, 22 Dec 2009 07:20:06 -0500 Received: by pxi27 with SMTP id 27so2575248pxi.4 for ; Tue, 22 Dec 2009 04:20:05 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <20091219231134.GA2167@volta.aurel32.net> References: <4a54bdd4cf32635b57b215e4bead4b948f39ba0c.1261248772.git.rth@twiddle.net> <20091219231134.GA2167@volta.aurel32.net> Date: Tue, 22 Dec 2009 13:20:05 +0100 Message-ID: <761ea48b0912220420o4a9ac9e6x1e765c314600f0f5@mail.gmail.com> Subject: Re: [Qemu-devel] [PATCH 5/5] tcg-i386: Implement setcond. From: Laurent Desnogues Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aurelien Jarno Cc: qemu-devel@nongnu.org, Richard Henderson On Sun, Dec 20, 2009 at 12:11 AM, Aurelien Jarno wro= te: > On Sat, Dec 19, 2009 at 10:46:38AM -0800, Richard Henderson wrote: >> Signed-off-by: Richard Henderson > > This looks ok, though I would appreciate someone else to review it in > details. It looks good to me too (though I didn't test it explicitly). Laurent >> --- >> =A0tcg/i386/tcg-target.c | =A0 73 ++++++++++++++++++++++++++++++++++++++= +++++++++-- >> =A01 files changed, 70 insertions(+), 3 deletions(-) >> >> diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c >> index 4c42caf..43e0155 100644 >> --- a/tcg/i386/tcg-target.c >> +++ b/tcg/i386/tcg-target.c >> @@ -360,9 +360,8 @@ static void tcg_out_jxx(TCGContext *s, int opc, int = label_index, int small) >> =A0 =A0 =A0} >> =A0} >> >> -static void tcg_out_brcond(TCGContext *s, int cond, >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TCGArg arg1, TCGAr= g arg2, int const_arg2, >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int label_index, i= nt small) >> +static void tcg_out_cmp(TCGContext *s, TCGArg arg1, TCGArg arg2, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int const_arg2) >> =A0{ >> =A0 =A0 =A0if (const_arg2) { >> =A0 =A0 =A0 =A0 =A0if (arg2 =3D=3D 0) { >> @@ -374,6 +373,13 @@ static void tcg_out_brcond(TCGContext *s, int cond, >> =A0 =A0 =A0} else { >> =A0 =A0 =A0 =A0 =A0tcg_out_modrm(s, 0x01 | (ARITH_CMP << 3), arg2, arg1)= ; >> =A0 =A0 =A0} >> +} >> + >> +static void tcg_out_brcond(TCGContext *s, int cond, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TCGArg arg1, TCGAr= g arg2, int const_arg2, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 int label_index, i= nt small) >> +{ >> + =A0 =A0tcg_out_cmp(s, arg1, arg2, const_arg2); >> =A0 =A0 =A0tcg_out_jxx(s, tcg_cond_to_jcc[cond], label_index, small); >> =A0} >> >> @@ -459,6 +465,57 @@ static void tcg_out_brcond2(TCGContext *s, const TC= GArg *args, >> =A0 =A0 =A0tcg_out_label(s, label_next, (tcg_target_long)s->code_ptr); >> =A0} >> >> +static void tcg_out_setcond(TCGContext *s, int cond, TCGArg dest, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TCGArg arg1, TC= GArg arg2, int const_arg2) >> +{ >> + =A0 =A0tcg_out_cmp(s, arg1, arg2, const_arg2); >> + =A0 =A0/* setcc */ >> + =A0 =A0tcg_out_modrm(s, 0x90 | tcg_cond_to_jcc[cond] | P_EXT, 0, dest)= ; >> + =A0 =A0tgen_arithi(s, ARITH_AND, dest, 0xff, 0); >> +} >> + >> +static void tcg_out_setcond2(TCGContext *s, const TCGArg *args, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 const int *con= st_args) >> +{ >> + =A0 =A0TCGArg new_args[6]; >> + =A0 =A0int label_true, label_over; >> + >> + =A0 =A0memcpy(new_args, args+1, 5*sizeof(TCGArg)); >> + >> + =A0 =A0if (args[0] =3D=3D args[1] || args[0] =3D=3D args[2] >> + =A0 =A0 =A0 =A0|| (!const_args[3] && args[0] =3D=3D args[3]) >> + =A0 =A0 =A0 =A0|| (!const_args[4] && args[0] =3D=3D args[4])) { >> + =A0 =A0 =A0 =A0/* When the destination overlaps with one of the argume= nt >> + =A0 =A0 =A0 =A0 =A0 registers, don't do anything tricky. =A0*/ >> + =A0 =A0 =A0 =A0label_true =3D gen_new_label(); >> + =A0 =A0 =A0 =A0label_over =3D gen_new_label(); >> + >> + =A0 =A0 =A0 =A0new_args[5] =3D label_true; >> + =A0 =A0 =A0 =A0tcg_out_brcond2(s, new_args, const_args+1, 1); >> + >> + =A0 =A0 =A0 =A0tcg_out_movi(s, TCG_TYPE_I32, args[0], 0); >> + =A0 =A0 =A0 =A0tcg_out_jxx(s, JCC_JMP, label_over, 1); >> + =A0 =A0 =A0 =A0tcg_out_label(s, label_true, (tcg_target_long)s->code_p= tr); >> + >> + =A0 =A0 =A0 =A0tcg_out_movi(s, TCG_TYPE_I32, args[0], 1); >> + =A0 =A0 =A0 =A0tcg_out_label(s, label_over, (tcg_target_long)s->code_p= tr); >> + =A0 =A0} else { >> + =A0 =A0 =A0 =A0/* When the destination does not overlap one of the arg= uments, >> + =A0 =A0 =A0 =A0 =A0 clear the destination first, jump if cond false, a= nd emit an >> + =A0 =A0 =A0 =A0 =A0 increment in the true case. =A0This results in sma= ller code. =A0*/ >> + >> + =A0 =A0 =A0 =A0tcg_out_movi(s, TCG_TYPE_I32, args[0], 0); >> + >> + =A0 =A0 =A0 =A0label_over =3D gen_new_label(); >> + =A0 =A0 =A0 =A0new_args[4] =3D tcg_invert_cond(new_args[4]); >> + =A0 =A0 =A0 =A0new_args[5] =3D label_over; >> + =A0 =A0 =A0 =A0tcg_out_brcond2(s, new_args, const_args+1, 1); >> + >> + =A0 =A0 =A0 =A0tgen_arithi(s, ARITH_ADD, args[0], 1, 0); >> + =A0 =A0 =A0 =A0tcg_out_label(s, label_over, (tcg_target_long)s->code_p= tr); >> + =A0 =A0} >> +} >> + >> =A0#if defined(CONFIG_SOFTMMU) >> >> =A0#include "../../softmmu_defs.h" >> @@ -1120,6 +1177,13 @@ static inline void tcg_out_op(TCGContext *s, int = opc, >> =A0 =A0 =A0 =A0 =A0tcg_out_modrm(s, 0xb7 | P_EXT, args[0], args[1]); >> =A0 =A0 =A0 =A0 =A0break; >> >> + =A0 =A0case INDEX_op_setcond_i32: >> + =A0 =A0 =A0 =A0tcg_out_setcond(s, args[3], args[0], args[1], args[2], = const_args[2]); >> + =A0 =A0 =A0 =A0break; >> + =A0 =A0case INDEX_op_setcond2_i32: >> + =A0 =A0 =A0 =A0tcg_out_setcond2(s, args, const_args); >> + =A0 =A0 =A0 =A0break; >> + >> =A0 =A0 =A0case INDEX_op_qemu_ld8u: >> =A0 =A0 =A0 =A0 =A0tcg_out_qemu_ld(s, args, 0); >> =A0 =A0 =A0 =A0 =A0break; >> @@ -1208,6 +1272,9 @@ static const TCGTargetOpDef x86_op_defs[] =3D { >> =A0 =A0 =A0{ INDEX_op_ext8u_i32, { "r", "q"} }, >> =A0 =A0 =A0{ INDEX_op_ext16u_i32, { "r", "r"} }, >> >> + =A0 =A0{ INDEX_op_setcond_i32, { "q", "r", "ri" } }, >> + =A0 =A0{ INDEX_op_setcond2_i32, { "r", "r", "r", "ri", "ri" } }, >> + >> =A0#if TARGET_LONG_BITS =3D=3D 32 >> =A0 =A0 =A0{ INDEX_op_qemu_ld8u, { "r", "L" } }, >> =A0 =A0 =A0{ INDEX_op_qemu_ld8s, { "r", "L" } }, >> -- >> 1.6.5.2 >> >> >> >> > > -- > Aurelien Jarno =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0GPG: 10= 24D/F1BCDB73 > aurelien@aurel32.net =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 http://www.aurel32.n= et > > >