tcg/mips stable patches
cover tcg/mips stable patches
Supercedes: [email protected] ("[RFC PATCH 11.0 0/2] tcg/mips64: Fix shifts and unaligned loads - [DORA-B]")
Hi Quentin, thanks for these. Note that I cannot even compile test mips64 anymore because Debian buster was the last os release, and buster has package versions too old for qemu.
I've fixed up the html damage from your mailer, reviewed the changes, and have changed the second patch to fix the address inside the called function. If one wanted to backport the fix all the way to qemu v8, one would have to apply your patch in two locations for mips32.
Michael, the first patch applies cleanly from stable-10.1, and the second applies from stable-10.0.
r~
Quintin Kong (2):
tcg/mips64: Fix variable shift operand order tcg/mips64: Preserve the base of unaligned loads
tcg/mips/tcg-target.c.inc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 tcg/mips64: Fix variable shift operand order
From: Quintin Kong <[email protected]>
TCGOutOpBinary passes (output, value, count), but MIPS variable shift instructions encode (rd, rt, rs), where rt is the value and rs is the count. tcg_out_opc_reg() takes its register fields in (rd, rs, rt) order, so passing (a0, a1, a2) encodes the value as the count and the count as the value.
Swap a1 and a2 at the four variable shift emitters. This covers the I32 and I64 forms of SHL, SHR, SAR, and ROTR.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4103
Message-ID: <[email protected]>
--- tcg/mips/tcg-target.c.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tcg/mips/tcg-target.c.inc +4 -4
@@ -2049,7 +2049,7 @@ static void tgen_rotr(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) { MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_ROTRV : OPC_DROTRV; - tcg_out_opc_reg(s, insn, a0, a1, a2); + tcg_out_opc_reg(s, insn, a0, a2, a1); } static void tgen_rotri(TCGContext *s, TCGType type,
@@ -2073,7 +2073,7 @@ static void tgen_sar(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) { MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_SRAV : OPC_DSRAV; - tcg_out_opc_reg(s, insn, a0, a1, a2); + tcg_out_opc_reg(s, insn, a0, a2, a1); } static void tgen_sari(TCGContext *s, TCGType type,
@@ -2096,7 +2096,7 @@ static void tgen_shl(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) { MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_SLLV : OPC_DSLLV; - tcg_out_opc_reg(s, insn, a0, a1, a2); + tcg_out_opc_reg(s, insn, a0, a2, a1); } static void tgen_shli(TCGContext *s, TCGType type,
@@ -2119,7 +2119,7 @@ static void tgen_shr(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1, TCGReg a2) { MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_SRLV : OPC_DSRLV; - tcg_out_opc_reg(s, insn, a0, a1, a2); + tcg_out_opc_reg(s, insn, a0, a2, a1); } static void tgen_shri(TCGContext *s, TCGType type,
Signature · 1 line
2.43.0
PATCH 2/2 tcg/mips64: Preserve the base of unaligned loads
In reply to Richard HendersonFrom: Quintin Kong <[email protected]>
The qemu_ld output constraint permits the output register to overlap a dead address input. That is valid for a direct load, but a pre-R6 MIPS host implements an unaligned 32-bit or 64-bit load with an LWR/LWL or LDR/LDL pair. Both instructions require the original base address.
If lo and base overlap, the first instruction replaces the base with part of the loaded value. The second instruction then accesses an unrelated address.
Prior to eb664d0c527, the address register was always a temporary, so this problem never occured. Copy an overlapping base to TCG_TMP0.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4102
Message-ID: <[email protected]>
--- tcg/mips/tcg-target.c.inc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
tcg/mips/tcg-target.c.inc +11 -3
@@ -1338,9 +1338,9 @@ static void tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi, const MIPSInsn ld1 = HOST_BIG_ENDIAN ? OPC_LDL : OPC_LDR; const MIPSInsn ld2 = HOST_BIG_ENDIAN ? OPC_LDR : OPC_LDL; bool sgn = opc & MO_SIGN; + MemOp size = opc & MO_SIZE; - switch (opc & MO_SIZE) { - case MO_16: + if (size == MO_16) { if (HOST_BIG_ENDIAN) { tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP0, base, 0); tcg_out_opc_imm(s, OPC_LBU, lo, base, 1);
@@ -1360,8 +1360,16 @@ static void tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi, tcg_out_opc_sa(s, OPC_SLL, TCG_TMP1, TCG_TMP1, 8); tcg_out_opc_reg(s, OPC_OR, lo, TCG_TMP0, TCG_TMP1); } - break; + return; + } + /* Both loads in the unaligned pair require the original base. */ + if (lo == base) { + tcg_out_mov(s, TCG_TYPE_PTR, TCG_TMP0, base); + base = TCG_TMP0; + } + + switch (size) { case MO_32: tcg_out_opc_imm(s, lw1, lo, base, 0); tcg_out_opc_imm(s, lw2, lo, base, 3);
Signature · 1 line
2.43.0
Hi Richard,
Thanks very much for clearing up the HTML damage from my mailer and for the review. I agree that fixing the address inside the called function could be better. Thanks again, and thanks Michael for taking these onto stable-10.0/10.1.
Best,
Quintin
原始邮件
发件人:Richard Henderson <[email protected]>
发件时间:2026年7月29日 18:27
收件人:qemu-devel <[email protected]>
抄送:mjt <[email protected]>, 2358543632 <[email protected]>, quintin.kong <[email protected]> 主题:[PATCH 0/2] tcg/mips stable patches
Supercedes: [email protected]
("[RFC PATCH 11.0 0/2] tcg/mips64: Fix shifts and unaligned loads - [DORA-B]")
Hi Quentin, thanks for these. Note that I cannot even compile test mips64 anymore because Debian buster was the last os release, and buster has package versions too old for qemu.
I've fixed up the html damage from your mailer, reviewed the changes, and have changed the second patch to fix the address inside the called function. If one wanted to backport the fix all the way to qemu v8, one would have to apply your patch in two locations for mips32.
Michael, the first patch applies cleanly from stable-10.1, and the second applies from stable-10.0.
r~
Quintin Kong (2):
tcg/mips64: Fix variable shift operand order tcg/mips64: Preserve the base of unaligned loads
tcg/mips/tcg-target.c.inc | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
--
2.43.0