Module: xenomai-head
Branch: master
Commit: faa90ba52966623ecf7a070d3ea278f54d92c0ef
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=faa90ba52966623ecf7a070d3ea278f54d92c0ef

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sun Aug 23 18:32:08 2009 +0200

Fix quotient and remainder after pseudo-division.

After xnarch_nodiv_llimd, the quotient may be off by one,
leading to a wrong remainder. Test whether we are in this
case and fix the quotient and remainder if need be.

---

 include/asm-generic/bits/timeconv.h |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/bits/timeconv.h 
b/include/asm-generic/bits/timeconv.h
index 79060b3..aa595fe 100644
--- a/include/asm-generic/bits/timeconv.h
+++ b/include/asm-generic/bits/timeconv.h
@@ -60,10 +60,17 @@ long long xnarch_ns_to_tsc(long long ns)
 unsigned long long xnarch_divrem_billion(unsigned long long value,
                                         unsigned long *rem)
 {
-       unsigned long long r;
-       r = xnarch_nodiv_ullimd(value, bln_frac.frac, bln_frac.integ);
-       *rem = value - r * 1000000000;
-       return r;
+       unsigned long long q;
+       unsigned r;
+
+       q = xnarch_nodiv_ullimd(value, bln_frac.frac, bln_frac.integ);
+       r = value - q * 1000000000;
+       if (r >= 1000000000) {
+               ++q;
+               r -= 1000000000;
+       }
+       *rem = r;
+       return q;
 }
 #else /* !XNARCH_HAVE_NODIV_LLIMD */
 long long xnarch_ns_to_tsc(long long ns)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to