1/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
2
3This file is part of GNU CC.
4
5GNU CC is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2, or (at your option)
8any later version.
9
10GNU CC is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GNU CC; see the file COPYING.  If not, write to
17the Free Software Foundation, 59 Temple Place - Suite 330,
18Boston, MA 02111-1307, USA.  */
19
20	.text
21	.align 4
22	.globl __divdi3
23__divdi3:
24	save %sp,-104,%sp
25	cmp %i0,0
26	bge .LL40
27	mov 0,%l4
28	mov -1,%l4
29	sub %g0,%i1,%o0
30	mov %o0,%o5
31	subcc %g0,%o0,%g0
32	sub %g0,%i0,%o0
33	subx %o0,0,%o4
34	mov %o4,%i0
35	mov %o5,%i1
36.LL40:
37	cmp %i2,0
38	bge .LL84
39	mov %i3,%o4
40	xnor %g0,%l4,%l4
41	sub %g0,%i3,%o0
42	mov %o0,%o3
43	subcc %g0,%o0,%g0
44	sub %g0,%i2,%o0
45	subx %o0,0,%o2
46	mov %o2,%i2
47	mov %o3,%i3
48	mov %i3,%o4
49.LL84:
50	cmp %i2,0
51	bne .LL45
52	mov %i1,%i3
53	cmp %o4,%i0
54	bleu .LL46
55	mov %i3,%o1
56	mov	32,%g1
57	subcc	%i0,%o4,%g0
581:	bcs	5f
59	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
60	sub	%i0,%o4,%i0	! this kills msb of n
61	addx	%i0,%i0,%i0	! so this cannot give carry
62	subcc	%g1,1,%g1
632:	bne	1b
64	 subcc	%i0,%o4,%g0
65	bcs	3f
66	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
67	b	3f
68	 sub	%i0,%o4,%i0	! this kills msb of n
694:	sub	%i0,%o4,%i0
705:	addxcc	%i0,%i0,%i0
71	bcc	2b
72	 subcc	%g1,1,%g1
73! Got carry from n.  Subtract next step to cancel this carry.
74	bne	4b
75	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
76	sub	%i0,%o4,%i0
773:	xnor	%o1,0,%o1
78	b .LL50
79	mov 0,%o2
80.LL46:
81	cmp %o4,0
82	bne .LL85
83	mov %i0,%o2
84	mov 1,%o0
85	mov 0,%o1
86	wr %g0, 0, %y
87	udiv %o0, %o1, %o0
88	mov %o0,%o4
89	mov %i0,%o2
90.LL85:
91	mov 0,%g3
92	mov	32,%g1
93	subcc	%g3,%o4,%g0
941:	bcs	5f
95	 addxcc %o2,%o2,%o2	! shift n1n0 and a q-bit in lsb
96	sub	%g3,%o4,%g3	! this kills msb of n
97	addx	%g3,%g3,%g3	! so this cannot give carry
98	subcc	%g1,1,%g1
992:	bne	1b
100	 subcc	%g3,%o4,%g0
101	bcs	3f
102	 addxcc %o2,%o2,%o2	! shift n1n0 and a q-bit in lsb
103	b	3f
104	 sub	%g3,%o4,%g3	! this kills msb of n
1054:	sub	%g3,%o4,%g3
1065:	addxcc	%g3,%g3,%g3
107	bcc	2b
108	 subcc	%g1,1,%g1
109! Got carry from n.  Subtract next step to cancel this carry.
110	bne	4b
111	 addcc	%o2,%o2,%o2	! shift n1n0 and a 0-bit in lsb
112	sub	%g3,%o4,%g3
1133:	xnor	%o2,0,%o2
114	mov %g3,%i0
115	mov %i3,%o1
116	mov	32,%g1
117	subcc	%i0,%o4,%g0
1181:	bcs	5f
119	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
120	sub	%i0,%o4,%i0	! this kills msb of n
121	addx	%i0,%i0,%i0	! so this cannot give carry
122	subcc	%g1,1,%g1
1232:	bne	1b
124	 subcc	%i0,%o4,%g0
125	bcs	3f
126	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
127	b	3f
128	 sub	%i0,%o4,%i0	! this kills msb of n
1294:	sub	%i0,%o4,%i0
1305:	addxcc	%i0,%i0,%i0
131	bcc	2b
132	 subcc	%g1,1,%g1
133! Got carry from n.  Subtract next step to cancel this carry.
134	bne	4b
135	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
136	sub	%i0,%o4,%i0
1373:	xnor	%o1,0,%o1
138	b .LL86
139	mov %o1,%l1
140.LL45:
141	cmp %i2,%i0
142	bleu .LL51
143	sethi %hi(65535),%o0
144	b .LL78
145	mov 0,%o1
146.LL51:
147	or %o0,%lo(65535),%o0
148	cmp %i2,%o0
149	bgu .LL58
150	mov %i2,%o1
151	cmp %i2,256
152	addx %g0,-1,%o0
153	b .LL64
154	and %o0,8,%o2
155.LL58:
156	sethi %hi(16777215),%o0
157	or %o0,%lo(16777215),%o0
158	cmp %i2,%o0
159	bgu .LL64
160	mov 24,%o2
161	mov 16,%o2
162.LL64:
163	srl %o1,%o2,%o0
164	sethi %hi(__clz_tab),%o1
165	or %o1,%lo(__clz_tab),%o1
166	ldub [%o0+%o1],%o0
167	add %o0,%o2,%o0
168	mov 32,%o1
169	subcc %o1,%o0,%o3
170	bne,a .LL72
171	sub %o1,%o3,%o1
172	cmp %i0,%i2
173	bgu .LL74
174	cmp %i3,%o4
175	blu .LL78
176	mov 0,%o1
177.LL74:
178	b .LL78
179	mov 1,%o1
180.LL72:
181	sll %i2,%o3,%o2
182	srl %o4,%o1,%o0
183	or %o2,%o0,%i2
184	sll %o4,%o3,%o4
185	srl %i0,%o1,%o2
186	sll %i0,%o3,%o0
187	srl %i3,%o1,%o1
188	or %o0,%o1,%i0
189	sll %i3,%o3,%i3
190	mov %i0,%o1
191	mov	32,%g1
192	subcc	%o2,%i2,%g0
1931:	bcs	5f
194	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
195	sub	%o2,%i2,%o2	! this kills msb of n
196	addx	%o2,%o2,%o2	! so this cannot give carry
197	subcc	%g1,1,%g1
1982:	bne	1b
199	 subcc	%o2,%i2,%g0
200	bcs	3f
201	 addxcc %o1,%o1,%o1	! shift n1n0 and a q-bit in lsb
202	b	3f
203	 sub	%o2,%i2,%o2	! this kills msb of n
2044:	sub	%o2,%i2,%o2
2055:	addxcc	%o2,%o2,%o2
206	bcc	2b
207	 subcc	%g1,1,%g1
208! Got carry from n.  Subtract next step to cancel this carry.
209	bne	4b
210	 addcc	%o1,%o1,%o1	! shift n1n0 and a 0-bit in lsb
211	sub	%o2,%i2,%o2
2123:	xnor	%o1,0,%o1
213	mov %o2,%i0
214	wr	%g0,%o1,%y	! SPARC has 0-3 delay insn after a wr
215	sra	%o4,31,%g2	! Do not move this insn
216	and	%o1,%g2,%g2	! Do not move this insn
217	andcc	%g0,0,%g1	! Do not move this insn
218	mulscc	%g1,%o4,%g1
219	mulscc	%g1,%o4,%g1
220	mulscc	%g1,%o4,%g1
221	mulscc	%g1,%o4,%g1
222	mulscc	%g1,%o4,%g1
223	mulscc	%g1,%o4,%g1
224	mulscc	%g1,%o4,%g1
225	mulscc	%g1,%o4,%g1
226	mulscc	%g1,%o4,%g1
227	mulscc	%g1,%o4,%g1
228	mulscc	%g1,%o4,%g1
229	mulscc	%g1,%o4,%g1
230	mulscc	%g1,%o4,%g1
231	mulscc	%g1,%o4,%g1
232	mulscc	%g1,%o4,%g1
233	mulscc	%g1,%o4,%g1
234	mulscc	%g1,%o4,%g1
235	mulscc	%g1,%o4,%g1
236	mulscc	%g1,%o4,%g1
237	mulscc	%g1,%o4,%g1
238	mulscc	%g1,%o4,%g1
239	mulscc	%g1,%o4,%g1
240	mulscc	%g1,%o4,%g1
241	mulscc	%g1,%o4,%g1
242	mulscc	%g1,%o4,%g1
243	mulscc	%g1,%o4,%g1
244	mulscc	%g1,%o4,%g1
245	mulscc	%g1,%o4,%g1
246	mulscc	%g1,%o4,%g1
247	mulscc	%g1,%o4,%g1
248	mulscc	%g1,%o4,%g1
249	mulscc	%g1,%o4,%g1
250	mulscc	%g1,0,%g1
251	add	%g1,%g2,%o0
252	rd	%y,%o2
253	cmp %o0,%i0
254	bgu,a .LL78
255	add %o1,-1,%o1
256	bne,a .LL50
257	mov 0,%o2
258	cmp %o2,%i3
259	bleu .LL50
260	mov 0,%o2
261	add %o1,-1,%o1
262.LL78:
263	mov 0,%o2
264.LL50:
265	mov %o1,%l1
266.LL86:
267	mov %o2,%l0
268	mov %l0,%i0
269	mov %l1,%i1
270	cmp %l4,0
271	be .LL81
272	sub %g0,%i1,%o0
273	mov %o0,%l3
274	subcc %g0,%o0,%g0
275	sub %g0,%i0,%o0
276	subx %o0,0,%l2
277	mov %l2,%i0
278	mov %l3,%i1
279.LL81:
280	ret
281	restore
282