From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTIiH-0001sC-LK for qemu-devel@nongnu.org; Tue, 09 Feb 2016 19:32:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTIiE-0000Fm-Dj for qemu-devel@nongnu.org; Tue, 09 Feb 2016 19:32:57 -0500 Received: from mailapp01.imgtec.com ([195.59.15.196]:38652 helo=imgpgp01.kl.imgtec.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTIiE-0000Eq-5h for qemu-devel@nongnu.org; Tue, 09 Feb 2016 19:32:54 -0500 Date: Wed, 10 Feb 2016 00:32:51 +0000 From: James Hogan Message-ID: <20160210003251.GE3678@jhogan-linux.le.imgtec.org> References: <1455014403-10742-1-git-send-email-rth@twiddle.net> <1455014403-10742-12-git-send-email-rth@twiddle.net> <20160209165052.GC3678@jhogan-linux.le.imgtec.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="10jrOL3x2xqLmOsH" Content-Disposition: inline In-Reply-To: <20160209165052.GC3678@jhogan-linux.le.imgtec.org> 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 --10jrOL3x2xqLmOsH Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Richard, On Tue, Feb 09, 2016 at 04:50:52PM +0000, James Hogan wrote: > > @@ -589,6 +608,50 @@ static void tcg_out_movi(TCGContext *s, TCGType ty= pe, > > } > > 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); >=20 > 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. >=20 > 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 Actually, still not quite right. ALUIPC does dest <- ~0xffff & (PC + sign_extend(imm16<<16)) which is effectively dest <- PC & ~0xffff + sign_extend(imm16<<16) so disp should be between arg and code_ptr & ~0xffff, i.e. something like this I think: diff --git a/tcg/mips/tcg-target.c b/tcg/mips/tcg-target.c index 8205ea4e159f..9a5d31478797 100644 --- a/tcg/mips/tcg-target.c +++ b/tcg/mips/tcg-target.c @@ -666,12 +666,13 @@ static void tcg_out_movi(TCGContext *s, TCGType type, 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; + tcg_target_long disphi =3D arg - ((intptr_t)s->code_ptr & ~(tcg_ta= rget_long)0xffff); 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, 0, ret, disp >> 16); + } else if ((disphi & ~(tcg_target_long)0xffff) + =3D=3D sextract32(disphi, 16, 16) * 0x10000) { + tcg_out_opc_imm(s, OPC_ALUIPC, 0, ret, disphi >> 16); } else { TCGReg in =3D TCG_REG_ZERO; tcg_target_long tmp =3D (int16_t)arg; Otherwise, in this case its trying to load the immediate 0xfff1c30000 relative to 0xfff30b0084, and calculates a disp of FEB7FF7C, which is truncated to 0xFEB7. The result is then: 0xfff30b0000 + (int)0xfeb70000 =3D 0xfff1c20000 which is off by 64KiB. With the above change we get: disphi =3D 0xfeb80000 and the result is then: 0xfff30b0000 + (int)0xfeb80000 =3D 0xfff1c30000 Cheers James --10jrOL3x2xqLmOsH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWuoUzAAoJEGwLaZPeOHZ6GUoP/j8whkt82jGK+qIqecwj3NoP zukTWBICrh6j6fwiAoO3tUt8+HThvGhRlhHAhSm455y2UYnyTZYbWpvdqu9x0KFB ZQ2N7BCYGc8gaqrHi8TXiU90+rVNarPhO2jbWuwwd8Sev//MF4+UL4p07Xx8cSoT pUHzjiywv77UX9ruWtzzf/dSwl0BJBM0OyYM4EudzICBlXSiW14XnVVMsEg4boPl oiDVf1JUOiHRhwhhgPjbG0x+fyvMvqDMDU04nHJc91MJVg/gT4yMaxfP05Sshbku G2OPW1JuZcSkjM1wRjNROWAMNcH33pZsUrGOQ/eY4Ae8ok/qZz6T/Del6p/GjXRH msj+WLBMjDbUrxTm4cP345m+8vhOCD4gy3Tkf8vcL1LRjrNehDHUa84zMt7+Jzll Ke8Xz5RW0Dta/hg/elFi/9QVuQQBvEdltexmMg6erJ2ztwRjWSn1bM8PTbyEaM5v sgvaEJ90cc4z+75Nbd1qOIZZkUe9ed8dpUxDcI9VlEOk9DA+VI/QzEDBttQHkXlO bE1+D2frE0NSexUt6ZUZPMap6POl6gUAv1xT9Nvwb2il31rGWAQ6BHTt2LCkRxp8 p2QiGc8gugWEEeBcaG76UzA8587br2Hrddt6yE7vr8OfCUw+X3L0QNzRT5+B9qR7 bcMFtNxXtW6jyE/ffPKY =UiVT -----END PGP SIGNATURE----- --10jrOL3x2xqLmOsH--