1/* Alpha 21064 __udiv_qrnnd
2 *
3 *      Copyright (C) 1992, 1994, 1995, 1998,
4 *                    2001, 2002 Free Software Foundation, Inc.
5 *
6 * This file is part of Libgcrypt.
7 *
8 * Libgcrypt is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * Libgcrypt is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 *
22 * Note: This code is heavily based on the GNU MP Library.
23 *	 Actually it's the same code with only minor changes in the
24 *	 way the data is stored; this is to support the abstraction
25 *	 of an optional secure memory allocation which may be used
26 *	 to avoid revealing of sensitive data due to paging etc.
27 */
28
29
30
31	.set noreorder
32	.set noat
33.text
34	.align	3
35	.globl	__udiv_qrnnd
36	.ent	__udiv_qrnnd
37__udiv_qrnnd:
38	.frame $30,0,$26,0
39	.prologue 0
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
48	ldiq	cnt,16
49	blt	d,.Largedivisor
50
51.Loop1: cmplt	n0,0,tmp
52	addq	n1,n1,n1
53	bis	n1,tmp,n1
54	addq	n0,n0,n0
55	cmpule	d,n1,qb
56	subq	n1,d,tmp
57	cmovne	qb,tmp,n1
58	bis	n0,qb,n0
59	cmplt	n0,0,tmp
60	addq	n1,n1,n1
61	bis	n1,tmp,n1
62	addq	n0,n0,n0
63	cmpule	d,n1,qb
64	subq	n1,d,tmp
65	cmovne	qb,tmp,n1
66	bis	n0,qb,n0
67	cmplt	n0,0,tmp
68	addq	n1,n1,n1
69	bis	n1,tmp,n1
70	addq	n0,n0,n0
71	cmpule	d,n1,qb
72	subq	n1,d,tmp
73	cmovne	qb,tmp,n1
74	bis	n0,qb,n0
75	cmplt	n0,0,tmp
76	addq	n1,n1,n1
77	bis	n1,tmp,n1
78	addq	n0,n0,n0
79	cmpule	d,n1,qb
80	subq	n1,d,tmp
81	cmovne	qb,tmp,n1
82	bis	n0,qb,n0
83	subq	cnt,1,cnt
84	bgt	cnt,.Loop1
85	stq	n1,0(rem_ptr)
86	bis	$31,n0,$0
87	ret	$31,($26),1
88
89.Largedivisor:
90	and	n0,1,$4
91
92	srl	n0,1,n0
93	sll	n1,63,tmp
94	or	tmp,n0,n0
95	srl	n1,1,n1
96
97	and	d,1,$6
98	srl	d,1,$5
99	addq	$5,$6,$5
100
101.Loop2: cmplt	n0,0,tmp
102	addq	n1,n1,n1
103	bis	n1,tmp,n1
104	addq	n0,n0,n0
105	cmpule	$5,n1,qb
106	subq	n1,$5,tmp
107	cmovne	qb,tmp,n1
108	bis	n0,qb,n0
109	cmplt	n0,0,tmp
110	addq	n1,n1,n1
111	bis	n1,tmp,n1
112	addq	n0,n0,n0
113	cmpule	$5,n1,qb
114	subq	n1,$5,tmp
115	cmovne	qb,tmp,n1
116	bis	n0,qb,n0
117	cmplt	n0,0,tmp
118	addq	n1,n1,n1
119	bis	n1,tmp,n1
120	addq	n0,n0,n0
121	cmpule	$5,n1,qb
122	subq	n1,$5,tmp
123	cmovne	qb,tmp,n1
124	bis	n0,qb,n0
125	cmplt	n0,0,tmp
126	addq	n1,n1,n1
127	bis	n1,tmp,n1
128	addq	n0,n0,n0
129	cmpule	$5,n1,qb
130	subq	n1,$5,tmp
131	cmovne	qb,tmp,n1
132	bis	n0,qb,n0
133	subq	cnt,1,cnt
134	bgt	cnt,.Loop2
135
136	addq	n1,n1,n1
137	addq	$4,n1,n1
138	bne	$6,.LOdd
139	stq	n1,0(rem_ptr)
140	bis	$31,n0,$0
141	ret	$31,($26),1
142
143.LOdd:
144	/* q' in n0. r' in n1 */
145	addq	n1,n0,n1
146	cmpult	n1,n0,tmp	# tmp := carry from addq
147	beq	tmp,.LLp6
148	addq	n0,1,n0
149	subq	n1,d,n1
150.LLp6:	cmpult	n1,d,tmp
151	bne	tmp,.LLp7
152	addq	n0,1,n0
153	subq	n1,d,n1
154.LLp7:
155	stq	n1,0(rem_ptr)
156	bis	$31,n0,$0
157	ret	$31,($26),1
158
159	.end	__udiv_qrnnd
160