ia64/xen-unstable

changeset 19824:50634c215234

Move muldiv64 out and make it as a public function.

muldiv64 is used to caculate u64*u32/u32, and we
will use it for TSC scaling.

Signed-off-by: Xiantao Zhang <xiantao.zhang@intel.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 24 10:57:00 2009 +0100 (2009-06-24)
parents 82bbce59b65d
children 81edfffb3aff
files xen/arch/x86/hvm/i8254.c xen/common/lib.c xen/include/xen/lib.h
line diff
     1.1 --- a/xen/arch/x86/hvm/i8254.c	Wed Jun 24 10:48:21 2009 +0100
     1.2 +++ b/xen/arch/x86/hvm/i8254.c	Wed Jun 24 10:57:00 2009 +0100
     1.3 @@ -57,30 +57,6 @@ static int handle_speaker_io(
     1.4  #define get_guest_time(v) \
     1.5     (is_hvm_vcpu(v) ? hvm_get_guest_time(v) : (u64)get_s_time())
     1.6  
     1.7 -/* Compute with 96 bit intermediate result: (a*b)/c */
     1.8 -static uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
     1.9 -{
    1.10 -    union {
    1.11 -        uint64_t ll;
    1.12 -        struct {
    1.13 -#ifdef WORDS_BIGENDIAN
    1.14 -            uint32_t high, low;
    1.15 -#else
    1.16 -            uint32_t low, high;
    1.17 -#endif            
    1.18 -        } l;
    1.19 -    } u, res;
    1.20 -    uint64_t rl, rh;
    1.21 -
    1.22 -    u.ll = a;
    1.23 -    rl = (uint64_t)u.l.low * (uint64_t)b;
    1.24 -    rh = (uint64_t)u.l.high * (uint64_t)b;
    1.25 -    rh += (rl >> 32);
    1.26 -    res.l.high = rh / c;
    1.27 -    res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
    1.28 -    return res.ll;
    1.29 -}
    1.30 -
    1.31  static int pit_get_count(PITState *pit, int channel)
    1.32  {
    1.33      uint64_t d;
     2.1 --- a/xen/common/lib.c	Wed Jun 24 10:48:21 2009 +0100
     2.2 +++ b/xen/common/lib.c	Wed Jun 24 10:57:00 2009 +0100
     2.3 @@ -401,6 +401,35 @@ s64 __moddi3(s64 a, s64 b)
     2.4  
     2.5  #endif /* BITS_PER_LONG == 32 */
     2.6  
     2.7 +/* Compute with 96 bit intermediate result: (a*b)/c */
     2.8 +uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)
     2.9 +{
    2.10 +#ifdef __x86_64__
    2.11 +    asm ( "mul %%rdx; div %%rcx" : "=a" (a) : "0" (a), "d" (b), "c" (c) );
    2.12 +    return a;
    2.13 +#else
    2.14 +    union {
    2.15 +        uint64_t ll;
    2.16 +        struct {
    2.17 +#ifdef WORDS_BIGENDIAN
    2.18 +            uint32_t high, low;
    2.19 +#else
    2.20 +            uint32_t low, high;
    2.21 +#endif            
    2.22 +        } l;
    2.23 +    } u, res;
    2.24 +    uint64_t rl, rh;
    2.25 +
    2.26 +    u.ll = a;
    2.27 +    rl = (uint64_t)u.l.low * (uint64_t)b;
    2.28 +    rh = (uint64_t)u.l.high * (uint64_t)b;
    2.29 +    rh += (rl >> 32);
    2.30 +    res.l.high = rh / c;
    2.31 +    res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c;
    2.32 +    return res.ll;
    2.33 +#endif
    2.34 +}
    2.35 +
    2.36  unsigned long long parse_size_and_unit(const char *s, const char **ps)
    2.37  {
    2.38      unsigned long long ret;
     3.1 --- a/xen/include/xen/lib.h	Wed Jun 24 10:48:21 2009 +0100
     3.2 +++ b/xen/include/xen/lib.h	Wed Jun 24 10:57:00 2009 +0100
     3.3 @@ -99,6 +99,8 @@ unsigned long long simple_strtoull(
     3.4  
     3.5  unsigned long long parse_size_and_unit(const char *s, const char **ps);
     3.6  
     3.7 +uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c);
     3.8 +
     3.9  #define TAINT_UNSAFE_SMP                (1<<0)
    3.10  #define TAINT_MACHINE_CHECK             (1<<1)
    3.11  #define TAINT_BAD_PAGE                  (1<<2)