1 # Alpha 21064 __udiv_qrnnd
2 # Copyright (C) 1992, 1994, 1995, 2000 Free Software Foundation, Inc.
3
4 # This file is part of GCC.
5
6 # The GNU MP Library is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or (at your
9 # option) any later version.
10
11 # In addition to the permissions in the GNU General Public License, the
12 # Free Software Foundation gives you unlimited permission to link the
13 # compiled version of this file with other programs, and to distribute
14 # those programs without any restriction coming from the use of this
15 # file.  (The General Public License restrictions do apply in other
16 # respects; for example, they cover modification of the file, and
17 # distribution when not linked into another program.)
18
19 # This file is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
22 # License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with GCC; see the file COPYING.  If not, write to the
26 # Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 # MA 02111-1307, USA.
28
29        .set noreorder
30        .set noat
31
32	.text
33
34	.globl __udiv_qrnnd
35	.ent __udiv_qrnnd
36__udiv_qrnnd:
37	.frame $30,0,$26,0
38	.prologue 0
39
40#define cnt	$2
41#define tmp	$3
42#define rem_ptr	$16
43#define n1	$17
44#define n0	$18
45#define d	$19
46#define qb	$20
47#define AT	$at
48
49	ldiq	cnt,16
50	blt	d,$largedivisor
51
52$loop1:	cmplt	n0,0,tmp
53	addq	n1,n1,n1
54	bis	n1,tmp,n1
55	addq	n0,n0,n0
56	cmpule	d,n1,qb
57	subq	n1,d,tmp
58	cmovne	qb,tmp,n1
59	bis	n0,qb,n0
60	cmplt	n0,0,tmp
61	addq	n1,n1,n1
62	bis	n1,tmp,n1
63	addq	n0,n0,n0
64	cmpule	d,n1,qb
65	subq	n1,d,tmp
66	cmovne	qb,tmp,n1
67	bis	n0,qb,n0
68	cmplt	n0,0,tmp
69	addq	n1,n1,n1
70	bis	n1,tmp,n1
71	addq	n0,n0,n0
72	cmpule	d,n1,qb
73	subq	n1,d,tmp
74	cmovne	qb,tmp,n1
75	bis	n0,qb,n0
76	cmplt	n0,0,tmp
77	addq	n1,n1,n1
78	bis	n1,tmp,n1
79	addq	n0,n0,n0
80	cmpule	d,n1,qb
81	subq	n1,d,tmp
82	cmovne	qb,tmp,n1
83	bis	n0,qb,n0
84	subq	cnt,1,cnt
85	bgt	cnt,$loop1
86	stq	n1,0(rem_ptr)
87	bis	$31,n0,$0
88	ret	$31,($26),1
89
90$largedivisor:
91	and	n0,1,$4
92
93	srl	n0,1,n0
94	sll	n1,63,tmp
95	or	tmp,n0,n0
96	srl	n1,1,n1
97
98	and	d,1,$6
99	srl	d,1,$5
100	addq	$5,$6,$5
101
102$loop2:	cmplt	n0,0,tmp
103	addq	n1,n1,n1
104	bis	n1,tmp,n1
105	addq	n0,n0,n0
106	cmpule	$5,n1,qb
107	subq	n1,$5,tmp
108	cmovne	qb,tmp,n1
109	bis	n0,qb,n0
110	cmplt	n0,0,tmp
111	addq	n1,n1,n1
112	bis	n1,tmp,n1
113	addq	n0,n0,n0
114	cmpule	$5,n1,qb
115	subq	n1,$5,tmp
116	cmovne	qb,tmp,n1
117	bis	n0,qb,n0
118	cmplt	n0,0,tmp
119	addq	n1,n1,n1
120	bis	n1,tmp,n1
121	addq	n0,n0,n0
122	cmpule	$5,n1,qb
123	subq	n1,$5,tmp
124	cmovne	qb,tmp,n1
125	bis	n0,qb,n0
126	cmplt	n0,0,tmp
127	addq	n1,n1,n1
128	bis	n1,tmp,n1
129	addq	n0,n0,n0
130	cmpule	$5,n1,qb
131	subq	n1,$5,tmp
132	cmovne	qb,tmp,n1
133	bis	n0,qb,n0
134	subq	cnt,1,cnt
135	bgt	cnt,$loop2
136
137	addq	n1,n1,n1
138	addq	$4,n1,n1
139	bne	$6,$Odd
140	stq	n1,0(rem_ptr)
141	bis	$31,n0,$0
142	ret	$31,($26),1
143
144$Odd:
145	/* q' in n0. r' in n1 */
146	addq	n1,n0,n1
147
148	cmpult	n1,n0,tmp	# tmp := carry from addq
149	subq	n1,d,AT
150	addq	n0,tmp,n0
151	cmovne	tmp,AT,n1
152
153	cmpult	n1,d,tmp
154	addq	n0,1,AT
155	cmoveq	tmp,AT,n0
156	subq	n1,d,AT
157	cmoveq	tmp,AT,n1
158
159	stq	n1,0(rem_ptr)
160	bis	$31,n0,$0
161	ret	$31,($26),1
162
163	.end	__udiv_qrnnd
164