Patchwork [42/48] target-arm: fix signed narrow 64->32 operation

login
register
mail settings
Submitter Riku Voipio
Date March 26, 2010, 4:07 p.m.
Message ID <7d5786fe88c6fb3555cb4c24846d7cfae97994ae.1269617187.git.riku.voipio@nokia.com>
Download mbox | patch
Permalink /patch/48684/
State New
Headers show

Comments

Riku Voipio - March 26, 2010, 4:07 p.m.
From: Juha Riihimäki <juha.riihimaki@nokia.com>

Signed-Off-By: Riku Voipio <riku.voipio@nokia.com>
Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
---
 target-arm/neon_helper.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

Patch

diff --git a/target-arm/neon_helper.c b/target-arm/neon_helper.c
index 4604698..910f84a 100644
--- a/target-arm/neon_helper.c
+++ b/target-arm/neon_helper.c
@@ -1183,9 +1183,13 @@  uint32_t HELPER(neon_narrow_sat_u32)(CPUState *env, uint64_t x)
 
 uint32_t HELPER(neon_narrow_sat_s32)(CPUState *env, uint64_t x)
 {
-    if ((int64_t)x != (int32_t)x) {
+    if ((int64_t)x < -2147483648ll) {
         SET_QC();
-        return (x >> 63) ^ 0x7fffffff;
+        return 0x80000000;
+    }
+    if ((int64_t)x > 2147483647ll) {
+        SET_QC();
+        return 0x7fffffff;
     }
     return x;
 }