Michal Simek | 3370d82 | 2010-12-07 11:55:06 +0100 | [diff] [blame] | 1 | #include <linux/module.h> |
| 2 | |
| 3 | #include "libgcc.h" |
| 4 | |
Michal Simek | 3370d82 | 2010-12-07 11:55:06 +0100 | [diff] [blame] | 5 | #define W_TYPE_SIZE 32 |
| 6 | |
Michal Simek | a671de0 | 2012-12-13 17:46:31 +0100 | [diff] [blame^] | 7 | #define __ll_B ((unsigned long) 1 << (W_TYPE_SIZE / 2)) |
| 8 | #define __ll_lowpart(t) ((unsigned long) (t) & (__ll_B - 1)) |
| 9 | #define __ll_highpart(t) ((unsigned long) (t) >> (W_TYPE_SIZE / 2)) |
Michal Simek | 3370d82 | 2010-12-07 11:55:06 +0100 | [diff] [blame] | 10 | |
| 11 | /* If we still don't have umul_ppmm, define it using plain C. */ |
| 12 | #if !defined(umul_ppmm) |
| 13 | #define umul_ppmm(w1, w0, u, v) \ |
| 14 | do { \ |
Michal Simek | a671de0 | 2012-12-13 17:46:31 +0100 | [diff] [blame^] | 15 | unsigned long __x0, __x1, __x2, __x3; \ |
| 16 | unsigned short __ul, __vl, __uh, __vh; \ |
Michal Simek | 3370d82 | 2010-12-07 11:55:06 +0100 | [diff] [blame] | 17 | \ |
| 18 | __ul = __ll_lowpart(u); \ |
| 19 | __uh = __ll_highpart(u); \ |
| 20 | __vl = __ll_lowpart(v); \ |
| 21 | __vh = __ll_highpart(v); \ |
| 22 | \ |
Michal Simek | a671de0 | 2012-12-13 17:46:31 +0100 | [diff] [blame^] | 23 | __x0 = (unsigned long) __ul * __vl; \ |
| 24 | __x1 = (unsigned long) __ul * __vh; \ |
| 25 | __x2 = (unsigned long) __uh * __vl; \ |
| 26 | __x3 = (unsigned long) __uh * __vh; \ |
Michal Simek | 3370d82 | 2010-12-07 11:55:06 +0100 | [diff] [blame] | 27 | \ |
| 28 | __x1 += __ll_highpart(__x0); /* this can't give carry */\ |
| 29 | __x1 += __x2; /* but this indeed can */ \ |
| 30 | if (__x1 < __x2) /* did we get it? */ \ |
| 31 | __x3 += __ll_B; /* yes, add it in the proper pos */ \ |
| 32 | \ |
| 33 | (w1) = __x3 + __ll_highpart(__x1); \ |
| 34 | (w0) = __ll_lowpart(__x1) * __ll_B + __ll_lowpart(__x0);\ |
| 35 | } while (0) |
| 36 | #endif |
| 37 | |
| 38 | #if !defined(__umulsidi3) |
| 39 | #define __umulsidi3(u, v) ({ \ |
| 40 | DWunion __w; \ |
| 41 | umul_ppmm(__w.s.high, __w.s.low, u, v); \ |
| 42 | __w.ll; \ |
| 43 | }) |
| 44 | #endif |
| 45 | |
Michal Simek | a671de0 | 2012-12-13 17:46:31 +0100 | [diff] [blame^] | 46 | long long __muldi3(long long u, long long v) |
Michal Simek | 3370d82 | 2010-12-07 11:55:06 +0100 | [diff] [blame] | 47 | { |
| 48 | const DWunion uu = {.ll = u}; |
| 49 | const DWunion vv = {.ll = v}; |
| 50 | DWunion w = {.ll = __umulsidi3(uu.s.low, vv.s.low)}; |
| 51 | |
Michal Simek | a671de0 | 2012-12-13 17:46:31 +0100 | [diff] [blame^] | 52 | w.s.high += ((unsigned long) uu.s.low * (unsigned long) vv.s.high |
| 53 | + (unsigned long) uu.s.high * (unsigned long) vv.s.low); |
Michal Simek | 3370d82 | 2010-12-07 11:55:06 +0100 | [diff] [blame] | 54 | |
| 55 | return w.ll; |
| 56 | } |
Michal Simek | d50c303 | 2011-02-24 15:36:49 +0100 | [diff] [blame] | 57 | EXPORT_SYMBOL(__muldi3); |