1 /* Header file for libgcc2.c. */
2 /* Copyright (C) 2000, 2001, 2004, 2005, 2009
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 typedef int SItype
__attribute__ ((mode (SI
)));
27 typedef unsigned int USItype
__attribute__ ((mode (SI
)));
28 typedef int DItype
__attribute__ ((mode (DI
)));
29 typedef unsigned int UDItype
__attribute__ ((mode (DI
)));
31 #define BITS_PER_UNIT 8
32 #define W_TYPE_SIZE (4 * BITS_PER_UNIT)
35 #define UWtype USItype
36 #define UDWtype UDItype
38 struct DWstruct
{Wtype low
, high
;};
46 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
47 __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}" \
48 : "=r" ((USItype) (sh)), \
49 "=&r" ((USItype) (sl)) \
50 : "0" ((USItype) (ah)), \
51 "g" ((USItype) (bh)), \
52 "1" ((USItype) (al)), \
55 #define umul_ppmm(w1, w0, u, v) \
56 __asm__ ("mul{l} %3" \
57 : "=a" ((USItype) (w0)), \
58 "=d" ((USItype) (w1)) \
59 : "%0" ((USItype) (u)), \
61 #define udiv_qrnnd(q, r, n1, n0, dv) \
62 __asm__ ("div{l} %4" \
63 : "=a" ((USItype) (q)), \
64 "=d" ((USItype) (r)) \
65 : "0" ((USItype) (n0)), \
66 "1" ((USItype) (n1)), \
67 "rm" ((USItype) (dv)))
69 #define count_leading_zeros(count, x) ((count) = __builtin_clz (x))
72 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
74 const DWunion nn
= {.ll
= n
};
75 const DWunion dd
= {.ll
= d
};
77 UWtype d0
, d1
, n0
, n1
, n2
;
92 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
95 /* Remainder in n0. */
102 d0
= 1 / d0
; /* Divide intentionally by zero. */
104 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
105 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
107 /* Remainder in n0. */
128 /* Remainder in n1n0. */
140 count_leading_zeros (bm
, d1
);
143 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
144 conclude (the most significant bit of n1 is set) /\ (the
145 quotient digit q0 = 0 or 1).
147 This special case is necessary, not an optimization. */
149 /* The condition on the next line takes advantage of that
150 n1 >= d1 (true due to program flow). */
151 if (n1
> d1
|| n0
>= d0
)
154 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
173 b
= W_TYPE_SIZE
- bm
;
175 d1
= (d1
<< bm
) | (d0
>> b
);
178 n1
= (n1
<< bm
) | (n0
>> b
);
181 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
182 umul_ppmm (m1
, m0
, q0
, d0
);
184 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
187 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
192 /* Remainder in (n1n0 - m1m0) >> bm. */
195 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
196 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
197 rr
.s
.high
= n1
>> bm
;
204 const DWunion ww
= {{.low
= q0
, .high
= q1
}};
209 __udivdi3 (UDWtype n
, UDWtype d
)
211 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
215 __umoddi3 (UDWtype u
, UDWtype v
)
219 (void) __udivmoddi4 (u
, v
, &w
);