]> git.ipfire.org Git - people/ms/u-boot.git/blame - 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
CommitLineData
6cb142fa
WD
1/*
2 * U-boot - muldi3.c contains routines for mult and div
3 *
155fd766 4 * Copyright (c) 2005-2007 Analog Devices Inc.
6cb142fa 5 *
1a459660 6 * SPDX-License-Identifier: GPL-2.0+
6cb142fa
WD
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) \
20do { \
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
3f0606ad
AL
51typedef unsigned int USItype __attribute__ ((mode(SI)));
52typedef int SItype __attribute__ ((mode(SI)));
53typedef int DItype __attribute__ ((mode(DI)));
54typedef int word_type __attribute__ ((mode(__word__)));
6cb142fa 55
3f0606ad
AL
56struct DIstruct {
57 SItype low, high;
58};
59typedef union {
6cb142fa
WD
60 struct DIstruct s;
61 DItype ll;
62} DIunion;
63
3f0606ad 64DItype __muldi3(DItype u, DItype v)
6cb142fa
WD
65{
66 DIunion w;
67 DIunion uu, vv;
8e7b703a 68
3f0606ad 69 uu.ll = u, vv.ll = v;
6cb142fa 70 /* panic("kernel panic for __muldi3"); */
3f0606ad 71 w.ll = __umulsidi3(uu.s.low, vv.s.low);
6cb142fa 72 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
3f0606ad 73 + (USItype) uu.s.high * (USItype) vv.s.low);
8e7b703a 74
6cb142fa
WD
75 return w.ll;
76}