1 #include <xen/lib.h> 2 3 /* Compute with 96 bit intermediate result: (a*b)/c */ muldiv64(uint64_t a,uint32_t b,uint32_t c)4uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) 5 { 6 #ifdef CONFIG_X86 7 asm ( "mulq %1; divq %2" : "+a" (a) 8 : "rm" ((uint64_t)b), "rm" ((uint64_t)c) 9 : "rdx" ); 10 11 return a; 12 #else 13 union { 14 uint64_t ll; 15 struct { 16 #ifdef WORDS_BIGENDIAN 17 uint32_t high, low; 18 #else 19 uint32_t low, high; 20 #endif 21 } l; 22 } u, res; 23 uint64_t rl, rh; 24 25 u.ll = a; 26 rl = (uint64_t)u.l.low * (uint64_t)b; 27 rh = (uint64_t)u.l.high * (uint64_t)b; 28 rh += (rl >> 32); 29 res.l.high = rh / c; 30 res.l.low = (((rh % c) << 32) + (uint32_t)rl) / c; 31 32 return res.ll; 33 #endif 34 } 35 36 /* 37 * Local variables: 38 * mode: C 39 * c-file-style: "BSD" 40 * c-basic-offset: 4 41 * tab-width: 4 42 * indent-tabs-mode: nil 43 * End: 44 */ 45