2 * U-boot - muldi3.c contains routines for mult and div
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
24 /* Generic function got from GNU gcc package, libgcc2.c */
26 #define SI_TYPE_SIZE 32
28 #define __ll_B (1L << (SI_TYPE_SIZE / 2))
29 #define __ll_lowpart(t) ((USItype) (t) % __ll_B)
30 #define __ll_highpart(t) ((USItype) (t) / __ll_B)
31 #define BITS_PER_UNIT 8
33 #if !defined(umul_ppmm)
34 #define umul_ppmm(w1, w0, u, v) \
36 USItype __x0, __x1, __x2, __x3; \
37 USItype __ul, __vl, __uh, __vh; \
39 __ul = __ll_lowpart(u); \
40 __uh = __ll_highpart(u); \
41 __vl = __ll_lowpart(v); \
42 __vh = __ll_highpart(v); \
44 __x0 = (USItype) __ul * __vl; \
45 __x1 = (USItype) __ul * __vh; \
46 __x2 = (USItype) __uh * __vl; \
47 __x3 = (USItype) __uh * __vh; \
49 __x1 += __ll_highpart(__x0); /* this can't give carry */\
50 __x1 += __x2; /* but this indeed can */ \
51 if (__x1 < __x2) /* did we get it? */ \
52 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
54 (w1) = __x3 + __ll_highpart(__x1); \
55 (w0) = __ll_lowpart(__x1) * __ll_B + __ll_lowpart(__x0);\
59 #if !defined(__umulsidi3)
60 #define __umulsidi3(u, v) \
62 umul_ppmm(__w.s.high, __w.s.low, u, v); \
66 typedef unsigned int USItype __attribute__ ((mode(SI)));
67 typedef int SItype __attribute__ ((mode(SI)));
68 typedef int DItype __attribute__ ((mode(DI)));
69 typedef int word_type __attribute__ ((mode(__word__)));
79 DItype __muldi3(DItype u, DItype v)
85 /* panic("kernel panic for __muldi3"); */
86 w.ll = __umulsidi3(uu.s.low, vv.s.low);
87 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
88 + (USItype) uu.s.high * (USItype) vv.s.low);