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