Linux 4.13.16
[linux/fpc-iii.git] / arch / h8300 / lib / muldi3.c
blob7905122435311be7ba3ac62bf4fa829eb82678d2
1 #include "libgcc.h"
3 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
4 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
5 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
7 #define umul_ppmm(w1, w0, u, v) \
8 do { \
9 UWtype __x0, __x1, __x2, __x3; \
10 UHWtype __ul, __vl, __uh, __vh; \
11 __ul = __ll_lowpart(u); \
12 __uh = __ll_highpart(u); \
13 __vl = __ll_lowpart(v); \
14 __vh = __ll_highpart(v); \
15 __x0 = (UWtype) __ul * __vl; \
16 __x1 = (UWtype) __ul * __vh; \
17 __x2 = (UWtype) __uh * __vl; \
18 __x3 = (UWtype) __uh * __vh; \
19 __x1 += __ll_highpart(__x0); \
20 __x1 += __x2; \
21 if (__x1 < __x2) \
22 __x3 += __ll_B; \
23 (w1) = __x3 + __ll_highpart(__x1); \
24 (w0) = __ll_lowpart(__x1) * __ll_B + __ll_lowpart(__x0); \
25 } while (0)
27 #define __umulsidi3(u, v) ( \
28 { \
29 DWunion __w; \
30 umul_ppmm(__w.s.high, __w.s.low, u, v); \
31 __w.ll; } \
34 DWtype __muldi3(DWtype u, DWtype v)
36 const DWunion uu = {.ll = u};
37 const DWunion vv = {.ll = v};
38 DWunion w = {.ll = __umulsidi3(uu.s.low, vv.s.low)};
40 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
41 + (UWtype) uu.s.high * (UWtype) vv.s.low);
43 return w.ll;