From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTBVC-0002So-MJ for qemu-devel@nongnu.org; Tue, 09 Feb 2016 11:50:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTBV8-0008Do-Jj for qemu-devel@nongnu.org; Tue, 09 Feb 2016 11:50:58 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:9041 helo=imgpgp01.kl.imgtec.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTBV7-0008CE-Rm for qemu-devel@nongnu.org; Tue, 09 Feb 2016 11:50:54 -0500 Date: Tue, 9 Feb 2016 16:50:52 +0000 From: James Hogan Message-ID: <20160209165052.GC3678@jhogan-linux.le.imgtec.org> References: <1455014403-10742-1-git-send-email-rth@twiddle.net> <1455014403-10742-12-git-send-email-rth@twiddle.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="nmemrqcdn5VTmUEE" Content-Disposition: inline In-Reply-To: <1455014403-10742-12-git-send-email-rth@twiddle.net> Subject: Re: [Qemu-devel] [PATCH 11/15] tcg-mips: Use mips64r6 instructions in tcg_out_movi List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: qemu-devel@nongnu.org, aurelien@aurel32.net --nmemrqcdn5VTmUEE Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Richard, On Tue, Feb 09, 2016 at 09:39:59PM +1100, Richard Henderson wrote: > The DAHI and DATI instructions can eliminate two insns > off the pre-r6 path. >=20 > Signed-off-by: Richard Henderson > --- > tcg/mips/tcg-target.c | 63 +++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 63 insertions(+) >=20 > diff --git a/tcg/mips/tcg-target.c b/tcg/mips/tcg-target.c > index 97f9251..f7f4331 100644 > --- a/tcg/mips/tcg-target.c > +++ b/tcg/mips/tcg-target.c > @@ -303,7 +303,9 @@ typedef enum { > OPC_ORI =3D 015 << 26, > OPC_XORI =3D 016 << 26, > OPC_LUI =3D 017 << 26, > + OPC_AUI =3D OPC_LUI, > OPC_DADDIU =3D 031 << 26, > + OPC_DAUI =3D 035 << 26, > OPC_LB =3D 040 << 26, > OPC_LH =3D 041 << 26, > OPC_LW =3D 043 << 26, > @@ -383,6 +385,8 @@ typedef enum { > OPC_REGIMM =3D 001 << 26, > OPC_BLTZ =3D OPC_REGIMM | (000 << 16), > OPC_BGEZ =3D OPC_REGIMM | (001 << 16), > + OPC_DAHI =3D OPC_REGIMM | (006 << 16), > + OPC_DATI =3D OPC_REGIMM | (036 << 16), > =20 > OPC_SPECIAL2 =3D 034 << 26, > OPC_MUL_R5 =3D OPC_SPECIAL2 | 002, > @@ -402,6 +406,10 @@ typedef enum { > OPC_SEB =3D OPC_SPECIAL3 | 02040, > OPC_SEH =3D OPC_SPECIAL3 | 03040, > =20 > + OPC_PCREL =3D 073 << 26, > + OPC_ADDIUPC =3D OPC_PCREL | (0 << 19), > + OPC_ALUIPC =3D OPC_PCREL | (3 << 19) | (7 << 16), > + > /* MIPS r6 doesn't have JR, JALR should be used instead */ > OPC_JR =3D use_mips32r6_instructions ? OPC_JALR : OPC_JR_R5, > =20 > @@ -448,6 +456,17 @@ static inline void tcg_out_opc_imm(TCGContext *s, MI= PSInsn opc, > tcg_out32(s, inst); > } > =20 > +static inline void tcg_out_opc_pc19(TCGContext *s, MIPSInsn opc, > + TCGReg rs, TCGArg imm) > +{ > + int32_t inst; > + > + inst =3D opc; > + inst |=3D (rs & 0x1F) << 21; > + inst |=3D (imm & 0x7ffff); > + tcg_out32(s, inst); > +} > + > /* > * Type bitfield > */ > @@ -589,6 +608,50 @@ static void tcg_out_movi(TCGContext *s, TCGType type, > } > if (TCG_TARGET_REG_BITS =3D=3D 32 || arg =3D=3D (int32_t)arg) { > tcg_out_opc_imm(s, OPC_LUI, ret, TCG_REG_ZERO, arg >> 16); > + } else if (use_mips32r6_instructions) { > + tcg_target_long disp =3D arg - (intptr_t)s->code_ptr; > + if (disp =3D=3D sextract32(disp, 2, 19) * 4) { > + tcg_out_opc_pc19(s, OPC_ADDIUPC, ret, disp >> 2); > + return; > + } else if ((disp & ~(tcg_target_long)0xffff) > + =3D=3D sextract32(disp, 16, 16) * 0x10000) { > + tcg_out_opc_imm(s, OPC_ALUIPC, ret, 0, disp >> 16); I think ret and 0 are the wrong way around here. You're putting 0 in rs (the destination register), which causes a seg fault. OUT: [size=3D56]=20 0xfff30b0064: lw s1,-8(s0)=20 0xfff30b0068: bnezalc zero,s1,0xfff30b0090=20 0xfff30b006c: nop=20 0xfff30b0070: j 0xfff0000000=20 0xfff30b0074: nop=20 0xfff30b0078: lui s1,0xbfc0=20 0xfff30b007c: ori s1,s1,0x580=20 0xfff30b0080: sd s1,256(s0)=20 0xfff30b0084: aluipc zero,0xfeb7=20 0xfff30b0088: j 0xfff30b0034=20 0xfff30b008c: ori v0,v0,0x4010=20 0xfff30b0090: aluipc zero,0xfeb7=20 0xfff30b0094: j 0xfff30b0034=20 0xfff30b0098: ori v0,v0,0x4013 Cheers James > + } else { > + TCGReg in =3D TCG_REG_ZERO; > + tcg_target_long tmp =3D (int16_t)arg; > + > + /* The R6 manual recommends construction of immediates in > + order of low to high (ADDI, AUI, DAHI, DATI) in order > + to simplify hardware recognizing these sequences. */ > + > + if (tmp) { > + tcg_out_opc_imm(s, OPC_ADDIU, ret, in, tmp); > + in =3D ret; > + } > + arg =3D (arg - tmp) >> 16; > + tmp =3D (int16_t)arg; > + > + /* Note that DAHI and DATI only have one register operand, > + and are thus we must put a zero low part in place. Also > + note that we already eliminated simple 32-bit constants > + so we know this must happen. */ > + if (tmp || in !=3D ret) { > + tcg_out_opc_imm(s, OPC_AUI, ret, in, tmp); > + } > + arg =3D (arg - tmp) >> 16; > + tmp =3D (int16_t)arg; > + > + if (tmp) { > + tcg_out_opc_imm(s, OPC_DAHI, ret, 0, tmp); > + } > + arg =3D (arg - tmp) >> 16; > + tcg_debug_assert(arg =3D=3D (int16_t)arg); > + > + if (arg) { > + tcg_out_opc_imm(s, OPC_DATI, ret, 0, arg); > + } > + return; > + } > } else { > tcg_out_movi(s, TCG_TYPE_I32, ret, arg >> 31 >> 1); > if (arg & 0xffff0000ull) { > --=20 > 2.5.0 >=20 --nmemrqcdn5VTmUEE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWuhjsAAoJEGwLaZPeOHZ6hBgP+QGXNZx3cwxmVQJczSXmLw3/ VZugyRaoFLURf25gCIbUUK40cxu9lfts4bdvlfUtg7msIyEthazNeh63YextiPYK 6EpxsFMH7NXDzhgJPQPFQjoZCSQBN62VVv0KiO+ihGhZBUKTIUef8IpADkXL7ggq w9H22hzIgPAH+M3J8Yvtafzw2aucOkopSn1qeHNw40a7qSLg0NLaM4BdPWcQ08sE 2QTdakrqxO0/J1Z5Ok9tGFR28A94mjPjFaFsXgDr72kJoVq27uzKn3izmJQgZ0T7 bxGMzd5Y3Ya4DNGUL5mrwKPzYH+1zdFNaqKLbl8e7vVfPDFNpGhpEHUr8gFZymyf l5nv/Ws+P1KTzlkPwhGWA7nYDlNO3frRMHYl5e1e7vhkphWPErqWbWNCtExUY23d 2xgbhb3xdVcrIoxkIj8XcBXcUUrACnTKY6K3+DkFrTbCa/BMs1l9ec0/crw2fyot VI6ih4ZWNzqA2v8HvUT3oa9O4JnnRmweeaamauIcMeP4t8rwGOBvlXNyEFIO60rF qmmnWIIW9pf0LCQOuI/fvWAILHKRS1B6nf/CotoV3nXeuAlgOhIipW+Tyc6ELQ1d I8prwvKVr6DdSwWOwY9ABvg/A0MaJQ52l5Slx9Ji/EjhQPz5yr88O/eK8urazcOq euP6B3jA9AuNUlamrRz2 =BMqG -----END PGP SIGNATURE----- --nmemrqcdn5VTmUEE--