All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>,
	Vince Del Vecchio <Vince.DelVecchio@mediatek.com>,
	Faraz Shahbazker <faraz.shahbazker@mediatek.com>,
	Aurelien Jarno <aurelien@aurel32.net>,
	Milica Lazarevic <Milica.Lazarevic@Syrmia.com>,
	James Hilliard <james.hilliard1@gmail.com>,
	Aleksandar Rikalo <arikalo@gmail.com>
Subject: Re: [PATCH 17/19] target/mips: Don't set forbidden slot on never-taken nanoMIPS branches
Date: Tue, 17 Nov 2026 23:59:48 +0100	[thread overview]
Message-ID: <8d01f99f-74dd-4cec-b103-cd360944d8a3@oss.qualcomm.com> (raw)
In-Reply-To: <4d7da53d-8c5a-4080-9407-a6f4e186e3d1@linaro.org>

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;
> 
> 



  reply	other threads:[~2026-11-17 23:00 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-17 18:54   ` Richard Henderson
2026-11-13 16:11 ` [PATCH 02/19] target/mips: Require rt == 0 " 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é
2026-11-17 19:00   ` Richard Henderson
2026-11-17 22:35     ` Philippe Mathieu-Daudé
2026-11-18  0:01       ` Richard Henderson
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
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
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
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
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
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é
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
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
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
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é
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é
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
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
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é [this message]
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
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
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8d01f99f-74dd-4cec-b103-cd360944d8a3@oss.qualcomm.com \
    --to=philmd@oss.qualcomm.com \
    --cc=Milica.Lazarevic@Syrmia.com \
    --cc=Vince.DelVecchio@mediatek.com \
    --cc=arikalo@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=faraz.shahbazker@mediatek.com \
    --cc=james.hilliard1@gmail.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.