qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Fix -sizeof(foo) in target-arm/neon_helper.c shift helpers
@ 2009-01-27 17:47 Julian Brown
  0 siblings, 0 replies; only message in thread
From: Julian Brown @ 2009-01-27 17:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: paul

[-- 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; \

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-01-27 17:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-27 17:47 [Qemu-devel] Fix -sizeof(foo) in target-arm/neon_helper.c shift helpers Julian Brown

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).