From mboxrd@z Thu Jan 1 00:00:00 1970 From: Subject: [PATCH v4 04/25] xen: implement an signed 64 bit division helper function Date: Mon, 9 Jan 2012 17:59:40 +0000 Message-ID: <1326132001-21251-4-git-send-email-stefano.stabellini@eu.citrix.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Tim.Deegan@citrix.com, Ian.Campbell@citrix.com, JBeulich@suse.com, stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org From: Stefano Stabellini 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. Changes in v4: - use ABS(). Signed-off-by: Stefano Stabellini --- xen/common/lib.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/xen/common/lib.c b/xen/common/lib.c index 4ae637c..e9d0637 100644 --- a/xen/common/lib.c +++ b/xen/common/lib.c @@ -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 */ -- 1.7.2.5