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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Jun  2 18:24:24 2009 +0200

Introduce xnarch_divrem_billion

We need an efficient helper to divide a long long value by 10e9 and
collect the remainder.

---

 include/asm-generic/arith.h         |    1 +
 include/asm-generic/bits/timeconv.h |   16 ++++++++++++++++
 include/asm-generic/system.h        |    3 +++
 include/asm-sim/system.h            |    9 +++++++++
 4 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/include/asm-generic/arith.h b/include/asm-generic/arith.h
index 70a134e..dac9ccb 100644
--- a/include/asm-generic/arith.h
+++ b/include/asm-generic/arith.h
@@ -382,6 +382,7 @@ static inline void xnarch_init_llmulshft(const unsigned 
m_in,
 #define xnarch_imuldiv               rthal_imuldiv
 #define xnarch_imuldiv_ceil          rthal_imuldiv_ceil
 #define xnarch_llimd                 rthal_llimd
+#define xnarch_nodiv_ullimd          rthal_nodiv_ullimd
 #define xnarch_nodiv_llimd           rthal_nodiv_llimd
 #define xnarch_llmulshft             rthal_llmulshft
 #define xnarch_get_cpu_tsc           rthal_rdtsc
diff --git a/include/asm-generic/bits/timeconv.h 
b/include/asm-generic/bits/timeconv.h
index e6f4d11..c2635fc 100644
--- a/include/asm-generic/bits/timeconv.h
+++ b/include/asm-generic/bits/timeconv.h
@@ -27,6 +27,7 @@ static unsigned long long cpufreq;
 static unsigned int tsc_scale, tsc_shift;
 #ifdef XNARCH_HAVE_NODIV_LLIMD
 static rthal_u32frac_t tsc_frac;
+static rthal_u32frac_t bln_frac;
 #endif
 #endif
 
@@ -56,11 +57,25 @@ long long xnarch_ns_to_tsc(long long ns)
 {
        return xnarch_nodiv_llimd(ns, tsc_frac.frac, tsc_frac.integ);
 }
+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 - xnarch_ullmul(r, 1000000000);
+       return r;
+}
 #else /* !XNARCH_HAVE_NODIV_LLIMD */
 long long xnarch_ns_to_tsc(long long ns)
 {
        return xnarch_llimd(ns, cpufreq, 1000000000);
 }
+unsigned long long xnarch_divrem_billion(unsigned long long value,
+                                        unsigned long *rem)
+{
+       return xnarch_ulldiv(value, 1000000000, rem);
+
+}
 #endif /* !XNARCH_HAVE_NODIV_LLIMD */
 
 static inline void xnarch_init_timeconv(unsigned long long freq)
@@ -70,6 +85,7 @@ static inline void xnarch_init_timeconv(unsigned long long 
freq)
        xnarch_init_llmulshft(1000000000, freq, &tsc_scale, &tsc_shift);
 #ifdef XNARCH_HAVE_NODIV_LLIMD
        xnarch_init_u32frac(&tsc_frac, 1 << tsc_shift, tsc_scale);
+       xnarch_init_u32frac(&bln_frac, 1, 1000000000);
 #endif
 #endif
 }
diff --git a/include/asm-generic/system.h b/include/asm-generic/system.h
index 7d68a9d..fcec613 100644
--- a/include/asm-generic/system.h
+++ b/include/asm-generic/system.h
@@ -287,6 +287,9 @@ long long xnarch_ns_to_tsc(long long ns);
 
 unsigned long long xnarch_get_cpu_time(void);
 
+unsigned long long xnarch_divrem_billion(unsigned long long value,
+                                        unsigned long *rem);
+
 static inline unsigned long long xnarch_get_cpu_freq(void)
 {
        return RTHAL_CPU_FREQ;
diff --git a/include/asm-sim/system.h b/include/asm-sim/system.h
index 5162bef..1df58c6 100644
--- a/include/asm-sim/system.h
+++ b/include/asm-sim/system.h
@@ -418,6 +418,15 @@ static inline unsigned long long xnarch_ns_to_tsc 
(unsigned long long ns)
     return ns;
 }
 
+unsigned long long xnarch_divrem_billion(unsigned long long value,
+                                        unsigned long *rem)
+{
+       unsigned long long r;
+       r = value / 1000000000ULL;
+       *rem = value - (r * 1000000000ULL);
+       return r;
+}
+
 static inline unsigned long long xnarch_get_cpu_time (void)
 {
     return mvm_get_cpu_time();


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

Reply via email to