]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/blackfin/lib/muldi3.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / blackfin / lib / muldi3.c
1 /*
2 * U-boot - muldi3.c contains routines for mult and div
3 *
4 * Copyright (c) 2005-2007 Analog Devices Inc.
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9 /* Generic function got from GNU gcc package, libgcc2.c */
10 #ifndef SI_TYPE_SIZE
11 #define SI_TYPE_SIZE 32
12 #endif
13 #define __ll_B (1L << (SI_TYPE_SIZE / 2))
14 #define __ll_lowpart(t) ((USItype) (t) % __ll_B)
15 #define __ll_highpart(t) ((USItype) (t) / __ll_B)
16 #define BITS_PER_UNIT 8
17
18 #if !defined (umul_ppmm)
19 #define umul_ppmm(w1, w0, u, v) \
20 do { \
21 USItype __x0, __x1, __x2, __x3; \
22 USItype __ul, __vl, __uh, __vh; \
23 \
24 __ul = __ll_lowpart (u); \
25 __uh = __ll_highpart (u); \
26 __vl = __ll_lowpart (v); \
27 __vh = __ll_highpart (v); \
28 \
29 __x0 = (USItype) __ul * __vl; \
30 __x1 = (USItype) __ul * __vh; \
31 __x2 = (USItype) __uh * __vl; \
32 __x3 = (USItype) __uh * __vh; \
33 \
34 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
35 __x1 += __x2; /* but this indeed can */ \
36 if (__x1 < __x2) /* did we get it? */ \
37 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
38 \
39 (w1) = __x3 + __ll_highpart (__x1); \
40 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
41 } while (0)
42 #endif
43
44 #if !defined (__umulsidi3)
45 #define __umulsidi3(u, v) \
46 ({DIunion __w; \
47 umul_ppmm (__w.s.high, __w.s.low, u, v); \
48 __w.ll; })
49 #endif
50
51 typedef unsigned int USItype __attribute__ ((mode(SI)));
52 typedef int SItype __attribute__ ((mode(SI)));
53 typedef int DItype __attribute__ ((mode(DI)));
54 typedef int word_type __attribute__ ((mode(__word__)));
55
56 struct DIstruct {
57 SItype low, high;
58 };
59 typedef union {
60 struct DIstruct s;
61 DItype ll;
62 } DIunion;
63
64 DItype __muldi3(DItype u, DItype v)
65 {
66 DIunion w;
67 DIunion uu, vv;
68
69 uu.ll = u, vv.ll = v;
70 /* panic("kernel panic for __muldi3"); */
71 w.ll = __umulsidi3(uu.s.low, vv.s.low);
72 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
73 + (USItype) uu.s.high * (USItype) vv.s.low);
74
75 return w.ll;
76 }