2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc32 / sparcv8 / udiv_qrnnd.S
blobc3f097118fc18f4c5dab20ef046264e341a09bc5
1 ! SPARC  __udiv_qrnnd division support, used from longlong.h.
3 ! Copyright (C) 1993, 1994 Free Software Foundation, Inc.
5 ! This file is part of the GNU MP Library.
7 ! The GNU MP Library is free software; you can redistribute it and/or modify
8 ! it under the terms of the GNU Lesser General Public License as published by
9 ! the Free Software Foundation; either version 2.1 of the License, or (at your
10 ! option) any later version.
12 ! The GNU MP Library is distributed in the hope that it will be useful, but
13 ! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ! or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 ! License for more details.
17 ! You should have received a copy of the GNU Lesser General Public License
18 ! along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19 ! the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 ! INPUT PARAMETERS
23 ! rem_ptr       o0
24 ! n1            o1
25 ! n0            o2
26 ! d             o3
28 #include "sysdep.h"
30 ENTRY(__udiv_qrnnd)
31         tst     %o3
32         bneg    LOC(largedivisor)
33         mov     8,%g1
35         b       LOC(p1)
36         addxcc  %o2,%o2,%o2
38 LOC(plop):
39         bcc     LOC(n1)
40         addxcc  %o2,%o2,%o2
41 LOC(p1):
42         addx    %o1,%o1,%o1
43         subcc   %o1,%o3,%o4
44         bcc     LOC(n2)
45         addxcc  %o2,%o2,%o2
46 LOC(p2):
47         addx    %o1,%o1,%o1
48         subcc   %o1,%o3,%o4
49         bcc     LOC(n3)
50         addxcc  %o2,%o2,%o2
51 LOC(p3):
52         addx    %o1,%o1,%o1
53         subcc   %o1,%o3,%o4
54         bcc     LOC(n4)
55         addxcc  %o2,%o2,%o2
56 LOC(p4):
57         addx    %o1,%o1,%o1
58         addcc   %g1,-1,%g1
59         bne     LOC(plop)
60         subcc   %o1,%o3,%o4
61         bcc     LOC(n5)
62         addxcc  %o2,%o2,%o2
63 LOC(p5):
64         st      %o1,[%o0]
65         retl
66         xnor    %g0,%o2,%o0
68 LOC(nlop):
69         bcc     LOC(p1)
70         addxcc  %o2,%o2,%o2
71 LOC(n1):
72         addx    %o4,%o4,%o4
73         subcc   %o4,%o3,%o1
74         bcc     LOC(p2)
75         addxcc  %o2,%o2,%o2
76 LOC(n2):
77         addx    %o4,%o4,%o4
78         subcc   %o4,%o3,%o1
79         bcc     LOC(p3)
80         addxcc  %o2,%o2,%o2
81 LOC(n3):
82         addx    %o4,%o4,%o4
83         subcc   %o4,%o3,%o1
84         bcc     LOC(p4)
85         addxcc  %o2,%o2,%o2
86 LOC(n4):
87         addx    %o4,%o4,%o4
88         addcc   %g1,-1,%g1
89         bne     LOC(nlop)
90         subcc   %o4,%o3,%o1
91         bcc     LOC(p5)
92         addxcc  %o2,%o2,%o2
93 LOC(n5):
94         st      %o4,[%o0]
95         retl
96         xnor    %g0,%o2,%o0
98 LOC(largedivisor):
99         and     %o2,1,%o5       ! %o5 = n0 & 1
101         srl     %o2,1,%o2
102         sll     %o1,31,%g2
103         or      %g2,%o2,%o2     ! %o2 = lo(n1n0 >> 1)
104         srl     %o1,1,%o1       ! %o1 = hi(n1n0 >> 1)
106         and     %o3,1,%g2
107         srl     %o3,1,%g3       ! %g3 = floor(d / 2)
108         add     %g3,%g2,%g3     ! %g3 = ceil(d / 2)
110         b       LOC(Lp1)
111         addxcc  %o2,%o2,%o2
113 LOC(Lplop):
114         bcc     LOC(Ln1)
115         addxcc  %o2,%o2,%o2
116 LOC(Lp1):
117         addx    %o1,%o1,%o1
118         subcc   %o1,%g3,%o4
119         bcc     LOC(Ln2)
120         addxcc  %o2,%o2,%o2
121 LOC(Lp2):
122         addx    %o1,%o1,%o1
123         subcc   %o1,%g3,%o4
124         bcc     LOC(Ln3)
125         addxcc  %o2,%o2,%o2
126 LOC(Lp3):
127         addx    %o1,%o1,%o1
128         subcc   %o1,%g3,%o4
129         bcc     LOC(Ln4)
130         addxcc  %o2,%o2,%o2
131 LOC(Lp4):
132         addx    %o1,%o1,%o1
133         addcc   %g1,-1,%g1
134         bne     LOC(Lplop)
135         subcc   %o1,%g3,%o4
136         bcc     LOC(Ln5)
137         addxcc  %o2,%o2,%o2
138 LOC(Lp5):
139         add     %o1,%o1,%o1     ! << 1
140         tst     %g2
141         bne     LOC(Oddp)
142         add     %o5,%o1,%o1
143         st      %o1,[%o0]
144         retl
145         xnor    %g0,%o2,%o0
147 LOC(Lnlop):
148         bcc     LOC(Lp1)
149         addxcc  %o2,%o2,%o2
150 LOC(Ln1):
151         addx    %o4,%o4,%o4
152         subcc   %o4,%g3,%o1
153         bcc     LOC(Lp2)
154         addxcc  %o2,%o2,%o2
155 LOC(Ln2):
156         addx    %o4,%o4,%o4
157         subcc   %o4,%g3,%o1
158         bcc     LOC(Lp3)
159         addxcc  %o2,%o2,%o2
160 LOC(Ln3):
161         addx    %o4,%o4,%o4
162         subcc   %o4,%g3,%o1
163         bcc     LOC(Lp4)
164         addxcc  %o2,%o2,%o2
165 LOC(Ln4):
166         addx    %o4,%o4,%o4
167         addcc   %g1,-1,%g1
168         bne     LOC(Lnlop)
169         subcc   %o4,%g3,%o1
170         bcc     LOC(Lp5)
171         addxcc  %o2,%o2,%o2
172 LOC(Ln5):
173         add     %o4,%o4,%o4     ! << 1
174         tst     %g2
175         bne     LOC(Oddn)
176         add     %o5,%o4,%o4
177         st      %o4,[%o0]
178         retl
179         xnor    %g0,%o2,%o0
181 LOC(Oddp):
182         xnor    %g0,%o2,%o2
183         ! q' in %o2. r' in %o1
184         addcc   %o1,%o2,%o1
185         bcc     LOC(Lp6)
186         addx    %o2,0,%o2
187         sub     %o1,%o3,%o1
188 LOC(Lp6):
189         subcc   %o1,%o3,%g0
190         bcs     LOC(Lp7)
191         subx    %o2,-1,%o2
192         sub     %o1,%o3,%o1
193 LOC(Lp7):
194         st      %o1,[%o0]
195         retl
196         mov     %o2,%o0
198 LOC(Oddn):
199         xnor    %g0,%o2,%o2
200         ! q' in %o2. r' in %o4
201         addcc   %o4,%o2,%o4
202         bcc     LOC(Ln6)
203         addx    %o2,0,%o2
204         sub     %o4,%o3,%o4
205 LOC(Ln6):
206         subcc   %o4,%o3,%g0
207         bcs     LOC(Ln7)
208         subx    %o2,-1,%o2
209         sub     %o4,%o3,%o4
210 LOC(Ln7):
211         st      %o4,[%o0]
212         retl
213         mov     %o2,%o0
215 END(__udiv_qrnnd)