1 #ifndef __LUNAIX_MULDIV64_H
2 #define __LUNAIX_MULDIV64_H
4 #include <lunaix/spike.h>
5 #include <lunaix/types.h>
7 #define do_udiv64(n, base) \
9 unsigned long __upper, __low, __high, __mod, __base; \
11 if (__builtin_constant_p(__base) && is_pot(__base)) { \
12 __mod = n & (__base - 1); \
13 n >>= ILOG2(__base); \
15 asm("" : "=a"(__low), "=d"(__high) : "A"(n)); \
18 __upper = __high % (__base); \
19 __high = __high / (__base); \
22 : "=a"(__low), "=d"(__mod) \
23 : "rm"(__base), "0"(__low), "1"(__upper)); \
24 asm("" : "=A"(n) : "a"(__low), "d"(__high)); \
30 udiv64(u64_t n, unsigned int base)
37 static inline unsigned int
38 umod64(u64_t n, unsigned int base)
40 return do_udiv64(n, base);
43 #endif /* __LUNAIX_MULDIV64_H */