xref: /linux/arch/alpha/lib/udiv-qrnnd.S (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
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#include <asm/export.h>
29
30        .set noreorder
31        .set noat
32
33	.text
34
35	.globl __udiv_qrnnd
36	.ent __udiv_qrnnd
37__udiv_qrnnd:
38	.frame $30,0,$26,0
39	.prologue 0
40
41#define cnt	$2
42#define tmp	$3
43#define rem_ptr	$16
44#define n1	$17
45#define n0	$18
46#define d	$19
47#define qb	$20
48#define AT	$at
49
50	ldiq	cnt,16
51	blt	d,$largedivisor
52
53$loop1:	cmplt	n0,0,tmp
54	addq	n1,n1,n1
55	bis	n1,tmp,n1
56	addq	n0,n0,n0
57	cmpule	d,n1,qb
58	subq	n1,d,tmp
59	cmovne	qb,tmp,n1
60	bis	n0,qb,n0
61	cmplt	n0,0,tmp
62	addq	n1,n1,n1
63	bis	n1,tmp,n1
64	addq	n0,n0,n0
65	cmpule	d,n1,qb
66	subq	n1,d,tmp
67	cmovne	qb,tmp,n1
68	bis	n0,qb,n0
69	cmplt	n0,0,tmp
70	addq	n1,n1,n1
71	bis	n1,tmp,n1
72	addq	n0,n0,n0
73	cmpule	d,n1,qb
74	subq	n1,d,tmp
75	cmovne	qb,tmp,n1
76	bis	n0,qb,n0
77	cmplt	n0,0,tmp
78	addq	n1,n1,n1
79	bis	n1,tmp,n1
80	addq	n0,n0,n0
81	cmpule	d,n1,qb
82	subq	n1,d,tmp
83	cmovne	qb,tmp,n1
84	bis	n0,qb,n0
85	subq	cnt,1,cnt
86	bgt	cnt,$loop1
87	stq	n1,0(rem_ptr)
88	bis	$31,n0,$0
89	ret	$31,($26),1
90
91$largedivisor:
92	and	n0,1,$4
93
94	srl	n0,1,n0
95	sll	n1,63,tmp
96	or	tmp,n0,n0
97	srl	n1,1,n1
98
99	and	d,1,$6
100	srl	d,1,$5
101	addq	$5,$6,$5
102
103$loop2:	cmplt	n0,0,tmp
104	addq	n1,n1,n1
105	bis	n1,tmp,n1
106	addq	n0,n0,n0
107	cmpule	$5,n1,qb
108	subq	n1,$5,tmp
109	cmovne	qb,tmp,n1
110	bis	n0,qb,n0
111	cmplt	n0,0,tmp
112	addq	n1,n1,n1
113	bis	n1,tmp,n1
114	addq	n0,n0,n0
115	cmpule	$5,n1,qb
116	subq	n1,$5,tmp
117	cmovne	qb,tmp,n1
118	bis	n0,qb,n0
119	cmplt	n0,0,tmp
120	addq	n1,n1,n1
121	bis	n1,tmp,n1
122	addq	n0,n0,n0
123	cmpule	$5,n1,qb
124	subq	n1,$5,tmp
125	cmovne	qb,tmp,n1
126	bis	n0,qb,n0
127	cmplt	n0,0,tmp
128	addq	n1,n1,n1
129	bis	n1,tmp,n1
130	addq	n0,n0,n0
131	cmpule	$5,n1,qb
132	subq	n1,$5,tmp
133	cmovne	qb,tmp,n1
134	bis	n0,qb,n0
135	subq	cnt,1,cnt
136	bgt	cnt,$loop2
137
138	addq	n1,n1,n1
139	addq	$4,n1,n1
140	bne	$6,$Odd
141	stq	n1,0(rem_ptr)
142	bis	$31,n0,$0
143	ret	$31,($26),1
144
145$Odd:
146	/* q' in n0. r' in n1 */
147	addq	n1,n0,n1
148
149	cmpult	n1,n0,tmp	# tmp := carry from addq
150	subq	n1,d,AT
151	addq	n0,tmp,n0
152	cmovne	tmp,AT,n1
153
154	cmpult	n1,d,tmp
155	addq	n0,1,AT
156	cmoveq	tmp,AT,n0
157	subq	n1,d,AT
158	cmoveq	tmp,AT,n1
159
160	stq	n1,0(rem_ptr)
161	bis	$31,n0,$0
162	ret	$31,($26),1
163
164	.end	__udiv_qrnnd
165EXPORT_SYMBOL(__udiv_qrnnd)
166