All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fredrik Noring <noring@nocrew.org>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Emilio G. Cota" <cota@braap.org>,
	"Aleksandar Markovic" <amarkovic@wavecomp.com>
Cc: "Stefan Markovic" <smarkovic@wavecomp.com>,
	"Petar Jovanovic" <pjovanovic@wavecomp.com>,
	"Aleksandar Rikalo" <arikalo@wavecomp.com>,
	"Maciej W. Rozycki" <macro@linux-mips.org>,
	"Jürgen Urban" <JuergenUrban@gmx.de>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Correction needed for R5900 instruction decoding
Date: Thu, 1 Nov 2018 18:23:53 +0100	[thread overview]
Message-ID: <20181101172353.GA2316@sx9> (raw)
In-Reply-To: <51a26700-5da5-0a15-0e0e-6405ce5e65d4@redhat.com>

[ Philippe and Emilio -- thank you for cc-ing me. Good catch, since I'm
not subscribed to the QEMU mailing list. Changes to the R5900 emulation
are certainly of interest. ]

Hi Aleksandar, Philippe,

On Thu, Nov 01, 2018 at 03:31:54PM +0100, Philippe Mathieu-Daudé wrote:
> Cc'ing Fredrik.
> 
> On 1/11/18 12:06, Aleksandar Markovic wrote:
> > Hi, Fridrik,
> > 
> > I did some closer code inspection of R5900 in last few days, and I
> > noticed some sub-optimal implementation in the area where R5900-specific
> > opcodes overlap with the rest-of-MIPS-CPUs opcodes.
> > 
> > The right implementation should be based on the principle that all such
> > cases are covered with if statements involving INSN_R5900 flag, like
> > this:
> > 
> >          if (ctx->insn_flags & INSN_R5900) {
> >              <R5900-specific handling>
> >          } else {
> >              <rest-of-MIPS-handling>
> >          }
> > 
> > You followed that principle for OPC_SPECIAL2 and OPC_SPECIAL3, but for
> > some other opcodes not. For example, there are lines:
> > 
> >      if (reg == 0 && (opc == OPC_MFHI || opc == TX79_MMI_MFHI1 ||
> >                       opc == OPC_MFLO || opc == TX79_MMI_MFLO1)) {
> > 
> > or
> > 
> >       switch (opc) {
> >       case OPC_MFHI:
> >       case TX79_MMI_MFHI1:
> > 
> > Such implementation makes it difficult to discern R5900 and non-R5900
> > cases. Potentialy allows bugs to sneak in and affect non-R5900 support.

MFLO1, MFHI1, MTLO1 and MTHI1 for the TX79 and the R5900 are already
decoded in the ISA specific decode_tx79_mmi function, and thereby follow
your first suggested pattern. They do however reuse the gen_HILO function,
but it is a simpel matter to post a patch to make a new gen_tx79_HILO1
variant that is almost identical to the original gen_HILO.

The only other case is gen_muldiv that is used for DIV1 and DIVU1. The
same argument applies and a TX79 specific variant would be similar to the
original, but I can certainly post a variant for that one too.

> > The correction is not that difficult, I gather. Worse comme to worst,
> > you can remove R5900 MFLO1 and MFHI1 altogether, they are not that
> > essential at this moment, but do try correcting the decoding stuff as I
> > described. Can you please make these changes in next few days or so
> > (given that 3.1 release is getting closer and closer), and send them to
> > the list?

MFLO1 and MFHI1 are essential for MULT1, MULTU1, DIV1 and DIVU1 as well as
MADD1 and MADDU1 in the patch series I posted 25 October "[PATCH 00/11]
target/mips: Amend R5900 support". I will post updated patches shortly!

> > It is my bad that I didn't spot this during review, but in any case, I
> > think this should be fixed in 3.1 to make sure that non-R5900
> > functionalities are intact.

It is a common pattern in target/mips/translate.c to cover several ISAs
in the same gen_* and decode_* functions, especially when there are only
minor differences between them.

Fredrik

  reply	other threads:[~2018-11-01 17:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-01 11:06 [Qemu-devel] Correction needed for R5900 instruction decoding Aleksandar Markovic
2018-11-01 14:31 ` Philippe Mathieu-Daudé
2018-11-01 17:23   ` Fredrik Noring [this message]
2018-11-01 18:07     ` Aleksandar Markovic
2018-11-02 13:43     ` Aleksandar Markovic
2018-11-02 14:31       ` Fredrik Noring
2018-11-02 15:03         ` Aleksandar Markovic
2018-11-02 15:18           ` Peter Maydell
2018-11-02 15:49             ` Fredrik Noring
2018-11-01 14:35 ` Emilio G. Cota
2018-11-02 17:51 ` Philippe Mathieu-Daudé

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=20181101172353.GA2316@sx9 \
    --to=noring@nocrew.org \
    --cc=JuergenUrban@gmx.de \
    --cc=amarkovic@wavecomp.com \
    --cc=arikalo@wavecomp.com \
    --cc=cota@braap.org \
    --cc=macro@linux-mips.org \
    --cc=philmd@redhat.com \
    --cc=pjovanovic@wavecomp.com \
    --cc=qemu-devel@nongnu.org \
    --cc=smarkovic@wavecomp.com \
    /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.