* [PATCH 01/19] target/mips: Check for MIPS II when decoding BLEZL/BGTZL
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 18:54 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 02/19] target/mips: Require rt == 0 " Philippe Mathieu-Daudé
` (18 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
Branch-likely instructions were introduced in MIPS II; on MIPS I
they signal Reserved Instruction. BEQL/BNEL and the REGIMM likely
forms already check ISA_MIPS2, but BLEZL and BGTZL (non-R6) did not.
Fixes: d9224450208e ("target-mips: Tighten ISA level checks")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/translate.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index 10811db827c9..f521e0ec5bd0 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -14621,6 +14621,7 @@ static bool decode_opc_legacy(CPUMIPSState *env, DisasContext *ctx)
gen_compute_compact_branch(ctx, op, rs, rt, imm << 2);
} else {
/* OPC_BLEZL */
+ check_insn(ctx, ISA_MIPS2);
gen_compute_branch(ctx, op, 4, rs, rt, imm << 2, 4);
}
break;
@@ -14634,6 +14635,7 @@ static bool decode_opc_legacy(CPUMIPSState *env, DisasContext *ctx)
gen_compute_compact_branch(ctx, op, rs, rt, imm << 2);
} else {
/* OPC_BGTZL */
+ check_insn(ctx, ISA_MIPS2);
gen_compute_branch(ctx, op, 4, rs, rt, imm << 2, 4);
}
break;
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 01/19] target/mips: Check for MIPS II when decoding BLEZL/BGTZL
2026-11-13 16:11 ` [PATCH 01/19] target/mips: Check for MIPS II when decoding BLEZL/BGTZL Philippe Mathieu-Daudé
@ 2026-11-17 18:54 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 18:54 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> Branch-likely instructions were introduced in MIPS II; on MIPS I
> they signal Reserved Instruction. BEQL/BNEL and the REGIMM likely
> forms already check ISA_MIPS2, but BLEZL and BGTZL (non-R6) did not.
>
> Fixes: d9224450208e ("target-mips: Tighten ISA level checks")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/translate.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
> index 10811db827c9..f521e0ec5bd0 100644
> --- a/target/mips/tcg/translate.c
> +++ b/target/mips/tcg/translate.c
> @@ -14621,6 +14621,7 @@ static bool decode_opc_legacy(CPUMIPSState *env, DisasContext *ctx)
> gen_compute_compact_branch(ctx, op, rs, rt, imm << 2);
> } else {
> /* OPC_BLEZL */
> + check_insn(ctx, ISA_MIPS2);
> gen_compute_branch(ctx, op, 4, rs, rt, imm << 2, 4);
> }
> break;
> @@ -14634,6 +14635,7 @@ static bool decode_opc_legacy(CPUMIPSState *env, DisasContext *ctx)
> gen_compute_compact_branch(ctx, op, rs, rt, imm << 2);
> } else {
> /* OPC_BGTZL */
> + check_insn(ctx, ISA_MIPS2);
> gen_compute_branch(ctx, op, 4, rs, rt, imm << 2, 4);
> }
> break;
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 02/19] target/mips: Require rt == 0 when decoding BLEZL/BGTZL
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
2026-11-13 16:11 ` [PATCH 01/19] target/mips: Check for MIPS II when decoding BLEZL/BGTZL Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 18:57 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 03/19] target/mips: Require the MT module for MFTR/MTTR Philippe Mathieu-Daudé
` (17 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The BLEZL and BGTZL encodings fix rt to 00000. The legacy
decoder ignored rt on non-R6 CPUs, executing reserved encodings
as BLEZL/BGTZL instead of raising Reserved Instruction. On R6
these opcodes are the compact branches, which already reject
rt == 0.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/translate.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index f521e0ec5bd0..6e7e1a0f758e 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -14621,6 +14621,10 @@ static bool decode_opc_legacy(CPUMIPSState *env, DisasContext *ctx)
gen_compute_compact_branch(ctx, op, rs, rt, imm << 2);
} else {
/* OPC_BLEZL */
+ if (rt != 0) {
+ gen_reserved_instruction(ctx);
+ break;
+ }
check_insn(ctx, ISA_MIPS2);
gen_compute_branch(ctx, op, 4, rs, rt, imm << 2, 4);
}
@@ -14635,6 +14639,10 @@ static bool decode_opc_legacy(CPUMIPSState *env, DisasContext *ctx)
gen_compute_compact_branch(ctx, op, rs, rt, imm << 2);
} else {
/* OPC_BGTZL */
+ if (rt != 0) {
+ gen_reserved_instruction(ctx);
+ break;
+ }
check_insn(ctx, ISA_MIPS2);
gen_compute_branch(ctx, op, 4, rs, rt, imm << 2, 4);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 02/19] target/mips: Require rt == 0 when decoding BLEZL/BGTZL
2026-11-13 16:11 ` [PATCH 02/19] target/mips: Require rt == 0 " Philippe Mathieu-Daudé
@ 2026-11-17 18:57 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 18:57 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The BLEZL and BGTZL encodings fix rt to 00000. The legacy
> decoder ignored rt on non-R6 CPUs, executing reserved encodings
> as BLEZL/BGTZL instead of raising Reserved Instruction. On R6
> these opcodes are the compact branches, which already reject
> rt == 0.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/translate.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 03/19] target/mips: Require the MT module for MFTR/MTTR
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
2026-11-13 16:11 ` [PATCH 01/19] target/mips: Check for MIPS II when decoding BLEZL/BGTZL Philippe Mathieu-Daudé
2026-11-13 16:11 ` [PATCH 02/19] target/mips: Require rt == 0 " Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:00 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 04/19] target/mips: Reject the PMON encoding on Release 6 Philippe Mathieu-Daudé
` (16 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
MFTR/MTTR must raise Reserved Instruction on processors not
implementing the MT module (MD00378 pp.46/50, Config3.MT:
table 6.21). Use check_cp0_mt(), as done for the other MT
instructions, instead of only check_cp0_enabled().
Fixes: ead9360e2fbc ("Partial support for 34K multithreading")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/translate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index 6e7e1a0f758e..c434da714b0c 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -8588,7 +8588,7 @@ static void gen_cp0(CPUMIPSState *env, DisasContext *ctx, uint32_t opc,
opn = "mthc0";
break;
case OPC_MFTR:
- check_cp0_enabled(ctx);
+ check_cp0_mt(ctx);
if (rd == 0) {
/* Treat as NOP. */
return;
@@ -8598,7 +8598,7 @@ static void gen_cp0(CPUMIPSState *env, DisasContext *ctx, uint32_t opc,
opn = "mftr";
break;
case OPC_MTTR:
- check_cp0_enabled(ctx);
+ check_cp0_mt(ctx);
gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
opn = "mttr";
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 03/19] target/mips: Require the MT module for MFTR/MTTR
2026-11-13 16:11 ` [PATCH 03/19] target/mips: Require the MT module for MFTR/MTTR Philippe Mathieu-Daudé
@ 2026-11-17 19:00 ` Richard Henderson
2026-11-17 22:35 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:00 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> MFTR/MTTR must raise Reserved Instruction on processors not
> implementing the MT module (MD00378 pp.46/50, Config3.MT:
> table 6.21). Use check_cp0_mt(), as done for the other MT
> instructions, instead of only check_cp0_enabled().
>
> Fixes: ead9360e2fbc ("Partial support for 34K multithreading")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/translate.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Surely check_cp0_mt must be enabled for user-only,
not sit behind an ifdef.
r~
>
> diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
> index 6e7e1a0f758e..c434da714b0c 100644
> --- a/target/mips/tcg/translate.c
> +++ b/target/mips/tcg/translate.c
> @@ -8588,7 +8588,7 @@ static void gen_cp0(CPUMIPSState *env, DisasContext *ctx, uint32_t opc,
> opn = "mthc0";
> break;
> case OPC_MFTR:
> - check_cp0_enabled(ctx);
> + check_cp0_mt(ctx);
> if (rd == 0) {
> /* Treat as NOP. */
> return;
> @@ -8598,7 +8598,7 @@ static void gen_cp0(CPUMIPSState *env, DisasContext *ctx, uint32_t opc,
> opn = "mftr";
> break;
> case OPC_MTTR:
> - check_cp0_enabled(ctx);
> + check_cp0_mt(ctx);
> gen_mttr(env, ctx, rd, rt, (ctx->opcode >> 5) & 1,
> ctx->opcode & 0x7, (ctx->opcode >> 4) & 1);
> opn = "mttr";
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [PATCH 03/19] target/mips: Require the MT module for MFTR/MTTR
2026-11-17 19:00 ` Richard Henderson
@ 2026-11-17 22:35 ` Philippe Mathieu-Daudé
2026-11-18 0:01 ` Richard Henderson
0 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-17 22:35 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 17/11/26 20:00, Richard Henderson wrote:
> On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
>> MFTR/MTTR must raise Reserved Instruction on processors not
>> implementing the MT module (MD00378 pp.46/50, Config3.MT:
>> table 6.21). Use check_cp0_mt(), as done for the other MT
>> instructions, instead of only check_cp0_enabled().
>>
>> Fixes: ead9360e2fbc ("Partial support for 34K multithreading")
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>> ---
>> target/mips/tcg/translate.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Surely check_cp0_mt must be enabled for user-only,
> not sit behind an ifdef.
I suppose I got lucky, MIPS_HFLAG_CP0 is never set in user-mode so
the OPC_CP0 dispatch already raises CpU before any MT check could apply.
I'll remove the #ifdef (and fix the Config5/Config3 typo in comment),
thanks!
>
>
> r~
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [PATCH 03/19] target/mips: Require the MT module for MFTR/MTTR
2026-11-17 22:35 ` Philippe Mathieu-Daudé
@ 2026-11-18 0:01 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-18 0:01 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/17/26 14:35, Philippe Mathieu-Daudé wrote:
> On 17/11/26 20:00, Richard Henderson wrote:
>> On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
>>> MFTR/MTTR must raise Reserved Instruction on processors not
>>> implementing the MT module (MD00378 pp.46/50, Config3.MT:
>>> table 6.21). Use check_cp0_mt(), as done for the other MT
>>> instructions, instead of only check_cp0_enabled().
>>>
>>> Fixes: ead9360e2fbc ("Partial support for 34K multithreading")
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>>> ---
>>> target/mips/tcg/translate.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> Surely check_cp0_mt must be enabled for user-only,
>> not sit behind an ifdef.
>
> I suppose I got lucky, MIPS_HFLAG_CP0 is never set in user-mode so
> the OPC_CP0 dispatch already raises CpU before any MT check could apply.
>
> I'll remove the #ifdef (and fix the Config5/Config3 typo in comment),
> thanks!
I meant, check_cp0_mt is undefined for user-only.
How does this compile?
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 04/19] target/mips: Reject the PMON encoding on Release 6
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 03/19] target/mips: Require the MT module for MFTR/MTTR Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:04 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 05/19] target/mips: Enforce alignment and 64-bit CPU for the DSP LX loads Philippe Mathieu-Daudé
` (15 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
On R6, SPECIAL funct 0x05 is LSA, which decodetree matches only
when bits 10:8 are zero. Other encodings fell through to the
non-standard PMON hook instead of raising Reserved Instruction.
Fixes: 0e9524af2dd5 ("target/mips: Remove unreachable [D]LSA code")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/translate.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index c434da714b0c..d1be32bfd9f5 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -13301,6 +13301,10 @@ static void decode_opc_special(CPUMIPSState *env, DisasContext *ctx)
MIPS_INVAL("PMON / selsl");
gen_reserved_instruction(ctx);
#else
+ if (ctx->insn_flags & ISA_MIPS_R6) {
+ gen_reserved_instruction(ctx);
+ break;
+ }
gen_helper_pmon(tcg_env, tcg_constant_i32(sa));
#endif
break;
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 04/19] target/mips: Reject the PMON encoding on Release 6
2026-11-13 16:11 ` [PATCH 04/19] target/mips: Reject the PMON encoding on Release 6 Philippe Mathieu-Daudé
@ 2026-11-17 19:04 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:04 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> On R6, SPECIAL funct 0x05 is LSA, which decodetree matches only
> when bits 10:8 are zero. Other encodings fell through to the
> non-standard PMON hook instead of raising Reserved Instruction.
>
> Fixes: 0e9524af2dd5 ("target/mips: Remove unreachable [D]LSA code")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/translate.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
> index c434da714b0c..d1be32bfd9f5 100644
> --- a/target/mips/tcg/translate.c
> +++ b/target/mips/tcg/translate.c
> @@ -13301,6 +13301,10 @@ static void decode_opc_special(CPUMIPSState *env, DisasContext *ctx)
> MIPS_INVAL("PMON / selsl");
> gen_reserved_instruction(ctx);
> #else
> + if (ctx->insn_flags & ISA_MIPS_R6) {
> + gen_reserved_instruction(ctx);
> + break;
> + }
> gen_helper_pmon(tcg_env, tcg_constant_i32(sa));
> #endif
> break;
Depending on how long this lives, perhaps better as a REMOVED line in
rel6.decode to catch this instead?
Anyway,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 05/19] target/mips: Enforce alignment and 64-bit CPU for the DSP LX loads
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 04/19] target/mips: Reject the PMON encoding on Release 6 Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:05 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 06/19] target/mips: Fix reset into microMIPS mode when Config3.ISA is 3 Philippe Mathieu-Daudé
` (14 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The DSP LHX, LWX and LDX loads require a naturally aligned address
and raise Address Error otherwise (MD00374 r3.01 p.130-131, MD00375
r3.02 p.145). Use the default memop alignment mask for them (strict,
except under linux-user FIXADE); LBUX is a byte access.
The Octeon LX forms share gen_lx() and are unchanged.
LDX belongs to the MIPS64 DSP module only, but was decoded on any DSP
CPU in a 64-bit build, including 32-bit ones such as the 24KE or 74K.
Call check_mips_64() after the DSP Disabled check to raise Reserved
Instruction there.
Fixes: 9b1a1d68d041 ("target-mips: Add ASE DSP load instructions")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/translate.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index d1be32bfd9f5..6966b7e56abb 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -13653,17 +13653,18 @@ static void decode_opc_special3_legacy(CPUMIPSState *env, DisasContext *ctx)
switch (op2) {
#if defined(TARGET_MIPS64)
case OPC_LDX:
- gen_lx(ctx, rd, rs, rt, MO_UQ);
+ check_mips_64(ctx);
+ gen_lx(ctx, rd, rs, rt, MO_UQ | ctx->default_tcg_memop_mask);
break;
#endif
case OPC_LBUX:
gen_lx(ctx, rd, rs, rt, MO_UB);
break;
case OPC_LHX:
- gen_lx(ctx, rd, rs, rt, MO_SW);
+ gen_lx(ctx, rd, rs, rt, MO_SW | ctx->default_tcg_memop_mask);
break;
case OPC_LWX:
- gen_lx(ctx, rd, rs, rt, MO_SL);
+ gen_lx(ctx, rd, rs, rt, MO_SL | ctx->default_tcg_memop_mask);
break;
default: /* Invalid */
MIPS_INVAL("MASK LX");
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 05/19] target/mips: Enforce alignment and 64-bit CPU for the DSP LX loads
2026-11-13 16:11 ` [PATCH 05/19] target/mips: Enforce alignment and 64-bit CPU for the DSP LX loads Philippe Mathieu-Daudé
@ 2026-11-17 19:05 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:05 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The DSP LHX, LWX and LDX loads require a naturally aligned address
> and raise Address Error otherwise (MD00374 r3.01 p.130-131, MD00375
> r3.02 p.145). Use the default memop alignment mask for them (strict,
> except under linux-user FIXADE); LBUX is a byte access.
> The Octeon LX forms share gen_lx() and are unchanged.
>
> LDX belongs to the MIPS64 DSP module only, but was decoded on any DSP
> CPU in a 64-bit build, including 32-bit ones such as the 24KE or 74K.
> Call check_mips_64() after the DSP Disabled check to raise Reserved
> Instruction there.
>
> Fixes: 9b1a1d68d041 ("target-mips: Add ASE DSP load instructions")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/translate.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 06/19] target/mips: Fix reset into microMIPS mode when Config3.ISA is 3
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 05/19] target/mips: Enforce alignment and 64-bit CPU for the DSP LX loads Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:06 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 07/19] target/mips: Fix microMIPS BC2NEZC POOL32I minor opcode Philippe Mathieu-Daudé
` (13 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The Config3.ISA == 3 test ANDs bit 14 and bit 15 as two separate
constants, so it is always false and no CPU resets into microMIPS
mode. Test the 2-bit field instead.
Config3.ISA == 3: both MIPS32 and microMIPS32 are implemented, with
microMIPS32 used out of reset (MD00090 rev 6.02, Table 9.67, p. 248).
Fixes: 0bbc0396809f ("target/mips: Prevent switching mode Config3 ISA bit nanoMIPS")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/cpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index 8ad5e49ade41..324e5989cca1 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -459,7 +459,7 @@ static void mips_cpu_reset_hold(Object *obj, ResetType type)
env->CP0_PWField = 0x02;
}
- if (env->CP0_Config3 & (1 << CP0C3_ISA) & (1 << (CP0C3_ISA + 1))) {
+ if (extract32(env->CP0_Config3, CP0C3_ISA, 2) == 3) {
/* microMIPS on reset when Config3.ISA is 3 */
env->hflags |= MIPS_HFLAG_M16;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 06/19] target/mips: Fix reset into microMIPS mode when Config3.ISA is 3
2026-11-13 16:11 ` [PATCH 06/19] target/mips: Fix reset into microMIPS mode when Config3.ISA is 3 Philippe Mathieu-Daudé
@ 2026-11-17 19:06 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:06 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The Config3.ISA == 3 test ANDs bit 14 and bit 15 as two separate
> constants, so it is always false and no CPU resets into microMIPS
> mode. Test the 2-bit field instead.
>
> Config3.ISA == 3: both MIPS32 and microMIPS32 are implemented, with
> microMIPS32 used out of reset (MD00090 rev 6.02, Table 9.67, p. 248).
>
> Fixes: 0bbc0396809f ("target/mips: Prevent switching mode Config3 ISA bit nanoMIPS")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/cpu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 07/19] target/mips: Fix microMIPS BC2NEZC POOL32I minor opcode
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 06/19] target/mips: Fix reset into microMIPS mode when Config3.ISA is 3 Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:07 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 08/19] target/mips: Fix microMIPS CACHE offset used for ITC tag access Philippe Mathieu-Daudé
` (12 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
BC2NEZC is POOL32I minor opcode 0x0b (bits 25:21 = 01011);
0x0a is BC2EQZC. See MD00582 rev 6.04 p. 131 and MD00594
rev 6.04 p. 145.
Both constants are unreferenced, so there is no functional change.
Fixes: 3a1f426828cd ("target-mips: add microMIPS32 R6 opcode enum")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/micromips_translate.c.inc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/mips/tcg/micromips_translate.c.inc b/target/mips/tcg/micromips_translate.c.inc
index d6a5c2263b56..4ad2b699615e 100644
--- a/target/mips/tcg/micromips_translate.c.inc
+++ b/target/mips/tcg/micromips_translate.c.inc
@@ -513,7 +513,7 @@ enum {
TLTIU = 0x0a,
BC2EQZC = 0x0a,
TGEIU = 0x0b,
- BC2NEZC = 0x0a,
+ BC2NEZC = 0x0b,
TNEI = 0x0c,
R6_SYNCI = 0x0c,
LUI = 0x0d,
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 07/19] target/mips: Fix microMIPS BC2NEZC POOL32I minor opcode
2026-11-13 16:11 ` [PATCH 07/19] target/mips: Fix microMIPS BC2NEZC POOL32I minor opcode Philippe Mathieu-Daudé
@ 2026-11-17 19:07 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:07 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> BC2NEZC is POOL32I minor opcode 0x0b (bits 25:21 = 01011);
> 0x0a is BC2EQZC. See MD00582 rev 6.04 p. 131 and MD00594
> rev 6.04 p. 145.
>
> Both constants are unreferenced, so there is no functional change.
>
> Fixes: 3a1f426828cd ("target-mips: add microMIPS32 R6 opcode enum")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/micromips_translate.c.inc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 08/19] target/mips: Fix microMIPS CACHE offset used for ITC tag access
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 07/19] target/mips: Fix microMIPS BC2NEZC POOL32I minor opcode Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:08 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 09/19] target/mips: Add the NMS check to the nanoMIPS CACHE instruction Philippe Mathieu-Daudé
` (11 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
CACHE is encoded in POOL32B with a 9-bit signed offset in bits 8:0
(MD00582 rev 6.04, p. 144). The decoder passed the generic 'imm'
(the low 16 bits of the opcode), which also holds the minor opcode
and reserved bits 15:9, so the ITC tag access used a wrong effective
address. Extract the 9-bit offset, as done for CACHEE.
Fixes: 0d74a222c27e ("target-mips: make ITC Configuration Tags accessible")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/micromips_translate.c.inc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/mips/tcg/micromips_translate.c.inc b/target/mips/tcg/micromips_translate.c.inc
index 4ad2b699615e..21374e3ec60f 100644
--- a/target/mips/tcg/micromips_translate.c.inc
+++ b/target/mips/tcg/micromips_translate.c.inc
@@ -1820,7 +1820,7 @@ static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx)
case CACHE:
check_cp0_enabled(ctx);
if (ctx->hflags & MIPS_HFLAG_ITC_CACHE) {
- gen_cache_operation(ctx, rt, rs, imm);
+ gen_cache_operation(ctx, rt, rs, SIMM(ctx->opcode, 0, 9));
}
break;
case LWC2:
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 08/19] target/mips: Fix microMIPS CACHE offset used for ITC tag access
2026-11-13 16:11 ` [PATCH 08/19] target/mips: Fix microMIPS CACHE offset used for ITC tag access Philippe Mathieu-Daudé
@ 2026-11-17 19:08 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:08 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> CACHE is encoded in POOL32B with a 9-bit signed offset in bits 8:0
> (MD00582 rev 6.04, p. 144). The decoder passed the generic 'imm'
> (the low 16 bits of the opcode), which also holds the minor opcode
> and reserved bits 15:9, so the ITC tag access used a wrong effective
> address. Extract the 9-bit offset, as done for CACHEE.
>
> Fixes: 0d74a222c27e ("target-mips: make ITC Configuration Tags accessible")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/micromips_translate.c.inc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 09/19] target/mips: Add the NMS check to the nanoMIPS CACHE instruction
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 08/19] target/mips: Fix microMIPS CACHE offset used for ITC tag access Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:12 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 10/19] target/mips: Fix nanoMIPS BPOSGE32C branch offset sign extension Philippe Mathieu-Daudé
` (10 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
CACHE and CACHEE share pseudo-code raising Reserved Instruction on
NMS cores without caches, but only CACHEE performed that check.
See MD01247 rev 01.01, "CACHE/CACHEE" (printed page 63).
Fixes: 8f1d9b6d6397 ("target/mips: Add emulation of nanoMIPS 32-bit LD/ST")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 1 +
1 file changed, 1 insertion(+)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index c883b5514f1c..20e96f2ad9be 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -4131,6 +4131,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
}
break;
case NM_CACHE:
+ check_nms_dl_il_sl_tl_l2c(ctx);
check_cp0_enabled(ctx);
if (ctx->hflags & MIPS_HFLAG_ITC_CACHE) {
gen_cache_operation(ctx, rt, rs, s);
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 09/19] target/mips: Add the NMS check to the nanoMIPS CACHE instruction
2026-11-13 16:11 ` [PATCH 09/19] target/mips: Add the NMS check to the nanoMIPS CACHE instruction Philippe Mathieu-Daudé
@ 2026-11-17 19:12 ` Richard Henderson
2026-11-17 23:07 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:12 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> CACHE and CACHEE share pseudo-code raising Reserved Instruction on
> NMS cores without caches, but only CACHEE performed that check.
> See MD01247 rev 01.01, "CACHE/CACHEE" (printed page 63).
>
> Fixes: 8f1d9b6d6397 ("target/mips: Add emulation of nanoMIPS 32-bit LD/ST")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
> index c883b5514f1c..20e96f2ad9be 100644
> --- a/target/mips/tcg/nanomips_translate.c.inc
> +++ b/target/mips/tcg/nanomips_translate.c.inc
> @@ -4131,6 +4131,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
> }
> break;
> case NM_CACHE:
> + check_nms_dl_il_sl_tl_l2c(ctx);
> check_cp0_enabled(ctx);
> if (ctx->hflags & MIPS_HFLAG_ITC_CACHE) {
> gen_cache_operation(ctx, rt, rs, s);
Also missing check_eva.
Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [PATCH 09/19] target/mips: Add the NMS check to the nanoMIPS CACHE instruction
2026-11-17 19:12 ` Richard Henderson
@ 2026-11-17 23:07 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-17 23:07 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 17/11/26 20:12, Richard Henderson wrote:
> On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
>> CACHE and CACHEE share pseudo-code raising Reserved Instruction on
>> NMS cores without caches, but only CACHEE performed that check.
>> See MD01247 rev 01.01, "CACHE/CACHEE" (printed page 63).
>>
>> Fixes: 8f1d9b6d6397 ("target/mips: Add emulation of nanoMIPS 32-bit
>> LD/ST")
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>> ---
>> target/mips/tcg/nanomips_translate.c.inc | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/
>> tcg/nanomips_translate.c.inc
>> index c883b5514f1c..20e96f2ad9be 100644
>> --- a/target/mips/tcg/nanomips_translate.c.inc
>> +++ b/target/mips/tcg/nanomips_translate.c.inc
>> @@ -4131,6 +4131,7 @@ static int
>> decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
>> }
>> break;
>> case NM_CACHE:
>> + check_nms_dl_il_sl_tl_l2c(ctx);
>> check_cp0_enabled(ctx);
>> if (ctx->hflags & MIPS_HFLAG_ITC_CACHE) {
>> gen_cache_operation(ctx, rt, rs, s);
>
> Also missing check_eva.
Hmm looking further commit 84c2fdc397b6 ("target/mips: Fix CACHEE opcode
(CACHE using EVA addressing)") added the check at an invalid position;
we check EVA -> CP0 -> NMS; the spec checks NMS -> EVA -> CP0 (in
MD01247 rev 01.01 p.63 pseudo-code block). On a core with NMS=1, no
caches, EVA=1 and CP0 disabled, the spec says RI while we deliver
Coprocessor Unusable.
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 10/19] target/mips: Fix nanoMIPS BPOSGE32C branch offset sign extension
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 09/19] target/mips: Add the NMS check to the nanoMIPS CACHE instruction Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:15 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 11/19] target/mips: Pass the right instruction size for nanoMIPS RESTORE.JRC Philippe Mathieu-Daudé
` (9 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The BPOSGE32C offset is a signed value s[14:1], with s[14] stored in
instruction bit 0 (MD01249 rev 0.04, "BPOSGE32C", printed page 88).
The decoder zero-extended it, so backward branches went to the wrong
target.
Reuse the sign-extended offset already computed by the P.BR3A pool.
Fixes: 6d033ca7513d ("target/mips: Add emulation of DSP ASE for nanoMIPS")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index 20e96f2ad9be..3e326afd0827 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -4365,13 +4365,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
break;
case NM_BPOSGE32C:
check_dsp_r3(ctx);
- {
- imm = extract32(ctx->opcode, 1, 13)
- | extract32(ctx->opcode, 0, 1) << 13;
-
- gen_compute_branch_nm(ctx, OPC_BPOSGE32, 4, -1, -2,
- imm << 1);
- }
+ gen_compute_branch_nm(ctx, OPC_BPOSGE32, 4, -1, -2, s);
break;
default:
gen_reserved_instruction(ctx);
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 10/19] target/mips: Fix nanoMIPS BPOSGE32C branch offset sign extension
2026-11-13 16:11 ` [PATCH 10/19] target/mips: Fix nanoMIPS BPOSGE32C branch offset sign extension Philippe Mathieu-Daudé
@ 2026-11-17 19:15 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:15 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The BPOSGE32C offset is a signed value s[14:1], with s[14] stored in
> instruction bit 0 (MD01249 rev 0.04, "BPOSGE32C", printed page 88).
> The decoder zero-extended it, so backward branches went to the wrong
> target.
>
> Reuse the sign-extended offset already computed by the P.BR3A pool.
>
> Fixes: 6d033ca7513d ("target/mips: Add emulation of DSP ASE for nanoMIPS")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 11/19] target/mips: Pass the right instruction size for nanoMIPS RESTORE.JRC
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 10/19] target/mips: Fix nanoMIPS BPOSGE32C branch offset sign extension Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:15 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 12/19] target/mips: Fix nanoMIPS BC1EQZC/BC1NEZC always raising RI Philippe Mathieu-Daudé
` (8 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
RESTORE.JRC[32] is a 32-bit instruction (MD01247, printed page 155),
but gen_compute_branch_nm() was called with an instruction size of 2
(copy/paste from the 16-bit form), which wrongly set MIPS_HFLAG_B16.
No functional effect: gen_branch() clears MIPS_HFLAG_B16 before
anything reads it.
Fixes: c02809830346 ("target/mips: Add emulation of some nanoMIPS 32-bit instr")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index 3e326afd0827..5941889b617b 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -3745,7 +3745,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
extract32(ctx->opcode, 2, 1),
extract32(ctx->opcode, 3, 9) << 3);
if ((ctx->opcode & 3) == NM_RESTORE_JRC) {
- gen_compute_branch_nm(ctx, OPC_JR, 2, 31, 0, 0);
+ gen_compute_branch_nm(ctx, OPC_JR, 4, 31, 0, 0);
}
break;
default:
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 11/19] target/mips: Pass the right instruction size for nanoMIPS RESTORE.JRC
2026-11-13 16:11 ` [PATCH 11/19] target/mips: Pass the right instruction size for nanoMIPS RESTORE.JRC Philippe Mathieu-Daudé
@ 2026-11-17 19:15 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:15 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> RESTORE.JRC[32] is a 32-bit instruction (MD01247, printed page 155),
> but gen_compute_branch_nm() was called with an instruction size of 2
> (copy/paste from the 16-bit form), which wrongly set MIPS_HFLAG_B16.
>
> No functional effect: gen_branch() clears MIPS_HFLAG_B16 before
> anything reads it.
>
> Fixes: c02809830346 ("target/mips: Add emulation of some nanoMIPS 32-bit instr")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 12/19] target/mips: Fix nanoMIPS BC1EQZC/BC1NEZC always raising RI
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 11/19] target/mips: Pass the right instruction size for nanoMIPS RESTORE.JRC Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:16 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 13/19] target/mips: Fix nanoMIPS BEQC16/BNEC16 corner cases Philippe Mathieu-Daudé
` (7 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The P.BR3A decoder passes OPC_BC1EQZ / OPC_BC1NEZ (the MIPS CP1
opcodes) to gen_compute_branch_cp1_nm(), but the function switches
on the nanoMIPS pool values NM_BC1EQZC (0) and NM_BC1NEZC (1). No
call could match, so both instructions raised Reserved Instruction.
The P.BR3A encoding is in MD01247 rev 01.01, printed page 288.
Switch on the values the callers pass.
Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index 5941889b617b..f9dc573dbb01 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -2558,11 +2558,11 @@ static void gen_compute_branch_cp1_nm(DisasContext *ctx, uint32_t op,
btarget = addr_add(ctx, ctx->base.pc_next + 4, offset);
switch (op) {
- case NM_BC1EQZC:
+ case OPC_BC1EQZ:
tcg_gen_xori_i64(t0, t0, 1);
ctx->hflags |= MIPS_HFLAG_BC;
break;
- case NM_BC1NEZC:
+ case OPC_BC1NEZ:
/* t0 already set */
ctx->hflags |= MIPS_HFLAG_BC;
break;
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 12/19] target/mips: Fix nanoMIPS BC1EQZC/BC1NEZC always raising RI
2026-11-13 16:11 ` [PATCH 12/19] target/mips: Fix nanoMIPS BC1EQZC/BC1NEZC always raising RI Philippe Mathieu-Daudé
@ 2026-11-17 19:16 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:16 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The P.BR3A decoder passes OPC_BC1EQZ / OPC_BC1NEZ (the MIPS CP1
> opcodes) to gen_compute_branch_cp1_nm(), but the function switches
> on the nanoMIPS pool values NM_BC1EQZC (0) and NM_BC1NEZC (1). No
> call could match, so both instructions raised Reserved Instruction.
>
> The P.BR3A encoding is in MD01247 rev 01.01, printed page 288.
> Switch on the values the callers pass.
>
> Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 13/19] target/mips: Fix nanoMIPS BEQC16/BNEC16 corner cases
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 12/19] target/mips: Fix nanoMIPS BC1EQZC/BC1NEZC always raising RI Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:18 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 14/19] target/mips: Fix nanoMIPS BLTUC with rs == $zero Philippe Mathieu-Daudé
` (6 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
BNEC[16] with identical registers is never taken, so it is a NOP.
gen_compute_branch_nm() instead wrote $ra and skipped the next
4 bytes as if it were a MIPS branch-and-link-likely.
Also raise Reserved Instruction on NMS cores, where the 16-bit
forms are not available.
Fixes: 764371d24c51 ("target/mips: Add emulation of nanoMIPS 16-bit branch")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index f9dc573dbb01..25d57e75a0b0 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -4756,6 +4756,10 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx)
/* P16.BRI */
uint32_t opc = extract32(ctx->opcode, 4, 3) <
extract32(ctx->opcode, 7, 3) ? OPC_BEQ : OPC_BNE;
+ check_nms(ctx);
+ if (rs == rt) {
+ break;
+ }
gen_compute_branch_nm(ctx, opc, 2, rs, rt,
extract32(ctx->opcode, 0, 4) << 1);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 13/19] target/mips: Fix nanoMIPS BEQC16/BNEC16 corner cases
2026-11-13 16:11 ` [PATCH 13/19] target/mips: Fix nanoMIPS BEQC16/BNEC16 corner cases Philippe Mathieu-Daudé
@ 2026-11-17 19:18 ` Richard Henderson
2026-11-17 22:37 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:18 UTC (permalink / raw)
To: qemu-devel
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> BNEC[16] with identical registers is never taken, so it is a NOP.
> gen_compute_branch_nm() instead wrote $ra and skipped the next
> 4 bytes as if it were a MIPS branch-and-link-likely.
>
> Also raise Reserved Instruction on NMS cores, where the 16-bit
> forms are not available.
>
> Fixes: 764371d24c51 ("target/mips: Add emulation of nanoMIPS 16-bit branch")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
> index f9dc573dbb01..25d57e75a0b0 100644
> --- a/target/mips/tcg/nanomips_translate.c.inc
> +++ b/target/mips/tcg/nanomips_translate.c.inc
> @@ -4756,6 +4756,10 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx)
> /* P16.BRI */
> uint32_t opc = extract32(ctx->opcode, 4, 3) <
> extract32(ctx->opcode, 7, 3) ? OPC_BEQ : OPC_BNE;
> + check_nms(ctx);
> + if (rs == rt) {
> + break;
> + }
> gen_compute_branch_nm(ctx, opc, 2, rs, rt,
> extract32(ctx->opcode, 0, 4) << 1);
> }
Surely not. BNE x,x is never taken, but BEQ x,x is.
r~
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [PATCH 13/19] target/mips: Fix nanoMIPS BEQC16/BNEC16 corner cases
2026-11-17 19:18 ` Richard Henderson
@ 2026-11-17 22:37 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-17 22:37 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
On 17/11/26 20:18, Richard Henderson wrote:
> On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
>> BNEC[16] with identical registers is never taken, so it is a NOP.
>> gen_compute_branch_nm() instead wrote $ra and skipped the next
>> 4 bytes as if it were a MIPS branch-and-link-likely.
>>
>> Also raise Reserved Instruction on NMS cores, where the 16-bit
>> forms are not available.
>>
>> Fixes: 764371d24c51 ("target/mips: Add emulation of nanoMIPS 16-bit
>> branch")
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>> ---
>> target/mips/tcg/nanomips_translate.c.inc | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/
>> tcg/nanomips_translate.c.inc
>> index f9dc573dbb01..25d57e75a0b0 100644
>> --- a/target/mips/tcg/nanomips_translate.c.inc
>> +++ b/target/mips/tcg/nanomips_translate.c.inc
>> @@ -4756,6 +4756,10 @@ static int decode_isa_nanomips(CPUMIPSState
>> *env, DisasContext *ctx)
>> /* P16.BRI */
>> uint32_t opc = extract32(ctx->opcode, 4, 3) <
>> extract32(ctx->opcode, 7, 3) ?
>> OPC_BEQ : OPC_BNE;
>> + check_nms(ctx);
>> + if (rs == rt) {
>> + break;
>> + }
>> gen_compute_branch_nm(ctx, opc, 2, rs, rt,
>> extract32(ctx->opcode, 0, 4)
>> << 1);
>> }
>
> Surely not. BNE x,x is never taken, but BEQ x,x is.
Right... Updated as:
- if (rs == rt) {
+ if (opc == OPC_BNE && rs == rt) {
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 14/19] target/mips: Fix nanoMIPS BLTUC with rs == $zero
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 13/19] target/mips: Fix nanoMIPS BEQC16/BNEC16 corner cases Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:20 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 15/19] target/mips: Pass the nanoMIPS BREAK code to generate_exception_break() Philippe Mathieu-Daudé
` (5 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
BLTUC rs, rt branches if unsigned(rs) < unsigned(rt) (MD01247 p.55).
With rs == $zero it is taken when rt != 0, but the decoder treated
it as a NOP. Only skip the branch when rs == rt (never taken).
Reaching the generic path exposes the R6 BGTZALC/BLTZALC-like special
cases in gen_compute_compact_branch_nm(), which set $ra and compare as
signed; nanoMIPS has neither. Drop them from the unsigned branches
(they were unreachable for BGEUC, which the decoder maps to BC/BEQZC).
Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 34 +++---------------------
1 file changed, 3 insertions(+), 31 deletions(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index 25d57e75a0b0..524972b24a98 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -2419,18 +2419,8 @@ static void gen_compute_compact_branch_nm(DisasContext *ctx, uint32_t opc,
/* compact branch */
case OPC_BGEC:
case OPC_BLTC:
- gen_load_gpr(t0, rs);
- gen_load_gpr(t1, rt);
- bcond_compute = 1;
- ctx->btarget = addr_add(ctx, ctx->base.pc_next + 4, offset);
- break;
case OPC_BGEUC:
case OPC_BLTUC:
- if (rs == 0 || rs == rt) {
- /* OPC_BLEZALC, OPC_BGEZALC */
- /* OPC_BGTZALC, OPC_BLTZALC */
- tcg_gen_movi_tl(cpu_gpr[31], ctx->base.pc_next + 4);
- }
gen_load_gpr(t0, rs);
gen_load_gpr(t1, rt);
bcond_compute = 1;
@@ -2476,28 +2466,10 @@ static void gen_compute_compact_branch_nm(DisasContext *ctx, uint32_t opc,
switch (opc) {
case OPC_BGEUC:
- if (rs == 0 && rt != 0) {
- /* OPC_BLEZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LE), t1, 0, fs);
- } else if (rs != 0 && rt != 0 && rs == rt) {
- /* OPC_BGEZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GE), t1, 0, fs);
- } else {
- /* OPC_BGEUC */
- tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GEU), t0, t1, fs);
- }
+ tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_GEU), t0, t1, fs);
break;
case OPC_BLTUC:
- if (rs == 0 && rt != 0) {
- /* OPC_BGTZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_GT), t1, 0, fs);
- } else if (rs != 0 && rt != 0 && rs == rt) {
- /* OPC_BLTZALC */
- tcg_gen_brcondi_tl(tcg_invert_cond(TCG_COND_LT), t1, 0, fs);
- } else {
- /* OPC_BLTUC */
- tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LTU), t0, t1, fs);
- }
+ tcg_gen_brcond_tl(tcg_invert_cond(TCG_COND_LTU), t0, t1, fs);
break;
case OPC_BGEC:
if (rs == 0 && rt != 0) {
@@ -4414,7 +4386,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
}
break;
case NM_BLTUC:
- if (rs == 0 || rs == rt) {
+ if (rs == rt) {
/* NOP */
ctx->hflags |= MIPS_HFLAG_FBNSLOT;
} else {
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 14/19] target/mips: Fix nanoMIPS BLTUC with rs == $zero
2026-11-13 16:11 ` [PATCH 14/19] target/mips: Fix nanoMIPS BLTUC with rs == $zero Philippe Mathieu-Daudé
@ 2026-11-17 19:20 ` Richard Henderson
2026-11-17 22:51 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:20 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> /* compact branch */
> case OPC_BGEC:
> case OPC_BLTC:
> - gen_load_gpr(t0, rs);
> - gen_load_gpr(t1, rt);
> - bcond_compute = 1;
> - ctx->btarget = addr_add(ctx, ctx->base.pc_next + 4, offset);
> - break;
I don't understand why you're discarding bcond_compute?
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* Re: [PATCH 14/19] target/mips: Fix nanoMIPS BLTUC with rs == $zero
2026-11-17 19:20 ` Richard Henderson
@ 2026-11-17 22:51 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-17 22:51 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 17/11/26 20:20, Richard Henderson wrote:
> On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
>> /* compact branch */
>> case OPC_BGEC:
>> case OPC_BLTC:
>> - gen_load_gpr(t0, rs);
>> - gen_load_gpr(t1, rt);
>> - bcond_compute = 1;
>> - ctx->btarget = addr_add(ctx, ctx->base.pc_next + 4, offset);
>> - break;
>
> I don't understand why you're discarding bcond_compute?
Restoring context:
diff --git a/target/mips/tcg/nanomips_translate.c.inc
b/target/mips/tcg/nanomips_translate.c.inc
index 25d57e75a0b0..524972b24a98 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -2419,18 +2419,8 @@ static void
gen_compute_compact_branch_nm(DisasContext *ctx, uint32_t opc,
/* compact branch */
case OPC_BGEC:
case OPC_BLTC:
- gen_load_gpr(t0, rs);
- gen_load_gpr(t1, rt);
- bcond_compute = 1;
- ctx->btarget = addr_add(ctx, ctx->base.pc_next + 4, offset);
- break;
// now fall thru ...
case OPC_BGEUC:
case OPC_BLTUC:
- if (rs == 0 || rs == rt) {
- /* OPC_BLEZALC, OPC_BGEZALC */
- /* OPC_BGTZALC, OPC_BLTZALC */
- tcg_gen_movi_tl(cpu_gpr[31], ctx->base.pc_next + 4);
- }
// ... here
gen_load_gpr(t0, rs);
gen_load_gpr(t1, rt);
bcond_compute = 1;
I'll amend to description for clarity:
The deleted BGEC/BLTC lines are duplicated verbatim by the BGEUC/BLTUC
block they now fall through into, so bcond_compute/btarget handling is
unchanged.
^ permalink raw reply related [flat|nested] 48+ messages in thread
* [PATCH 15/19] target/mips: Pass the nanoMIPS BREAK code to generate_exception_break()
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (13 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 14/19] target/mips: Fix nanoMIPS BLTUC with rs == $zero Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:23 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 16/19] target/mips: Decode 6-bit bit number of nanoMIPS BBEQZC/BBNEZC Philippe Mathieu-Daudé
` (4 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The nanoMIPS BREAK[32] and BREAK[16] decoders call
generate_exception_end() and drop the break code, leaving a
stale env->error_code for linux-user. Pass the encoded 'code'
19 bits for BREAK[32], 3 bits for BREAK[16] (MD01247 rev 01.01,
p.59).
Complete 6f3533dd1b6a ("target/mips: Extract break code into
env->error_code").
Fixes: c02809830346 ("target/mips: Add emulation of some nanoMIPS 32-bit")
Fixes: 8869ad02bfd9 ("target/mips: Add emulation of nanoMIPS 16-bit misc")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index 524972b24a98..3612c68561fd 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -3545,7 +3545,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
}
break;
case NM_BREAK:
- generate_exception_end(ctx, EXCP_BREAK);
+ generate_exception_break(ctx, extract32(ctx->opcode, 0, 19));
break;
case NM_SDBBP:
if (is_uhi(ctx, extract32(ctx->opcode, 0, 19))) {
@@ -4481,7 +4481,7 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx)
}
break;
case NM_BREAK16:
- generate_exception_end(ctx, EXCP_BREAK);
+ generate_exception_break(ctx, extract32(ctx->opcode, 0, 3));
break;
case NM_SDBBP16:
if (is_uhi(ctx, extract32(ctx->opcode, 0, 3))) {
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 15/19] target/mips: Pass the nanoMIPS BREAK code to generate_exception_break()
2026-11-13 16:11 ` [PATCH 15/19] target/mips: Pass the nanoMIPS BREAK code to generate_exception_break() Philippe Mathieu-Daudé
@ 2026-11-17 19:23 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:23 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The nanoMIPS BREAK[32] and BREAK[16] decoders call
> generate_exception_end() and drop the break code, leaving a
> stale env->error_code for linux-user. Pass the encoded 'code'
> 19 bits for BREAK[32], 3 bits for BREAK[16] (MD01247 rev 01.01,
> p.59).
>
> Complete 6f3533dd1b6a ("target/mips: Extract break code into
> env->error_code").
>
> Fixes: c02809830346 ("target/mips: Add emulation of some nanoMIPS 32-bit")
> Fixes: 8869ad02bfd9 ("target/mips: Add emulation of nanoMIPS 16-bit misc")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 16/19] target/mips: Decode 6-bit bit number of nanoMIPS BBEQZC/BBNEZC
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (14 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 15/19] target/mips: Pass the nanoMIPS BREAK code to generate_exception_break() Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:24 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 17/19] target/mips: Don't set forbidden slot on never-taken nanoMIPS branches Philippe Mathieu-Daudé
` (3 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
BBEQZC (MD01247 p.38) and BBNEZC (p.39) encode the bit number in
bits 16:11; bit 17 is 'x' (don't care). The decoder used the 7-bit
immediate (17:11) of the other P.BRI branches, so a set bit 17 gave
a bit number >= 64 and raised Reserved Instruction on cores without
64-bit operations. Decode only 6 bits for these two; BEQIC and the
other P.BRI branches really have a 7-bit u field.
Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index 3612c68561fd..68e9ca9cdb03 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -4403,10 +4403,12 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
{
int32_t s = sextract32(ctx->opcode, 0, 1) << 11 |
extract32(ctx->opcode, 1, 10) << 1;
- uint32_t u = extract32(ctx->opcode, 11, 7);
+ uint32_t opc = extract32(ctx->opcode, 18, 3);
+ uint32_t u = extract32(ctx->opcode, 11,
+ (opc == NM_BBEQZC ||
+ opc == NM_BBNEZC) ? 6 : 7);
- gen_compute_imm_branch(ctx, extract32(ctx->opcode, 18, 3),
- rt, u, s);
+ gen_compute_imm_branch(ctx, opc, rt, u, s);
}
break;
default:
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 16/19] target/mips: Decode 6-bit bit number of nanoMIPS BBEQZC/BBNEZC
2026-11-13 16:11 ` [PATCH 16/19] target/mips: Decode 6-bit bit number of nanoMIPS BBEQZC/BBNEZC Philippe Mathieu-Daudé
@ 2026-11-17 19:24 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:24 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> BBEQZC (MD01247 p.38) and BBNEZC (p.39) encode the bit number in
> bits 16:11; bit 17 is 'x' (don't care). The decoder used the 7-bit
> immediate (17:11) of the other P.BRI branches, so a set bit 17 gave
> a bit number >= 64 and raised Reserved Instruction on cores without
> 64-bit operations. Decode only 6 bits for these two; BEQIC and the
> other P.BRI branches really have a 7-bit u field.
>
> Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 17/19] target/mips: Don't set forbidden slot on never-taken nanoMIPS branches
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (15 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 16/19] target/mips: Decode 6-bit bit number of nanoMIPS BBEQZC/BBNEZC Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:26 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 18/19] target/mips: Do not sign-extend partial LWR results on Octeon Philippe Mathieu-Daudé
` (2 subsequent siblings)
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
BNEC (rs == rt), BLTC (rs == rt != 0) and BLTUC (rs == rt) are NOPs,
but flagged the next insn as a forbidden slot. A following branch
then raised RI, and a fault there got a wrong EPC/Cause.BD. nanoMIPS
has neither delay nor forbidden slots (MD01247 p.12), so just fall
through.
Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
Fixes: 14668cfaaf4d ("target/mips: Fix emulation of nanoMIPS BNEC[32]")
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/nanomips_translate.c.inc | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
index 68e9ca9cdb03..72d72f6f84a0 100644
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -4370,26 +4370,20 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
switch (extract32(ctx->opcode, 14, 2)) {
case NM_BNEC:
check_nms(ctx);
- if (rs == rt) {
- /* NOP */
- ctx->hflags |= MIPS_HFLAG_FBNSLOT;
- } else {
+ /* rs == rt is never taken: NOP */
+ if (rs != rt) {
gen_compute_branch_nm(ctx, OPC_BNE, 4, rs, rt, s);
}
break;
case NM_BLTC:
- if (rs != 0 && rt != 0 && rs == rt) {
- /* NOP */
- ctx->hflags |= MIPS_HFLAG_FBNSLOT;
- } else {
+ /* rs == rt != 0 is never taken: NOP */
+ if (rs == 0 || rt == 0 || rs != rt) {
gen_compute_compact_branch_nm(ctx, OPC_BLTC, rs, rt, s);
}
break;
case NM_BLTUC:
- if (rs == rt) {
- /* NOP */
- ctx->hflags |= MIPS_HFLAG_FBNSLOT;
- } else {
+ /* rs == rt is never taken: NOP */
+ if (rs != rt) {
gen_compute_compact_branch_nm(ctx, OPC_BLTUC, rs, rt, s);
}
break;
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 17/19] target/mips: Don't set forbidden slot on never-taken nanoMIPS branches
2026-11-13 16:11 ` [PATCH 17/19] target/mips: Don't set forbidden slot on never-taken nanoMIPS branches Philippe Mathieu-Daudé
@ 2026-11-17 19:26 ` Richard Henderson
2026-11-17 22:59 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:26 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> BNEC (rs == rt), BLTC (rs == rt != 0) and BLTUC (rs == rt) are NOPs,
> but flagged the next insn as a forbidden slot. A following branch
> then raised RI, and a fault there got a wrong EPC/Cause.BD. nanoMIPS
> has neither delay nor forbidden slots (MD01247 p.12), so just fall
> through.
>
> Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit branch")
> Fixes: 14668cfaaf4d ("target/mips: Fix emulation of nanoMIPS BNEC[32]")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/nanomips_translate.c.inc | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
The problem would appear to be elsewhere: Why would
gen_compute_branch_nm *ever* set forbidden slot, given that nanomips
doesn't have them?
r~
>
> diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc
> index 68e9ca9cdb03..72d72f6f84a0 100644
> --- a/target/mips/tcg/nanomips_translate.c.inc
> +++ b/target/mips/tcg/nanomips_translate.c.inc
> @@ -4370,26 +4370,20 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
> switch (extract32(ctx->opcode, 14, 2)) {
> case NM_BNEC:
> check_nms(ctx);
> - if (rs == rt) {
> - /* NOP */
> - ctx->hflags |= MIPS_HFLAG_FBNSLOT;
> - } else {
> + /* rs == rt is never taken: NOP */
> + if (rs != rt) {
> gen_compute_branch_nm(ctx, OPC_BNE, 4, rs, rt, s);
> }
> break;
> case NM_BLTC:
> - if (rs != 0 && rt != 0 && rs == rt) {
> - /* NOP */
> - ctx->hflags |= MIPS_HFLAG_FBNSLOT;
> - } else {
> + /* rs == rt != 0 is never taken: NOP */
> + if (rs == 0 || rt == 0 || rs != rt) {
> gen_compute_compact_branch_nm(ctx, OPC_BLTC, rs, rt, s);
> }
> break;
> case NM_BLTUC:
> - if (rs == rt) {
> - /* NOP */
> - ctx->hflags |= MIPS_HFLAG_FBNSLOT;
> - } else {
> + /* rs == rt is never taken: NOP */
> + if (rs != rt) {
> gen_compute_compact_branch_nm(ctx, OPC_BLTUC, rs, rt, s);
> }
> break;
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [PATCH 17/19] target/mips: Don't set forbidden slot on never-taken nanoMIPS branches
2026-11-17 19:26 ` Richard Henderson
@ 2026-11-17 22:59 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-17 22:59 UTC (permalink / raw)
To: Richard Henderson, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 17/11/26 20:26, Richard Henderson wrote:
> On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
>> BNEC (rs == rt), BLTC (rs == rt != 0) and BLTUC (rs == rt) are NOPs,
>> but flagged the next insn as a forbidden slot. A following branch
>> then raised RI, and a fault there got a wrong EPC/Cause.BD. nanoMIPS
>> has neither delay nor forbidden slots (MD01247 p.12), so just fall
>> through.
>>
>> Fixes: 11d0fc10b7ef ("target/mips: Add emulation of nanoMIPS 32-bit
>> branch")
>> Fixes: 14668cfaaf4d ("target/mips: Fix emulation of nanoMIPS BNEC[32]")
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>> ---
>> target/mips/tcg/nanomips_translate.c.inc | 18 ++++++------------
>> 1 file changed, 6 insertions(+), 12 deletions(-)
>
> The problem would appear to be elsewhere: Why would
> gen_compute_branch_nm *ever* set forbidden slot, given that nanomips
> doesn't have them?
forbidden slots is not set in the branch helpers path but in the
decoder, see for example commit 14668cfaaf4d in the NOP path:
--- a/target/mips/tcg/nanomips_translate.c.inc
+++ b/target/mips/tcg/nanomips_translate.c.inc
@@ -4528,7 +4528,12 @@ static int decode_nanomips_32_48_opc(CPUMIPSState
*env, DisasContext *ctx)
switch (extract32(ctx->opcode, 14, 2)) {
case NM_BNEC:
check_nms(ctx);
- gen_compute_branch_nm(ctx, OPC_BNE, 4, rs, rt, s);
+ if (rs == rt) {
+ /* NOP */
+ ctx->hflags |= MIPS_HFLAG_FBNSLOT;
+ } else {
+ gen_compute_branch_nm(ctx, OPC_BNE, 4, rs, rt, s);
+ }
break;
I'll reword for clarity as:
The decoder NOP special-cases for BNEC/BLTC/BLTUC (rs == rt) set
MIPS_HFLAG_FBNSLOT, an idiom imported from the R6 compact-branch
decoder; nanoMIPS has neither delay nor forbidden slots (MD01247
p.12). With the flag set, the next branch hit gen_branch()'s default
case and raised RI, wrongly reported with Cause.BD set and EPC at
the NOP branch (stale hflags snapshotted by save_cpu_state()).
Fall through instead: no nanoMIPS path sets MIPS_HFLAG_FBNSLOT
anymore.
>
>
> r~
>
>>
>> diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/
>> tcg/nanomips_translate.c.inc
>> index 68e9ca9cdb03..72d72f6f84a0 100644
>> --- a/target/mips/tcg/nanomips_translate.c.inc
>> +++ b/target/mips/tcg/nanomips_translate.c.inc
>> @@ -4370,26 +4370,20 @@ static int
>> decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
>> switch (extract32(ctx->opcode, 14, 2)) {
>> case NM_BNEC:
>> check_nms(ctx);
>> - if (rs == rt) {
>> - /* NOP */
>> - ctx->hflags |= MIPS_HFLAG_FBNSLOT;
>> - } else {
>> + /* rs == rt is never taken: NOP */
>> + if (rs != rt) {
>> gen_compute_branch_nm(ctx, OPC_BNE, 4, rs, rt, s);
>> }
>> break;
>> case NM_BLTC:
>> - if (rs != 0 && rt != 0 && rs == rt) {
>> - /* NOP */
>> - ctx->hflags |= MIPS_HFLAG_FBNSLOT;
>> - } else {
>> + /* rs == rt != 0 is never taken: NOP */
>> + if (rs == 0 || rt == 0 || rs != rt) {
>> gen_compute_compact_branch_nm(ctx, OPC_BLTC, rs,
>> rt, s);
>> }
>> break;
>> case NM_BLTUC:
>> - if (rs == rt) {
>> - /* NOP */
>> - ctx->hflags |= MIPS_HFLAG_FBNSLOT;
>> - } else {
>> + /* rs == rt is never taken: NOP */
>> + if (rs != rt) {
>> gen_compute_compact_branch_nm(ctx, OPC_BLTUC,
>> rs, rt, s);
>> }
>> break;
>
>
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 18/19] target/mips: Do not sign-extend partial LWR results on Octeon
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (16 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 17/19] target/mips: Don't set forbidden slot on never-taken nanoMIPS branches Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:29 ` Richard Henderson
2026-11-13 16:11 ` [PATCH 19/19] target/mips: Do not negate NaN results in NMADD.fmt and NMSUB.fmt Philippe Mathieu-Daudé
2026-11-13 16:34 ` [PATCH 00/19] target/mips: Mixed bag of fixes Peter Maydell
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The MIPS64 Release 6.05 manual (LWR description) says that when bit
31 is not loaded, bits 63..32 of the destination are implementation
dependent: either unchanged or a copy of bit 31. Both behaviours are
architecturally allowed.
Octeon III CN71XX hardware leaves bits 63..32 unchanged unless the
whole word is loaded (vAddr[1:0] = 3 for big-endian, 0 for
little-endian). QEMU always sign-extended the merged low word.
Seen replaying a risu trace recorded on a Cavium Octeon III CN71XX:
"lwr s7,26334(a2)" left r23 = 0004114d368db793 on the hardware where
QEMU had 00000000368db793.
Only change the behaviour for Octeon CPUs (INSN_OCTEON); all other
CPUs keep sign-extending the result. LWL always loads bit 31 and is
unchanged.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/translate.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
index 6966b7e56abb..607384292633 100644
--- a/target/mips/tcg/translate.c
+++ b/target/mips/tcg/translate.c
@@ -2063,7 +2063,7 @@ void gen_lx(DisasContext *ctx, int rd, int base, int index, MemOp mop)
static void gen_ld(DisasContext *ctx, uint32_t opc,
int rt, int base, int offset)
{
- TCGv t0, t1;
+ TCGv t0, t1, t2, t3;
int mem_idx = ctx->mem_idx;
if (rt == 0 && ctx->insn_flags & (INSN_LOONGSON2E | INSN_LOONGSON2F |
@@ -2176,7 +2176,17 @@ static void gen_ld(DisasContext *ctx, uint32_t opc,
t1 = tcg_temp_new();
gen_load_gpr(t1, rt);
gen_lxr(ctx, t1, t0, mem_idx, mo_endian(ctx) | MO_UL);
- tcg_gen_ext32s_tl(t1, t1);
+ if (ctx->insn_flags & INSN_OCTEON) {
+ t2 = tcg_temp_new();
+ t3 = tcg_temp_new();
+ tcg_gen_ext32s_tl(t3, t1);
+ tcg_gen_andi_tl(t2, t0, 3);
+ tcg_gen_movcond_tl(TCG_COND_EQ, t1, t2,
+ tcg_constant_tl(disas_is_bigendian(ctx) ? 3 : 0),
+ t3, t1);
+ } else {
+ tcg_gen_ext32s_tl(t1, t1);
+ }
gen_store_gpr(t1, rt);
break;
case OPC_LLE:
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 18/19] target/mips: Do not sign-extend partial LWR results on Octeon
2026-11-13 16:11 ` [PATCH 18/19] target/mips: Do not sign-extend partial LWR results on Octeon Philippe Mathieu-Daudé
@ 2026-11-17 19:29 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:29 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The MIPS64 Release 6.05 manual (LWR description) says that when bit
> 31 is not loaded, bits 63..32 of the destination are implementation
> dependent: either unchanged or a copy of bit 31. Both behaviours are
> architecturally allowed.
>
> Octeon III CN71XX hardware leaves bits 63..32 unchanged unless the
> whole word is loaded (vAddr[1:0] = 3 for big-endian, 0 for
> little-endian). QEMU always sign-extended the merged low word.
>
> Seen replaying a risu trace recorded on a Cavium Octeon III CN71XX:
> "lwr s7,26334(a2)" left r23 = 0004114d368db793 on the hardware where
> QEMU had 00000000368db793.
>
> Only change the behaviour for Octeon CPUs (INSN_OCTEON); all other
> CPUs keep sign-extending the result. LWL always loads bit 31 and is
> unchanged.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/translate.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
Horrid, but,
Acked-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 48+ messages in thread
* [PATCH 19/19] target/mips: Do not negate NaN results in NMADD.fmt and NMSUB.fmt
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (17 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 18/19] target/mips: Do not sign-extend partial LWR results on Octeon Philippe Mathieu-Daudé
@ 2026-11-13 16:11 ` Philippe Mathieu-Daudé
2026-11-17 19:37 ` Richard Henderson
2026-11-13 16:34 ` [PATCH 00/19] target/mips: Mixed bag of fixes Peter Maydell
19 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-13 16:11 UTC (permalink / raw)
To: qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Richard Henderson, Milica Lazarevic, James Hilliard,
Philippe Mathieu-Daudé, Aleksandar Rikalo
The final negation of NMADD.fmt and NMSUB.fmt is arithmetic. With the
legacy NaN encoding (FCSR.NAN2008 = 0) QEMU returns the default NaN
(0x7ff7ffffffffffff for double precision, positive) for a NaN result,
then flipped its sign with float{32,64}_chs().
Observed on a Cavium Octeon III V0.2 (FPU V0.0, Linux 4.9.79) running
risu: "nmsub.d $f7,$f27,$f23,$f15" with $f27 = 0x7fffffffffffffff (a
signaling NaN in the legacy encoding), $f23 = 0 and
$f15 = 0x472fa6f57f408dcc gives 0x7ff7ffffffffffff on the hardware,
where QEMU gave 0xfff7ffffffffffff. The same was seen for the single
precision "nmsub.s $f1,$f18,$f22,$f21".
Do not change the sign of a NaN result when NAN2008 is 0. Non-NaN
results and the NAN2008 = 1 behavior are unchanged. NMADD.fmt, which
shares the code, was not exercised on the hardware.
The hardware (or its kernel FPU emulator) also returns a different NaN
than QEMU for "mul.d" with a signaling NaN operand and a denormal
operand: this is not addressed here.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
target/mips/tcg/fpu_helper.c | 39 ++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)
diff --git a/target/mips/tcg/fpu_helper.c b/target/mips/tcg/fpu_helper.c
index d6595da6482f..e085aa5669f0 100644
--- a/target/mips/tcg/fpu_helper.c
+++ b/target/mips/tcg/fpu_helper.c
@@ -1627,12 +1627,35 @@ uint64_t HELPER(float_msub_ps)(CPUMIPSState *env, uint64_t fdt0,
return ((uint64_t)fsth0 << 32) | fstl0;
}
+/*
+ * The final negation of NMADD.fmt and NMSUB.fmt is arithmetic: with the
+ * legacy NaN encoding (FCSR.NAN2008 = 0) the sign of a NaN result is not
+ * changed.
+ */
+static inline float64 nm_negate_d(CPUMIPSState *env, float64 a)
+{
+ if (!(env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) &&
+ float64_is_any_nan(a)) {
+ return a;
+ }
+ return float64_chs(a);
+}
+
+static inline float32 nm_negate_s(CPUMIPSState *env, float32 a)
+{
+ if (!(env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) &&
+ float32_is_any_nan(a)) {
+ return a;
+ }
+ return float32_chs(a);
+}
+
uint64_t HELPER(float_nmadd_d)(CPUMIPSState *env, uint64_t fst0,
uint64_t fst1, uint64_t fst2)
{
fst0 = float64_mul(fst0, fst1, &env->active_fpu.fp_status);
fst0 = float64_add(fst0, fst2, &env->active_fpu.fp_status);
- fst0 = float64_chs(fst0);
+ fst0 = nm_negate_d(env, fst0);
update_fcr31(env, GETPC());
return fst0;
@@ -1643,7 +1666,7 @@ uint32_t HELPER(float_nmadd_s)(CPUMIPSState *env, uint32_t fst0,
{
fst0 = float32_mul(fst0, fst1, &env->active_fpu.fp_status);
fst0 = float32_add(fst0, fst2, &env->active_fpu.fp_status);
- fst0 = float32_chs(fst0);
+ fst0 = nm_negate_s(env, fst0);
update_fcr31(env, GETPC());
return fst0;
@@ -1661,10 +1684,10 @@ uint64_t HELPER(float_nmadd_ps)(CPUMIPSState *env, uint64_t fdt0,
fstl0 = float32_mul(fstl0, fstl1, &env->active_fpu.fp_status);
fstl0 = float32_add(fstl0, fstl2, &env->active_fpu.fp_status);
- fstl0 = float32_chs(fstl0);
+ fstl0 = nm_negate_s(env, fstl0);
fsth0 = float32_mul(fsth0, fsth1, &env->active_fpu.fp_status);
fsth0 = float32_add(fsth0, fsth2, &env->active_fpu.fp_status);
- fsth0 = float32_chs(fsth0);
+ fsth0 = nm_negate_s(env, fsth0);
update_fcr31(env, GETPC());
return ((uint64_t)fsth0 << 32) | fstl0;
@@ -1675,7 +1698,7 @@ uint64_t HELPER(float_nmsub_d)(CPUMIPSState *env, uint64_t fst0,
{
fst0 = float64_mul(fst0, fst1, &env->active_fpu.fp_status);
fst0 = float64_sub(fst0, fst2, &env->active_fpu.fp_status);
- fst0 = float64_chs(fst0);
+ fst0 = nm_negate_d(env, fst0);
update_fcr31(env, GETPC());
return fst0;
@@ -1686,7 +1709,7 @@ uint32_t HELPER(float_nmsub_s)(CPUMIPSState *env, uint32_t fst0,
{
fst0 = float32_mul(fst0, fst1, &env->active_fpu.fp_status);
fst0 = float32_sub(fst0, fst2, &env->active_fpu.fp_status);
- fst0 = float32_chs(fst0);
+ fst0 = nm_negate_s(env, fst0);
update_fcr31(env, GETPC());
return fst0;
@@ -1704,10 +1727,10 @@ uint64_t HELPER(float_nmsub_ps)(CPUMIPSState *env, uint64_t fdt0,
fstl0 = float32_mul(fstl0, fstl1, &env->active_fpu.fp_status);
fstl0 = float32_sub(fstl0, fstl2, &env->active_fpu.fp_status);
- fstl0 = float32_chs(fstl0);
+ fstl0 = nm_negate_s(env, fstl0);
fsth0 = float32_mul(fsth0, fsth1, &env->active_fpu.fp_status);
fsth0 = float32_sub(fsth0, fsth2, &env->active_fpu.fp_status);
- fsth0 = float32_chs(fsth0);
+ fsth0 = nm_negate_s(env, fsth0);
update_fcr31(env, GETPC());
return ((uint64_t)fsth0 << 32) | fstl0;
--
2.55.0
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 19/19] target/mips: Do not negate NaN results in NMADD.fmt and NMSUB.fmt
2026-11-13 16:11 ` [PATCH 19/19] target/mips: Do not negate NaN results in NMADD.fmt and NMSUB.fmt Philippe Mathieu-Daudé
@ 2026-11-17 19:37 ` Richard Henderson
0 siblings, 0 replies; 48+ messages in thread
From: Richard Henderson @ 2026-11-17 19:37 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker, Aurelien Jarno,
Milica Lazarevic, James Hilliard, Aleksandar Rikalo
On 11/13/26 08:11, Philippe Mathieu-Daudé wrote:
> The final negation of NMADD.fmt and NMSUB.fmt is arithmetic. With the
> legacy NaN encoding (FCSR.NAN2008 = 0) QEMU returns the default NaN
> (0x7ff7ffffffffffff for double precision, positive) for a NaN result,
> then flipped its sign with float{32,64}_chs().
>
> Observed on a Cavium Octeon III V0.2 (FPU V0.0, Linux 4.9.79) running
> risu: "nmsub.d $f7,$f27,$f23,$f15" with $f27 = 0x7fffffffffffffff (a
> signaling NaN in the legacy encoding), $f23 = 0 and
> $f15 = 0x472fa6f57f408dcc gives 0x7ff7ffffffffffff on the hardware,
> where QEMU gave 0xfff7ffffffffffff. The same was seen for the single
> precision "nmsub.s $f1,$f18,$f22,$f21".
>
> Do not change the sign of a NaN result when NAN2008 is 0. Non-NaN
> results and the NAN2008 = 1 behavior are unchanged. NMADD.fmt, which
> shares the code, was not exercised on the hardware.
>
> The hardware (or its kernel FPU emulator) also returns a different NaN
> than QEMU for "mul.d" with a signaling NaN operand and a denormal
> operand: this is not addressed here.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> target/mips/tcg/fpu_helper.c | 39 ++++++++++++++++++++++++++++--------
> 1 file changed, 31 insertions(+), 8 deletions(-)
Isn't the larger problem that this should be using a fused multiply-add
via float64_muladd, and thus the negation via float_muladd_negate_result
(which will not affect NaN results).
Certainly MD00087 says the product uses infinite precision.
r~
>
> diff --git a/target/mips/tcg/fpu_helper.c b/target/mips/tcg/fpu_helper.c
> index d6595da6482f..e085aa5669f0 100644
> --- a/target/mips/tcg/fpu_helper.c
> +++ b/target/mips/tcg/fpu_helper.c
> @@ -1627,12 +1627,35 @@ uint64_t HELPER(float_msub_ps)(CPUMIPSState *env, uint64_t fdt0,
> return ((uint64_t)fsth0 << 32) | fstl0;
> }
>
> +/*
> + * The final negation of NMADD.fmt and NMSUB.fmt is arithmetic: with the
> + * legacy NaN encoding (FCSR.NAN2008 = 0) the sign of a NaN result is not
> + * changed.
> + */
> +static inline float64 nm_negate_d(CPUMIPSState *env, float64 a)
> +{
> + if (!(env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) &&
> + float64_is_any_nan(a)) {
> + return a;
> + }
> + return float64_chs(a);
> +}
> +
> +static inline float32 nm_negate_s(CPUMIPSState *env, float32 a)
> +{
> + if (!(env->active_fpu.fcr31 & (1 << FCR31_NAN2008)) &&
> + float32_is_any_nan(a)) {
> + return a;
> + }
> + return float32_chs(a);
> +}
> +
> uint64_t HELPER(float_nmadd_d)(CPUMIPSState *env, uint64_t fst0,
> uint64_t fst1, uint64_t fst2)
> {
> fst0 = float64_mul(fst0, fst1, &env->active_fpu.fp_status);
> fst0 = float64_add(fst0, fst2, &env->active_fpu.fp_status);
> - fst0 = float64_chs(fst0);
> + fst0 = nm_negate_d(env, fst0);
>
> update_fcr31(env, GETPC());
> return fst0;
> @@ -1643,7 +1666,7 @@ uint32_t HELPER(float_nmadd_s)(CPUMIPSState *env, uint32_t fst0,
> {
> fst0 = float32_mul(fst0, fst1, &env->active_fpu.fp_status);
> fst0 = float32_add(fst0, fst2, &env->active_fpu.fp_status);
> - fst0 = float32_chs(fst0);
> + fst0 = nm_negate_s(env, fst0);
>
> update_fcr31(env, GETPC());
> return fst0;
> @@ -1661,10 +1684,10 @@ uint64_t HELPER(float_nmadd_ps)(CPUMIPSState *env, uint64_t fdt0,
>
> fstl0 = float32_mul(fstl0, fstl1, &env->active_fpu.fp_status);
> fstl0 = float32_add(fstl0, fstl2, &env->active_fpu.fp_status);
> - fstl0 = float32_chs(fstl0);
> + fstl0 = nm_negate_s(env, fstl0);
> fsth0 = float32_mul(fsth0, fsth1, &env->active_fpu.fp_status);
> fsth0 = float32_add(fsth0, fsth2, &env->active_fpu.fp_status);
> - fsth0 = float32_chs(fsth0);
> + fsth0 = nm_negate_s(env, fsth0);
>
> update_fcr31(env, GETPC());
> return ((uint64_t)fsth0 << 32) | fstl0;
> @@ -1675,7 +1698,7 @@ uint64_t HELPER(float_nmsub_d)(CPUMIPSState *env, uint64_t fst0,
> {
> fst0 = float64_mul(fst0, fst1, &env->active_fpu.fp_status);
> fst0 = float64_sub(fst0, fst2, &env->active_fpu.fp_status);
> - fst0 = float64_chs(fst0);
> + fst0 = nm_negate_d(env, fst0);
>
> update_fcr31(env, GETPC());
> return fst0;
> @@ -1686,7 +1709,7 @@ uint32_t HELPER(float_nmsub_s)(CPUMIPSState *env, uint32_t fst0,
> {
> fst0 = float32_mul(fst0, fst1, &env->active_fpu.fp_status);
> fst0 = float32_sub(fst0, fst2, &env->active_fpu.fp_status);
> - fst0 = float32_chs(fst0);
> + fst0 = nm_negate_s(env, fst0);
>
> update_fcr31(env, GETPC());
> return fst0;
> @@ -1704,10 +1727,10 @@ uint64_t HELPER(float_nmsub_ps)(CPUMIPSState *env, uint64_t fdt0,
>
> fstl0 = float32_mul(fstl0, fstl1, &env->active_fpu.fp_status);
> fstl0 = float32_sub(fstl0, fstl2, &env->active_fpu.fp_status);
> - fstl0 = float32_chs(fstl0);
> + fstl0 = nm_negate_s(env, fstl0);
> fsth0 = float32_mul(fsth0, fsth1, &env->active_fpu.fp_status);
> fsth0 = float32_sub(fsth0, fsth2, &env->active_fpu.fp_status);
> - fsth0 = float32_chs(fsth0);
> + fsth0 = nm_negate_s(env, fsth0);
>
> update_fcr31(env, GETPC());
> return ((uint64_t)fsth0 << 32) | fstl0;
^ permalink raw reply [flat|nested] 48+ messages in thread
* Re: [PATCH 00/19] target/mips: Mixed bag of fixes
2026-11-13 16:11 [PATCH 00/19] target/mips: Mixed bag of fixes Philippe Mathieu-Daudé
` (18 preceding siblings ...)
2026-11-13 16:11 ` [PATCH 19/19] target/mips: Do not negate NaN results in NMADD.fmt and NMSUB.fmt Philippe Mathieu-Daudé
@ 2026-11-13 16:34 ` Peter Maydell
2026-11-16 8:37 ` Philippe Mathieu-Daudé
19 siblings, 1 reply; 48+ messages in thread
From: Peter Maydell @ 2026-11-13 16:34 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker,
Aurelien Jarno, Richard Henderson, Milica Lazarevic,
James Hilliard, Aleksandar Rikalo
On Fri, 13 Nov 2026 at 16:13, Philippe Mathieu-Daudé
<philmd@oss.qualcomm.com> wrote:
>
> Various individual fixes noted while reviewing manuals
> during decodetree conversion, and using a RISU prototype.
If you have a little time for MIPS could I get you to have a look at
Coverity issue 1689817 ? It's not urgent, but Coverity complains about
what it thinks is some dead code in the dextr_s_h helper:
} else if ((temp127 == 1) &&
(temp[1] < 0xFFFFFFFFFFFFFFFFll
|| temp[0] < 0xFFFFFFFFFFFF1000ll)) {
The compare with temp[1] is very odd here. The constant has the "ll"
suffix indicating that the author thought this would be signed,
but the value is 0xFFFF_FFFF_FFFF_FFFF so it doesn't fit in a
signed 64-bit integer type. So the C spec says it has type
"unsigned long long" (because it's a hex constant). That means
that the comparison is int64_t against uint64_t, which causes
temp[1] to be cast to unsigned and we do an unsigned comparison.
The upshot is that "temp[1] < 0xFFFFFFFFFFFFFFFFll" is a funny way of
writing "temp[1] != -1". So I think Coverity is wrong about there
being dead code, but it's confused because the code is written in a
confusing and possibly wrong way.
The comparison with temp[] is also 0xFFFF_FFFF_FFFF_1000 with the
LL suffix, so it's also not really a signed value or comparison.
I don't know what this instruction is supposed to be doing, but
it would be helpful if somebody who does could have a look and
rewrite the code to either do the right thing if the current
code is wrong, or else to rephrase it so it is clearer about
what it's doing if it's getting the right result in a weird way.
thanks
-- PMM
^ permalink raw reply [flat|nested] 48+ messages in thread* Re: [PATCH 00/19] target/mips: Mixed bag of fixes
2026-11-13 16:34 ` [PATCH 00/19] target/mips: Mixed bag of fixes Peter Maydell
@ 2026-11-16 8:37 ` Philippe Mathieu-Daudé
2026-11-16 9:55 ` Peter Maydell
0 siblings, 1 reply; 48+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-11-16 8:37 UTC (permalink / raw)
To: Peter Maydell
Cc: qemu-devel, Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker,
Aurelien Jarno, Richard Henderson, Milica Lazarevic,
James Hilliard, Aleksandar Rikalo
Hi Peter,
On 13/11/26 17:34, Peter Maydell wrote:
> On Fri, 13 Nov 2026 at 16:13, Philippe Mathieu-Daudé
> <philmd@oss.qualcomm.com> wrote:
>>
>> Various individual fixes noted while reviewing manuals
>> during decodetree conversion, and using a RISU prototype.
>
> If you have a little time for MIPS could I get you to have a look at
> Coverity issue 1689817 ? It's not urgent, but Coverity complains about
> what it thinks is some dead code in the dextr_s_h helper:
>
> } else if ((temp127 == 1) &&
> (temp[1] < 0xFFFFFFFFFFFFFFFFll
> || temp[0] < 0xFFFFFFFFFFFF1000ll)) {
>
> The compare with temp[1] is very odd here. The constant has the "ll"
> suffix indicating that the author thought this would be signed,
> but the value is 0xFFFF_FFFF_FFFF_FFFF so it doesn't fit in a
> signed 64-bit integer type. So the C spec says it has type
> "unsigned long long" (because it's a hex constant). That means
> that the comparison is int64_t against uint64_t, which causes
> temp[1] to be cast to unsigned and we do an unsigned comparison.
>
> The upshot is that "temp[1] < 0xFFFFFFFFFFFFFFFFll" is a funny way of
> writing "temp[1] != -1". So I think Coverity is wrong about there
> being dead code, but it's confused because the code is written in a
> confusing and possibly wrong way.
>
> The comparison with temp[] is also 0xFFFF_FFFF_FFFF_1000 with the
> LL suffix, so it's also not really a signed value or comparison.
>
> I don't know what this instruction is supposed to be doing, but
> it would be helpful if somebody who does could have a look and
> rewrite the code to either do the right thing if the current
> code is wrong, or else to rephrase it so it is clearer about
> what it's doing if it's getting the right result in a weird way.
Although MD00375 (MIPS64 DSP) and MD00765 (microMIPS64 DSP) manuals
list the DEXTP* or DEXTR* instructions encoding tables, they do not
contains these instruction descriptions. We can infer from the MIPS32
EXTR_S.H semantics which saturates to [-0x8000, 0x7FFF], sign-extend
to 64 bits and apply to the 128-bit HI:LO.
0xFFFF_FFFF_FFFF_1000 is a typo, should be 0xFFFF_FFFF_FFFF_8000.
Fix using uint64_t and explicit comparisons (positive values with
bit 63 set in the low half were not saturated, as that half was
compared as signed):
-- >8 --
diff --git a/target/mips/tcg/dsp_helper.c b/target/mips/tcg/dsp_helper.c
index 73934cab7786..1d4d54897dd6 100644
--- a/target/mips/tcg/dsp_helper.c
+++ b/target/mips/tcg/dsp_helper.c
@@ -3379,22 +3379,21 @@ target_ulong HELPER(extr_s_h)(target_ulong ac,
target_ulong shift,
target_ulong HELPER(dextr_s_h)(target_ulong ac, target_ulong shift,
CPUMIPSState *env)
{
- int64_t temp[2];
+ uint64_t temp[2];
uint32_t temp127;
shift = shift & 0x1F;
- mipsdsp_rashift_acc((uint64_t *)temp, ac, shift, env);
+ mipsdsp_rashift_acc(temp, ac, shift, env);
temp127 = (temp[1] >> 63) & 0x01;
- if ((temp127 == 0) && (temp[1] > 0 || temp[0] > 32767)) {
+ if (temp127 == 0 && (temp[1] != 0 || temp[0] > 0x7FFF)) {
temp[0] &= 0xFFFF0000;
temp[0] |= 0x00007FFF;
set_DSPControl_overflow_flag(1, 23, env);
- } else if ((temp127 == 1) &&
- (temp[1] < 0xFFFFFFFFFFFFFFFFll
- || temp[0] < 0xFFFFFFFFFFFF1000ll)) {
+ } else if (temp127 == 1 &&
+ (temp[1] != ~0ull || temp[0] < 0xFFFFFFFFFFFF8000ull)) {
temp[0] &= 0xFFFF0000;
temp[0] |= 0x00008000;
set_DSPControl_overflow_flag(1, 23, env);
---
But this is a good opportunity to rewrite in a more readable style
(I'm not a fan of complex condition checks in particular when 'else if'
is involved, I rather use local self-descriptive booleans); the same
fix becomes:
-- >8 --
diff --git a/target/mips/tcg/dsp_helper.c b/target/mips/tcg/dsp_helper.c
index 73934cab7786..82a9a29c0213 100644
--- a/target/mips/tcg/dsp_helper.c
+++ b/target/mips/tcg/dsp_helper.c
@@ -3379,28 +3379,25 @@ target_ulong HELPER(extr_s_h)(target_ulong ac,
target_ulong shift,
target_ulong HELPER(dextr_s_h)(target_ulong ac, target_ulong shift,
CPUMIPSState *env)
{
- int64_t temp[2];
- uint32_t temp127;
+ uint64_t temp[2];
+ int64_t lo;
+ bool negative, fits_s64, fits_s16;
shift = shift & 0x1F;
- mipsdsp_rashift_acc((uint64_t *)temp, ac, shift, env);
+ mipsdsp_rashift_acc(temp, ac, shift, env);
- temp127 = (temp[1] >> 63) & 0x01;
+ lo = temp[0];
+ negative = temp[1] >> 63;
+ fits_s64 = temp[1] == (uint64_t)(lo >> 63);
+ fits_s16 = lo == (int16_t)lo;
- if ((temp127 == 0) && (temp[1] > 0 || temp[0] > 32767)) {
- temp[0] &= 0xFFFF0000;
- temp[0] |= 0x00007FFF;
- set_DSPControl_overflow_flag(1, 23, env);
- } else if ((temp127 == 1) &&
- (temp[1] < 0xFFFFFFFFFFFFFFFFll
- || temp[0] < 0xFFFFFFFFFFFF1000ll)) {
- temp[0] &= 0xFFFF0000;
- temp[0] |= 0x00008000;
- set_DSPControl_overflow_flag(1, 23, env);
+ if (fits_s64 && fits_s16) {
+ return lo;
}
-
- return (int64_t)(int16_t)(temp[0] & MIPSDSP_LO);
+ set_DSPControl_overflow_flag(1, 23, env);
+ return negative ? INT16_MIN : INT16_MAX;
}
---
Is it reviewable-enough to be a single fix patch or do you rather
that split in 1 fix and 1 refactor?
Thanks,
Phil.
^ permalink raw reply related [flat|nested] 48+ messages in thread* Re: [PATCH 00/19] target/mips: Mixed bag of fixes
2026-11-16 8:37 ` Philippe Mathieu-Daudé
@ 2026-11-16 9:55 ` Peter Maydell
0 siblings, 0 replies; 48+ messages in thread
From: Peter Maydell @ 2026-11-16 9:55 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Jiaxun Yang, Vince Del Vecchio, Faraz Shahbazker,
Aurelien Jarno, Richard Henderson, Milica Lazarevic,
James Hilliard, Aleksandar Rikalo
On Mon, 16 Nov 2026 at 08:37, Philippe Mathieu-Daudé
<philmd@oss.qualcomm.com> wrote:
> On 13/11/26 17:34, Peter Maydell wrote:
> > If you have a little time for MIPS could I get you to have a look at
> > Coverity issue 1689817 ? It's not urgent, but Coverity complains about
> > what it thinks is some dead code in the dextr_s_h helper:
> > I don't know what this instruction is supposed to be doing, but
> > it would be helpful if somebody who does could have a look and
> > rewrite the code to either do the right thing if the current
> > code is wrong, or else to rephrase it so it is clearer about
> > what it's doing if it's getting the right result in a weird way.
>
> Although MD00375 (MIPS64 DSP) and MD00765 (microMIPS64 DSP) manuals
> list the DEXTP* or DEXTR* instructions encoding tables, they do not
> contains these instruction descriptions. We can infer from the MIPS32
> EXTR_S.H semantics which saturates to [-0x8000, 0x7FFF], sign-extend
> to 64 bits and apply to the 128-bit HI:LO.
> But this is a good opportunity to rewrite in a more readable style
> (I'm not a fan of complex condition checks in particular when 'else if'
> is involved, I rather use local self-descriptive booleans); the same
> fix becomes:
>
> -- >8 --
> diff --git a/target/mips/tcg/dsp_helper.c b/target/mips/tcg/dsp_helper.c
> index 73934cab7786..82a9a29c0213 100644
> --- a/target/mips/tcg/dsp_helper.c
> +++ b/target/mips/tcg/dsp_helper.c
> @@ -3379,28 +3379,25 @@ target_ulong HELPER(extr_s_h)(target_ulong ac,
> target_ulong shift,
> target_ulong HELPER(dextr_s_h)(target_ulong ac, target_ulong shift,
> CPUMIPSState *env)
> {
> - int64_t temp[2];
> - uint32_t temp127;
> + uint64_t temp[2];
> + int64_t lo;
> + bool negative, fits_s64, fits_s16;
>
> shift = shift & 0x1F;
>
> - mipsdsp_rashift_acc((uint64_t *)temp, ac, shift, env);
> + mipsdsp_rashift_acc(temp, ac, shift, env);
>
> - temp127 = (temp[1] >> 63) & 0x01;
> + lo = temp[0];
> + negative = temp[1] >> 63;
> + fits_s64 = temp[1] == (uint64_t)(lo >> 63);
> + fits_s16 = lo == (int16_t)lo;
>
> - if ((temp127 == 0) && (temp[1] > 0 || temp[0] > 32767)) {
> - temp[0] &= 0xFFFF0000;
> - temp[0] |= 0x00007FFF;
> - set_DSPControl_overflow_flag(1, 23, env);
> - } else if ((temp127 == 1) &&
> - (temp[1] < 0xFFFFFFFFFFFFFFFFll
> - || temp[0] < 0xFFFFFFFFFFFF1000ll)) {
> - temp[0] &= 0xFFFF0000;
> - temp[0] |= 0x00008000;
> - set_DSPControl_overflow_flag(1, 23, env);
> + if (fits_s64 && fits_s16) {
> + return lo;
> }
> -
> - return (int64_t)(int16_t)(temp[0] & MIPSDSP_LO);
> + set_DSPControl_overflow_flag(1, 23, env);
> + return negative ? INT16_MIN : INT16_MAX;
> }
>
> ---
>
> Is it reviewable-enough to be a single fix patch or do you rather
> that split in 1 fix and 1 refactor?
I think that's OK as a single patch if you explain in the
commit message which cases the old code was getting wrong
and what the intent of the code is.
-- PMM
^ permalink raw reply [flat|nested] 48+ messages in thread