1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 92-98, 1999 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License.
29 /* support functions required by the kernel. based on code from gcc-2.95.3 */
30 /* I Molton 29/07/01 */
35 static const u8 __clz_tab[] = {
36 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
37 5, 5, 5, 5, 5, 5, 5, 5,
38 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
39 6, 6, 6, 6, 6, 6, 6, 6,
40 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
41 7, 7, 7, 7, 7, 7, 7, 7,
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,
43 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,
45 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,
47 8, 8, 8, 8, 8, 8, 8, 8,
48 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
49 8, 8, 8, 8, 8, 8, 8, 8,
50 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
51 8, 8, 8, 8, 8, 8, 8, 8,
54 u64 __udivmoddi4(u64 n, u64 d, u64 * rp)
59 u32 d0, d1, n0, n1, n2;
75 count_leading_zeros(bm, d0);
78 /* Normalize, i.e. make the most significant bit of the
82 n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
86 udiv_qrnnd(q0, n0, n1, n0, d0);
89 /* Remainder in n0 >> bm. */
94 d0 = 1 / d0; /* Divide intentionally by zero. */
96 count_leading_zeros(bm, d0);
99 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
100 conclude (the most significant bit of n1 is set) /\ (the
101 leading quotient digit q1 = 1).
103 This special case is necessary, not an optimization.
104 (Shifts counts of SI_TYPE_SIZE are undefined.) */
111 b = SI_TYPE_SIZE - bm;
115 n1 = (n1 << bm) | (n0 >> b);
118 udiv_qrnnd(q1, n1, n2, n1, d0);
123 udiv_qrnnd(q0, n0, n1, n0, d0);
125 /* Remainder in n0 >> bm. */
140 /* Remainder in n1n0. */
149 count_leading_zeros(bm, d1);
151 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
152 conclude (the most significant bit of n1 is set) /\ (the
153 quotient digit q0 = 0 or 1).
155 This special case is necessary, not an optimization. */
157 /* The condition on the next line takes advantage of that
158 n1 >= d1 (true due to program flow). */
159 if (n1 > d1 || n0 >= d0) {
161 sub_ddmmss(n1, n0, n1, n0, d1, d0);
176 b = SI_TYPE_SIZE - bm;
178 d1 = (d1 << bm) | (d0 >> b);
181 n1 = (n1 << bm) | (n0 >> b);
184 udiv_qrnnd(q0, n1, n2, n1, d1);
185 umul_ppmm(m1, m0, q0, d0);
187 if (m1 > n1 || (m1 == n1 && m0 > n0)) {
189 sub_ddmmss(m1, m0, m1, m0, d1, d0);
194 /* Remainder in (n1n0 - m1m0) >> bm. */
196 sub_ddmmss(n1, n0, n1, n0, m1, m0);
197 rr.s.low = (n1 << b) | (n0 >> bm);
198 rr.s.high = n1 >> bm;
210 u64 __udivdi3(u64 n, u64 d)
212 return __udivmoddi4(n, d, (u64 *) 0);
215 u64 __umoddi3(u64 u, u64 v)
219 (void)__udivmoddi4(u, v, &w);