2
* This file is part of GNU CC.
4
* SPDX-License-Identifier: GPL-2.0+
7
typedef unsigned int UWtype;
8
typedef unsigned int UHWtype;
9
typedef unsigned long long UDWtype;
10
#define W_TYPE_SIZE 32
12
typedef unsigned char UQItype;
14
typedef unsigned long USItype;
15
typedef long long DItype;
16
typedef unsigned long long DSItype;
21
typedef int word_type;
23
typedef long long DWtype;
25
struct DWstruct { Wtype low, high;};
33
#define BITS_PER_UNIT 8
36
__udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp);
38
const UQItype __clz_tab[256] =
40
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
41
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
42
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
43
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
44
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
45
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
46
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
47
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
52
__ashldi3 (DWtype u, word_type b)
57
const DWunion uu = {.ll = u};
58
const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
64
w.s.high = (UWtype) uu.s.low << -bm;
68
const UWtype carries = (UWtype) uu.s.low >> bm;
70
w.s.low = (UWtype) uu.s.low << b;
71
w.s.high = ((UWtype) uu.s.high << b) | carries;
78
__ashrdi3 (DWtype u, word_type b)
83
const DWunion uu = {.ll = u};
84
const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
89
/* w.s.high = 1..1 or 0..0 */
90
w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
91
w.s.low = uu.s.high >> -bm;
95
const UWtype carries = (UWtype) uu.s.high << bm;
97
w.s.high = uu.s.high >> b;
98
w.s.low = ((UWtype) uu.s.low >> b) | carries;
105
__lshrdi3 (DWtype u, word_type b)
110
const DWunion uu = {.ll = u};
111
const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
117
w.s.low = (UWtype) uu.s.high >> -bm;
121
const UWtype carries = (UWtype) uu.s.high << bm;
123
w.s.high = (UWtype) uu.s.high >> b;
124
w.s.low = ((UWtype) uu.s.low >> b) | carries;
131
__cmpdi2 (DWtype a, DWtype b)
133
const DWunion au = {.ll = a};
134
const DWunion bu = {.ll = b};
136
if (au.s.high < bu.s.high)
138
else if (au.s.high > bu.s.high)
140
if ((UWtype) au.s.low < (UWtype) bu.s.low)
142
else if ((UWtype) au.s.low > (UWtype) bu.s.low)
148
__udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
150
const DWunion nn = {.ll = n};
151
const DWunion dd = {.ll = d};
153
UWtype d0, d1, n0, n1, n2;
162
#if !UDIV_NEEDS_NORMALIZATION
169
udiv_qrnnd (q0, n0, n1, n0, d0);
172
/* Remainder in n0. */
179
d0 = 1 / d0; /* Divide intentionally by zero. */
181
udiv_qrnnd (q1, n1, 0, n1, d0);
182
udiv_qrnnd (q0, n0, n1, n0, d0);
184
/* Remainder in n0. */
195
#else /* UDIV_NEEDS_NORMALIZATION */
203
count_leading_zeros (bm, d0);
207
/* Normalize, i.e. make the most significant bit of the
211
n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
215
udiv_qrnnd (q0, n0, n1, n0, d0);
218
/* Remainder in n0 >> bm. */
225
d0 = 1 / d0; /* Divide intentionally by zero. */
227
count_leading_zeros (bm, d0);
231
/* From (n1 >= d0) /\ (the most significant bit of d0 is set),
232
conclude (the most significant bit of n1 is set) /\ (the
233
leading quotient digit q1 = 1).
235
This special case is necessary, not an optimization.
236
(Shifts counts of W_TYPE_SIZE are undefined.) */
245
b = W_TYPE_SIZE - bm;
249
n1 = (n1 << bm) | (n0 >> b);
252
udiv_qrnnd (q1, n1, n2, n1, d0);
257
udiv_qrnnd (q0, n0, n1, n0, d0);
259
/* Remainder in n0 >> bm. */
269
#endif /* UDIV_NEEDS_NORMALIZATION */
280
/* Remainder in n1n0. */
292
count_leading_zeros (bm, d1);
295
/* From (n1 >= d1) /\ (the most significant bit of d1 is set),
296
conclude (the most significant bit of n1 is set) /\ (the
297
quotient digit q0 = 0 or 1).
299
This special case is necessary, not an optimization. */
301
/* The condition on the next line takes advantage of that
302
n1 >= d1 (true due to program flow). */
303
if (n1 > d1 || n0 >= d0)
306
sub_ddmmss (n1, n0, n1, n0, d1, d0);
325
b = W_TYPE_SIZE - bm;
327
d1 = (d1 << bm) | (d0 >> b);
330
n1 = (n1 << bm) | (n0 >> b);
333
udiv_qrnnd (q0, n1, n2, n1, d1);
334
umul_ppmm (m1, m0, q0, d0);
336
if (m1 > n1 || (m1 == n1 && m0 > n0))
339
sub_ddmmss (m1, m0, m1, m0, d1, d0);
344
/* Remainder in (n1n0 - m1m0) >> bm. */
347
sub_ddmmss (n1, n0, n1, n0, m1, m0);
348
rr.s.low = (n1 << b) | (n0 >> bm);
349
rr.s.high = n1 >> bm;
356
const DWunion ww = {{.low = q0, .high = q1}};
361
__divdi3 (DWtype u, DWtype v)
364
DWunion uu = {.ll = u};
365
DWunion vv = {.ll = v};
375
w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
385
const DWunion uu = {.ll = u};
386
const DWunion w = { {.low = -uu.s.low,
387
.high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
394
__muldi3 (DWtype u, DWtype v)
396
const DWunion uu = {.ll = u};
397
const DWunion vv = {.ll = v};
398
DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
400
w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
401
+ (UWtype) uu.s.high * (UWtype) vv.s.low);
407
__moddi3 (DWtype u, DWtype v)
410
DWunion uu = {.ll = u};
411
DWunion vv = {.ll = v};
420
(void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
428
__ucmpdi2 (DWtype a, DWtype b)
430
const DWunion au = {.ll = a};
431
const DWunion bu = {.ll = b};
433
if ((UWtype) au.s.high < (UWtype) bu.s.high)
435
else if ((UWtype) au.s.high > (UWtype) bu.s.high)
437
if ((UWtype) au.s.low < (UWtype) bu.s.low)
439
else if ((UWtype) au.s.low > (UWtype) bu.s.low)
446
__udivdi3 (UDWtype n, UDWtype d)
448
return __udivmoddi4 (n, d, (UDWtype *) 0);
452
__umoddi3 (UDWtype u, UDWtype v)
455
(void) __udivmoddi4 (u, v, &w);
461
udivmodsi4(USItype num, USItype den, word_type modwanted)
466
while (den < num && bit && !(den & (1L<<31)))
481
if (modwanted) return num;
486
__divsi3 (SItype a, SItype b)
503
res = udivmodsi4 (a, b, 0);
513
__udivsi3 (SItype a, SItype b)
515
return udivmodsi4 (a, b, 0);
520
__modsi3 (SItype a, SItype b)
534
res = udivmodsi4 (a, b, 1);
543
__mulsi3 (SItype a, SItype b)
562
__umodsi3 (SItype a, SItype b)
565
return udivmodsi4 (a, b, 1);
569
__gcc_bcmp (const unsigned char *s1, const unsigned char *s2, unsigned long size)
573
const unsigned char c1 = *s1++, c2 = *s2++;