1
2
3
4
5
6
7
8
9#define SI_TYPE_SIZE 32
10#define __BITS4 (SI_TYPE_SIZE / 4)
11#define __ll_B (1L << (SI_TYPE_SIZE / 2))
12#define __ll_lowpart(t) ((USItype) (t) % __ll_B)
13#define __ll_highpart(t) ((USItype) (t) / __ll_B)
14
15#define umul_ppmm(w1, w0, u, v) \
16 do { \
17 USItype __x0, __x1, __x2, __x3; \
18 USItype __ul, __vl, __uh, __vh; \
19 \
20 __ul = __ll_lowpart (u); \
21 __uh = __ll_highpart (u); \
22 __vl = __ll_lowpart (v); \
23 __vh = __ll_highpart (v); \
24 \
25 __x0 = (USItype) __ul * __vl; \
26 __x1 = (USItype) __ul * __vh; \
27 __x2 = (USItype) __uh * __vl; \
28 __x3 = (USItype) __uh * __vh; \
29 \
30 __x1 += __ll_highpart (__x0); \
31 __x1 += __x2; \
32 if (__x1 < __x2) \
33 __x3 += __ll_B; \
34 \
35 (w1) = __x3 + __ll_highpart (__x1); \
36 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
37 } while (0)
38
39#define __umulsidi3(u, v) \
40 ({DIunion __w; \
41 umul_ppmm (__w.s.high, __w.s.low, u, v); \
42 __w.ll; })
43
44typedef int SItype __attribute__ ((mode (SI)));
45typedef unsigned int USItype __attribute__ ((mode (SI)));
46typedef int DItype __attribute__ ((mode (DI)));
47typedef int word_type __attribute__ ((mode (__word__)));
48
49struct DIstruct {SItype high, low;};
50
51typedef union
52{
53 struct DIstruct s;
54 DItype ll;
55} DIunion;
56
57DItype __muldi3 (DItype u, DItype v)
58{
59 DIunion w;
60 DIunion uu, vv;
61
62 uu.ll = u,
63 vv.ll = v;
64
65 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
66 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
67 + (USItype) uu.s.high * (USItype) vv.s.low);
68
69 return w.ll;
70}
71