vfs: Make __vfs_write() static
[linux/fpc-iii.git] / arch / powerpc / math-emu / udivmodti4.c
blob1e52633dcbb7d83042556f2d297147a73d8af95f
1 // SPDX-License-Identifier: GPL-2.0
2 /* This has so very few changes over libgcc2's __udivmoddi4 it isn't funny. */
4 #include <math-emu/soft-fp.h>
6 #undef count_leading_zeros
7 #define count_leading_zeros __FP_CLZ
9 void
10 _fp_udivmodti4(_FP_W_TYPE q[2], _FP_W_TYPE r[2],
11 _FP_W_TYPE n1, _FP_W_TYPE n0,
12 _FP_W_TYPE d1, _FP_W_TYPE d0)
14 _FP_W_TYPE q0, q1, r0, r1;
15 _FP_I_TYPE b, bm;
17 if (d1 == 0)
19 #if !UDIV_NEEDS_NORMALIZATION
20 if (d0 > n1)
22 /* 0q = nn / 0D */
24 udiv_qrnnd (q0, n0, n1, n0, d0);
25 q1 = 0;
27 /* Remainder in n0. */
29 else
31 /* qq = NN / 0d */
33 if (d0 == 0)
34 d0 = 1 / d0; /* Divide intentionally by zero. */
36 udiv_qrnnd (q1, n1, 0, n1, d0);
37 udiv_qrnnd (q0, n0, n1, n0, d0);
39 /* Remainder in n0. */
42 r0 = n0;
43 r1 = 0;
45 #else /* UDIV_NEEDS_NORMALIZATION */
47 if (d0 > n1)
49 /* 0q = nn / 0D */
51 count_leading_zeros (bm, d0);
53 if (bm != 0)
55 /* Normalize, i.e. make the most significant bit of the
56 denominator set. */
58 d0 = d0 << bm;
59 n1 = (n1 << bm) | (n0 >> (_FP_W_TYPE_SIZE - bm));
60 n0 = n0 << bm;
63 udiv_qrnnd (q0, n0, n1, n0, d0);
64 q1 = 0;
66 /* Remainder in n0 >> bm. */
68 else
70 /* qq = NN / 0d */
72 if (d0 == 0)
73 d0 = 1 / d0; /* Divide intentionally by zero. */
75 count_leading_zeros (bm, d0);
77 if (bm == 0)
79 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
80 conclude (the most significant bit of n1 is set) /\ (the
81 leading quotient digit q1 = 1).
83 This special case is necessary, not an optimization.
84 (Shifts counts of SI_TYPE_SIZE are undefined.) */
86 n1 -= d0;
87 q1 = 1;
89 else
91 _FP_W_TYPE n2;
93 /* Normalize. */
95 b = _FP_W_TYPE_SIZE - bm;
97 d0 = d0 << bm;
98 n2 = n1 >> b;
99 n1 = (n1 << bm) | (n0 >> b);
100 n0 = n0 << bm;
102 udiv_qrnnd (q1, n1, n2, n1, d0);
105 /* n1 != d0... */
107 udiv_qrnnd (q0, n0, n1, n0, d0);
109 /* Remainder in n0 >> bm. */
112 r0 = n0 >> bm;
113 r1 = 0;
114 #endif /* UDIV_NEEDS_NORMALIZATION */
116 else
118 if (d1 > n1)
120 /* 00 = nn / DD */
122 q0 = 0;
123 q1 = 0;
125 /* Remainder in n1n0. */
126 r0 = n0;
127 r1 = n1;
129 else
131 /* 0q = NN / dd */
133 count_leading_zeros (bm, d1);
134 if (bm == 0)
136 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
137 conclude (the most significant bit of n1 is set) /\ (the
138 quotient digit q0 = 0 or 1).
140 This special case is necessary, not an optimization. */
142 /* The condition on the next line takes advantage of that
143 n1 >= d1 (true due to program flow). */
144 if (n1 > d1 || n0 >= d0)
146 q0 = 1;
147 sub_ddmmss (n1, n0, n1, n0, d1, d0);
149 else
150 q0 = 0;
152 q1 = 0;
154 r0 = n0;
155 r1 = n1;
157 else
159 _FP_W_TYPE m1, m0, n2;
161 /* Normalize. */
163 b = _FP_W_TYPE_SIZE - bm;
165 d1 = (d1 << bm) | (d0 >> b);
166 d0 = d0 << bm;
167 n2 = n1 >> b;
168 n1 = (n1 << bm) | (n0 >> b);
169 n0 = n0 << bm;
171 udiv_qrnnd (q0, n1, n2, n1, d1);
172 umul_ppmm (m1, m0, q0, d0);
174 if (m1 > n1 || (m1 == n1 && m0 > n0))
176 q0--;
177 sub_ddmmss (m1, m0, m1, m0, d1, d0);
180 q1 = 0;
182 /* Remainder in (n1n0 - m1m0) >> bm. */
183 sub_ddmmss (n1, n0, n1, n0, m1, m0);
184 r0 = (n1 << b) | (n0 >> bm);
185 r1 = n1 >> bm;
190 q[0] = q0; q[1] = q1;
191 r[0] = r0, r[1] = r1;