Skip to contentSkip to conversation

target-arm: fix sdiv helper

PATCH In review Aurelien Jarno 2 participants 2 messages Oct 15, 2009 – Oct 18, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm: fix sdiv helper

(INT32_MIN / -1) triggers an overflow, and the result depends on the host architecture (INT32_MIN on arm, -1 on ppc, SIGFPE on x86). Use a test to output the correct value.

---
 target-arm/helper.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
target-arm/helper.c +2 -0
index 701629a..b3d6198 100644
@@ -404,6 +404,8 @@ int32_t HELPER(sdiv)(int32_t num, int32_t den)
 {
     if (den == 0)
       return 0;
+    if (num == INT_MIN && den == -1)
+      return INT_MIN;
     return num / den;
 }
 
Signature · 1 line
1.6.1.3
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Aurelien Jarno

(INT32_MIN / -1) triggers an overflow, and the result depends on the host architecture (INT32_MIN on arm, -1 on ppc, SIGFPE on x86). Use a test to output the correct value.

---
 target-arm/helper.c |    2 ++

 1 files changed, 2 insertions(+), 0 deletions(-)
target-arm/helper.c +2 -1
index 701629a..b3d6198 100644
@@ -404,6 +404,8 @@ int32_t HELPER(sdiv)(int32_t num, int32_t den)
  {
     if (den == 0)
       return 0;
+    if (num == INT_MIN && den == -1)
+      return INT_MIN;
     return num / den;
  }
 
--
Quoted 1 line

1.6.1.3

That is provided we accept the behaviour for division by zero is not strictly conforming to what the ARM ARM says.

Also note this instruction is not available on v7-A CPU's (Cortex-A8 for instance). It's part of v7-R (Cortex R4).

Laurent