qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Julian Brown <julian@codesourcery.com>
To: qemu-devel@nongnu.org
Cc: paul@codesourcery.com
Subject: [Qemu-devel] Fix -sizeof(foo) in target-arm/neon_helper.c shift helpers
Date: Tue, 27 Jan 2009 17:47:32 +0000	[thread overview]
Message-ID: <20090127174732.27db1f88@rex.config> (raw)

[-- Attachment #1: Type: text/plain, Size: 629 bytes --]

This patch fixes some bogus comparisons in the helpers for ARM NEON
shift operations, which negate sizeof(foo) without taking into account
that the result of that expression is unsigned.

I have no qemu write access, so can someone apply this for me if OK?

Thanks,

Julian

ChangeLog

    * target-arm/neon_helper.c (shl_u8, shl_u16, shl_u32): Fix
    greater-than-element-size boundary condition.
    (shl_s8, shl_s16, shl_s32): Likewise.
    (rshl_s8, rshl_s16, rshl_s32, rshl_u8, rshl_u16, rshl_u32)
    (qshl_s8, qshl_s16, qshl_s32, qshl_u8, qshl_u16, qshl_u32): Add
    casts to uses of -sizeof(), fix boundary conditions.

[-- Attachment #2: neon-minus-sizeof-fixes-2.diff --]
[-- Type: text/x-patch, Size: 2472 bytes --]

Index: target-arm/neon_helper.c
===================================================================
--- target-arm/neon_helper.c	(revision 222269)
+++ target-arm/neon_helper.c	(working copy)
@@ -392,7 +392,7 @@ NEON_VOP(abd_u32, neon_u32, 1)
 #define NEON_FN(dest, src1, src2) do { \
     int8_t tmp; \
     tmp = (int8_t)src2; \
-    if (tmp >= sizeof(src1) * 8 || tmp <= -sizeof(src1) * 8) { \
+    if (abs(tmp) >= sizeof(src1) * 8) { \
         dest = 0; \
     } else if (tmp < 0) { \
         dest = src1 >> -tmp; \
@@ -422,7 +422,7 @@ uint64_t HELPER(neon_shl_u64)(uint64_t v
     tmp = (int8_t)src2; \
     if (tmp >= sizeof(src1) * 8) { \
         dest = 0; \
-    } else if (tmp <= -sizeof(src1) * 8) { \
+    } else if (tmp <= -(int) (sizeof(src1) * 8)) { \
         dest = src1 >> (sizeof(src1) * 8 - 1); \
     } else if (tmp < 0) { \
         dest = src1 >> -tmp; \
@@ -455,9 +455,9 @@ uint64_t HELPER(neon_shl_s64)(uint64_t v
     tmp = (int8_t)src2; \
     if (tmp >= sizeof(src1) * 8) { \
         dest = 0; \
-    } else if (tmp < -sizeof(src1) * 8) { \
+    } else if (tmp < -(int) (sizeof(src1) * 8)) { \
         dest >>= sizeof(src1) * 8 - 1; \
-    } else if (tmp == -sizeof(src1) * 8) { \
+    } else if (tmp == -(int) (sizeof(src1) * 8)) { \
         dest = src1 >> (tmp - 1); \
         dest++; \
         src2 >>= 1; \
@@ -494,9 +494,9 @@ uint64_t HELPER(neon_rshl_s64)(uint64_t 
 #define NEON_FN(dest, src1, src2) do { \
     int8_t tmp; \
     tmp = (int8_t)src2; \
-    if (tmp >= sizeof(src1) * 8 || tmp < -sizeof(src1) * 8) { \
+    if (abs(tmp) >= sizeof(src1) * 8) { \
         dest = 0; \
-    } else if (tmp == -sizeof(src1) * 8) { \
+    } else if (tmp == -(int) (sizeof(src1) * 8)) { \
         dest = src1 >> (tmp - 1); \
     } else if (tmp < 0) { \
         dest = (src1 + (1 << (-1 - tmp))) >> -tmp; \
@@ -535,7 +535,7 @@ uint64_t HELPER(neon_rshl_u64)(uint64_t 
         } else { \
             dest = 0; \
         } \
-    } else if (tmp <= -sizeof(src1) * 8) { \
+    } else if (tmp <= -(int) (sizeof(src1) * 8)) { \
         dest = 0; \
     } else if (tmp < 0) { \
         dest = src1 >> -tmp; \
@@ -583,7 +583,7 @@ uint64_t HELPER(neon_qshl_u64)(CPUState 
         if (src1) \
             SET_QC(); \
         dest = src1 >> 31; \
-    } else if (tmp <= -sizeof(src1) * 8) { \
+    } else if (tmp <= -(int) (sizeof(src1) * 8)) { \
         dest = src1 >> 31; \
     } else if (tmp < 0) { \
         dest = src1 >> -tmp; \

                 reply	other threads:[~2009-01-27 17:47 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=20090127174732.27db1f88@rex.config \
    --to=julian@codesourcery.com \
    --cc=paul@codesourcery.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).