1 /* Copyright (C) 1996-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <https://www.gnu.org/licenses/>. */
57 _ITOFT2 X, $f0, 0, Y, $f1, 8
65 /* Check to see if X fit in the double as an exact value. */
71 /* If we get here, we're expecting exact results from the division.
72 Do nothing else besides convert and clean up. */
93 /* If we get here, X is large enough that we don't expect exact
94 results, and neither X nor Y got mis-translated for the fp
95 division. Our task is to take the fp result, figure out how
96 far it's off from the correct result and compute a fixup. */
98 #define Q v0 /* quotient */
99 #define R t0 /* remainder */
100 #define SY t1 /* scaled Y */
101 #define S t2 /* scalar */
102 #define QY t3 /* Q*Y */
104 /* The fixup code below can only handle unsigned values. */
135 /* The quotient that we computed was too large. We need to reduce
136 it by S such that Y*S >= R. Obviously the closer we get to the
137 correct value the better, but overshooting high is ok, as we'll
138 fix that up later. */
152 /* The quotient that we computed was too small. Divide Y by the
153 current remainder (R) and add that to the existing quotient (Q).
154 The expectation, of course, is that R is much smaller than X. */
155 /* Begin with a shift-up loop. Compute S such that Y*S >= R. We
156 already have a copy of Y in SY and the value 1 in S. */
164 /* Shift-down and subtract loop. Each iteration compares our scaled
165 Y (SY) with the remainder (R); if SY <= R then X is divisible by
166 Y's scalar (S) so add it to the quotient (Q). */
181 /* If we got here, then X|Y is negative. Need to adjust everything
182 such that we're doing unsigned division in the fixup loop. */
183 /* T5 is true if result should be negative. */
194 blbc t5, $fix_sign_in_ret1
216 weak_alias (ldiv, lldiv)
217 weak_alias (ldiv, imaxdiv)