qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
To: qemu-devel@nongnu.org
Cc: sw@weilnetz.de
Subject: [Qemu-devel] [PATCH] target-tricore: properly fix dvinit_b/h_13
Date: Mon, 23 Mar 2015 18:37:05 +0100	[thread overview]
Message-ID: <1427132225-18863-1-git-send-email-kbastian@mail.uni-paderborn.de> (raw)

The TriCore documentation was wrong on how to calculate ovf bits for those two
instructions, which I confirmed with real hardware (TC1796 chip). An ovf
actually happens, if the result (without remainder) does not fit into 8/16 bits.

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
 target-tricore/op_helper.c | 40 ++++++++++------------------------------
 1 file changed, 10 insertions(+), 30 deletions(-)

diff --git a/target-tricore/op_helper.c b/target-tricore/op_helper.c
index 2cfa95d..220ec4a 100644
--- a/target-tricore/op_helper.c
+++ b/target-tricore/op_helper.c
@@ -1942,29 +1942,19 @@ uint64_t helper_unpack(target_ulong arg1)
 uint64_t helper_dvinit_b_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
 {
     uint64_t ret;
-    int32_t abs_sig_dividend, abs_base_dividend, abs_divisor;
-    int32_t quotient_sign;
+    int32_t abs_sig_dividend, abs_divisor;
 
     ret = sextract32(r1, 0, 32);
     ret = ret << 24;
-    quotient_sign = 0;
     if (!((r1 & 0x80000000) == (r2 & 0x80000000))) {
         ret |= 0xffffff;
-        quotient_sign = 1;
     }
 
-    abs_sig_dividend = abs((int32_t)r1) >> 7;
-    abs_base_dividend = abs((int32_t)r1) & 0x7f;
+    abs_sig_dividend = abs((int32_t)r1) >> 8;
     abs_divisor = abs((int32_t)r2);
-    /* calc overflow */
-    env->PSW_USB_V = 0;
-    if ((quotient_sign) && (abs_divisor)) {
-        env->PSW_USB_V = (((abs_sig_dividend == abs_divisor) &&
-                         (abs_base_dividend >= abs_divisor)) ||
-                         (abs_sig_dividend > abs_divisor));
-    } else {
-        env->PSW_USB_V = (abs_sig_dividend >= abs_divisor);
-    }
+    /* calc overflow
+       ofv if (a/b >= 255) <=> (a/255 >= b) */
+    env->PSW_USB_V = (abs_sig_dividend >= abs_divisor) << 31;
     env->PSW_USB_V = env->PSW_USB_V << 31;
     env->PSW_USB_SV |= env->PSW_USB_V;
     env->PSW_USB_AV = 0;
@@ -1992,29 +1982,19 @@ uint64_t helper_dvinit_b_131(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
 uint64_t helper_dvinit_h_13(CPUTriCoreState *env, uint32_t r1, uint32_t r2)
 {
     uint64_t ret;
-    int32_t abs_sig_dividend, abs_base_dividend, abs_divisor;
-    int32_t quotient_sign;
+    int32_t abs_sig_dividend, abs_divisor;
 
     ret = sextract32(r1, 0, 32);
     ret = ret << 16;
-    quotient_sign = 0;
     if (!((r1 & 0x80000000) == (r2 & 0x80000000))) {
         ret |= 0xffff;
-        quotient_sign = 1;
     }
 
-    abs_sig_dividend = abs((int32_t)r1) >> 7;
-    abs_base_dividend = abs((int32_t)r1) & 0x7f;
+    abs_sig_dividend = abs((int32_t)r1) >> 16;
     abs_divisor = abs((int32_t)r2);
-    /* calc overflow */
-    env->PSW_USB_V = 0;
-    if ((quotient_sign) && (abs_divisor)) {
-        env->PSW_USB_V = (((abs_sig_dividend == abs_divisor) &&
-                         (abs_base_dividend >= abs_divisor)) ||
-                         (abs_sig_dividend > abs_divisor));
-    } else {
-        env->PSW_USB_V = (abs_sig_dividend >= abs_divisor);
-    }
+    /* calc overflow
+       ofv if (a/b >= 0xffff) <=> (a/0xffff >= b) */
+    env->PSW_USB_V = (abs_sig_dividend >= abs_divisor) << 31;
     env->PSW_USB_V = env->PSW_USB_V << 31;
     env->PSW_USB_SV |= env->PSW_USB_V;
     env->PSW_USB_AV = 0;
-- 
2.3.3

                 reply	other threads:[~2015-03-23 16:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1427132225-18863-1-git-send-email-kbastian@mail.uni-paderborn.de \
    --to=kbastian@mail.uni-paderborn.de \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /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).