qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Mateja Marjanovic <mateja.marjanovic@rt-rk.com>, qemu-devel@nongnu.org
Cc: arikalo@wavecomp.com, Richard Henderson <rth@twiddle.net>,
	aurelien@aurel32.net
Subject: Re: [Qemu-devel] [PATCH v2 1/2] target/mips: Make the results of DIV_<U|S>.<B|H|W|D> the same as on hardware
Date: Tue, 2 Apr 2019 17:08:06 +0200	[thread overview]
Message-ID: <8dd10edf-a799-1c3b-2421-601d91eff0ac@redhat.com> (raw)
In-Reply-To: <1554207110-9113-2-git-send-email-mateja.marjanovic@rt-rk.com>

Hi Mateja,

On 4/2/19 2:11 PM, Mateja Marjanovic wrote:
> From: Mateja Marjanovic <Mateja.Marjanovic@rt-rk.com>
> 
> MSA instructions DIV_<U|S>.<B|H|W|D> when dividing by zero,
> didn't return the same value when executed on a referent hardware
> (FPGA MIPS 64 r6, little endian) and when executed on QEMU, which
> is not a real bug, because the result when dividing by zero is
> UNPREDICTABLE [1] (page 141, 142).

I'm surprised by the arch, I'd have expected a MSA floating point
exception instead of UNPREDICTABLE.

So here we decide to follow the FPGA model behavior rather than the
architecture...
If the community agree, my only request is to add a comment in the code
that this is the "FPGA MIPS 64 r6" behavior (else while looking at this
code later I'd be tempted to revert to a 0 return value instead of -1/1).

> 
> [1] MIPS Architecture for Programmers
>     Volume IV-j: The MIPS64 SIMD
>     Architecture Module, Revision 1.12
> 
> Signed-off-by: Mateja Marjanovic <mateja.marjanovic@rt-rk.com>
> ---
>  target/mips/msa_helper.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/target/mips/msa_helper.c b/target/mips/msa_helper.c
> index 655148d..8c77f12 100644
> --- a/target/mips/msa_helper.c
> +++ b/target/mips/msa_helper.c
> @@ -641,14 +641,15 @@ static inline int64_t msa_div_s_df(uint32_t df, int64_t arg1, int64_t arg2)
>      if (arg1 == DF_MIN_INT(df) && arg2 == -1) {
>          return DF_MIN_INT(df);
>      }
> -    return arg2 ? arg1 / arg2 : 0;
> +    return arg2 ? arg1 / arg2
> +                : arg1 >= 0 ? -1 : 1;
>  }
>  
>  static inline int64_t msa_div_u_df(uint32_t df, int64_t arg1, int64_t arg2)
>  {
>      uint64_t u_arg1 = UNSIGNED(arg1, df);
>      uint64_t u_arg2 = UNSIGNED(arg2, df);
> -    return u_arg2 ? u_arg1 / u_arg2 : 0;
> +    return arg2 ? u_arg1 / u_arg2 : -1;
>  }
>  
>  static inline int64_t msa_mod_s_df(uint32_t df, int64_t arg1, int64_t arg2)
> 

  parent reply	other threads:[~2019-04-02 15:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 12:11 [Qemu-devel] [PATCH v2 0/2] target/mips: Adjusting the results when dividing by zero in MSA instructions Mateja Marjanovic
2019-04-02 12:11 ` [Qemu-devel] [PATCH v2 1/2] target/mips: Make the results of DIV_<U|S>.<B|H|W|D> the same as on hardware Mateja Marjanovic
2019-04-02 12:51   ` Aleksandar Markovic
2019-04-02 15:08   ` Philippe Mathieu-Daudé [this message]
2019-04-02 15:26     ` Mateja Marjanovic
2019-04-02 12:11 ` [Qemu-devel] [PATCH v2 2/2] target/mips: Make the results of MOD_<U|S>.<B|H|W|D> " Mateja Marjanovic
2019-04-02 12:50   ` Aleksandar Markovic

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=8dd10edf-a799-1c3b-2421-601d91eff0ac@redhat.com \
    --to=philmd@redhat.com \
    --cc=arikalo@wavecomp.com \
    --cc=aurelien@aurel32.net \
    --cc=mateja.marjanovic@rt-rk.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).