xen: implement an signed 64 bit division helper function
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Mon, 23 Jan 2012 09:40:35 +0000 (09:40 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Mon, 23 Jan 2012 09:40:35 +0000 (09:40 +0000)
Implement a C function to perform 64 bit signed division and return
both quotient and remainder.
Useful as an helper function to implement __aeabi_ldivmod.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Committed-by: Keir Fraser <keir@xen.org>
xen/common/lib.c

index 4ae637c47836fd21629fed94f7746bd60d455eb6..e9d0637b68150e7fabb1e9e90602b64c13aef7f1 100644 (file)
@@ -399,6 +399,25 @@ s64 __moddi3(s64 a, s64 b)
     return (neg ? -urem : urem);
 }
 
+/*
+ * Quotient and remainder of unsigned long long division
+ */
+s64 __ldivmod_helper(s64 a, s64 b, s64 *r)
+{
+    u64 ua, ub, rem, quot;
+
+    ua = ABS(a);
+    ub = ABS(b);
+    quot = __qdivrem(ua, ub, &rem);
+    if ( a < 0 )
+        *r = -rem;
+    else
+        *r = rem;
+    if ( (a < 0) ^ (b < 0) )
+        return -quot;
+    else
+        return quot;
+}
 #endif /* BITS_PER_LONG == 32 */
 
 /* Compute with 96 bit intermediate result: (a*b)/c */