Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / libgmp / mpn / alpha / udiv_qrnnd.S
1 /* $Id$
2  # Alpha 21064 __udiv_qrnnd
3
4  # Copyright (C) 1992, 1994, 1995 Free Software Foundation, Inc.
5
6  # This file is part of the GNU MP Library.
7
8  # The GNU MP Library is free software; you can redistribute it and/or modify
9  # it under the terms of the GNU Library General Public License as published by
10  # the Free Software Foundation; either version 2 of the License, or (at your
11  # option) any later version.
12
13  # The GNU MP Library is distributed in the hope that it will be useful, but
14  # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
16  # License for more details.
17
18  # You should have received a copy of the GNU Library General Public License
19  # along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20  # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21  # MA 02111-1307, USA.
22 */
23
24
25         .set noreorder
26         .set noat
27 .text
28         .align  3
29         .globl  __udiv_qrnnd
30         .ent    __udiv_qrnnd
31 __udiv_qrnnd:
32         .frame $30,0,$26,0
33         .prologue 0
34 #define cnt     $2
35 #define tmp     $3
36 #define rem_ptr $16
37 #define n1      $17
38 #define n0      $18
39 #define d       $19
40 #define qb      $20
41
42         ldiq    cnt,16
43         blt     d,.Largedivisor
44
45 .Loop1: cmplt   n0,0,tmp
46         addq    n1,n1,n1
47         bis     n1,tmp,n1
48         addq    n0,n0,n0
49         cmpule  d,n1,qb
50         subq    n1,d,tmp
51         cmovne  qb,tmp,n1
52         bis     n0,qb,n0
53         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         subq    cnt,1,cnt
78         bgt     cnt,.Loop1
79         stq     n1,0(rem_ptr)
80         bis     $31,n0,$0
81         ret     $31,($26),1
82
83 .Largedivisor:
84         and     n0,1,$4
85
86         srl     n0,1,n0
87         sll     n1,63,tmp
88         or      tmp,n0,n0
89         srl     n1,1,n1
90
91         and     d,1,$6
92         srl     d,1,$5
93         addq    $5,$6,$5
94
95 .Loop2: cmplt   n0,0,tmp
96         addq    n1,n1,n1
97         bis     n1,tmp,n1
98         addq    n0,n0,n0
99         cmpule  $5,n1,qb
100         subq    n1,$5,tmp
101         cmovne  qb,tmp,n1
102         bis     n0,qb,n0
103         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         subq    cnt,1,cnt
128         bgt     cnt,.Loop2
129
130         addq    n1,n1,n1
131         addq    $4,n1,n1
132         bne     $6,.LOdd
133         stq     n1,0(rem_ptr)
134         bis     $31,n0,$0
135         ret     $31,($26),1
136
137 .LOdd:
138         /* q' in n0. r' in n1 */
139         addq    n1,n0,n1
140         cmpult  n1,n0,tmp       # tmp := carry from addq
141         beq     tmp,.LLp6
142         addq    n0,1,n0
143         subq    n1,d,n1
144 .LLp6:  cmpult  n1,d,tmp
145         bne     tmp,.LLp7
146         addq    n0,1,n0
147         subq    n1,d,n1
148 .LLp7:
149         stq     n1,0(rem_ptr)
150         bis     $31,n0,$0
151         ret     $31,($26),1
152
153         .end    __udiv_qrnnd