qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: Petar Jovanovic <Petar.Jovanovic@imgtec.com>
Cc: Petar Jovanovic <petar.jovanovic@rt-rk.com>,
	"aurelien@aurel32.net" <aurelien@aurel32.net>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
Date: Thu, 27 Jun 2013 11:20:33 -0700	[thread overview]
Message-ID: <51CC8271.6040204@twiddle.net> (raw)
In-Reply-To: <56EA75BA695AE044ACFB41322F6D2BF4022320A1@BADAG02.ba.imgtec.org>

On 06/17/2013 03:39 PM, Petar Jovanovic wrote:
> -    int64_t temp;
> -
> -    temp = (int32_t)a + 0x00008000;
> +    uint16_t temp;
> 
> -    if (a > (int)0x7fff8000) {
> -        temp = 0x7FFFFFFF;
> +    if (a > 0x7FFF7FFF) {
> +        temp = 0x7FFF;
>          set_DSPControl_overflow_flag(1, 22, env);
> +    } else {
> +        temp = ((a + 0x8000) >> 16) & 0xFFFF;

This doesn't look right either, as it doesn't properly check for overflow of
negative values.  I'd feel better if we implement this function exactly as
documented, modulo actually using 64-bit arithmetic.  How about

  int32_t temp;

  /* Shift right by one, to avoid needing 64-bit arithmetic.  As this A is
     signed, this creates the copy of the sign bit as documented.  */
  a >>= 1;
  temp = a + 0x4000;

  /* Compare temp{31} with temp{30} by xoring into the sign bit.  */
  if ((temp ^ (temp << 1)) < 0) {
      set_DSPControl_overflow_flag(1, 22, env);
      return 0x7fff;
  }
  return temp >> 15;


r~

  parent reply	other threads:[~2013-06-27 18:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-22 13:35 [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round Petar Jovanovic
2013-06-09  2:34 ` Petar Jovanovic
2013-06-17 22:39   ` Petar Jovanovic
2013-06-25 10:18     ` Petar Jovanovic
2013-06-27 18:20     ` Richard Henderson [this message]
2013-06-27 21:48       ` Petar Jovanovic
2013-06-28 17:40         ` Richard Henderson
2013-06-30 23:53           ` Petar Jovanovic

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=51CC8271.6040204@twiddle.net \
    --to=rth@twiddle.net \
    --cc=Petar.Jovanovic@imgtec.com \
    --cc=aurelien@aurel32.net \
    --cc=petar.jovanovic@rt-rk.com \
    --cc=qemu-devel@nongnu.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 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).