2.9
[glibc/nacl-glibc.git] / sysdeps / sparc / sparc32 / udiv_qrnnd.S
blob4955318a668425b2dd0e892c52d2c2347e336de3
1 ! SPARC  __udiv_qrnnd division support, used from longlong.h.
3 ! Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
5 ! This file is part of the GNU MP Library.
7 ! The GNU MP Library is free software; you can redistribute it and/or modify
8 ! it under the terms of the GNU Lesser General Public License as published by
9 ! the Free Software Foundation; either version 2.1 of the License, or (at your
10 ! option) any later version.
12 ! The GNU MP Library is distributed in the hope that it will be useful, but
13 ! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ! or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 ! License for more details.
17 ! You should have received a copy of the GNU Lesser General Public License
18 ! along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19 ! the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 ! Added PIC support - May/96, Miguel de Icaza
23 ! INPUT PARAMETERS
24 ! rem_ptr       i0
25 ! n1            i1
26 ! n0            i2
27 ! d             i3
29 #include <sysdep.h>
30 #undef ret      /* Kludge for glibc */
32 #ifdef PIC
33         .text
34 #else
35         .section .rodata,#alloc
36 #endif
37         .align  8
39         .type two_to_32,@object
40         .size two_to_32,8
41 two_to_32:
42         .double 0r4294967296
44         .type two_to_31,@object
45         .size two_to_31,8
46 two_to_31:
47         .double 0r2147483648
49         .text
50 ENTRY(__udiv_qrnnd)
51         !#PROLOGUE# 0
52         save    %sp,-104,%sp
53         !#PROLOGUE# 1
54         st      %i1,[%fp-8]
55         ld      [%fp-8],%f10
56 #ifdef PIC
57 LOC(base):
58         call    1f
59         fitod   %f10,%f4
60 1:      ldd     [%o7-(LOC(base)-two_to_32)],%f8
61 #else
62         sethi   %hi(two_to_32),%o7
63         fitod   %f10,%f4
64         ldd     [%o7+%lo(two_to_32)],%f8
65 #endif
66         cmp     %i1,0
67         bge     LOC(248)
68         mov     %i0,%i5
69         faddd   %f4,%f8,%f4
70 LOC(248):
71         st      %i2,[%fp-8]
72         ld      [%fp-8],%f10
73         fmuld   %f4,%f8,%f6
74         cmp     %i2,0
75         bge     LOC(249)
76         fitod   %f10,%f2
77         faddd   %f2,%f8,%f2
78 LOC(249):
79         st      %i3,[%fp-8]
80         faddd   %f6,%f2,%f2
81         ld      [%fp-8],%f10
82         cmp     %i3,0
83         bge     LOC(250)
84         fitod   %f10,%f4
85         faddd   %f4,%f8,%f4
86 LOC(250):
87         fdivd   %f2,%f4,%f2
88 #ifdef PIC
89         ldd     [%o7-(LOC(base)-two_to_31)],%f4
90 #else
91         sethi   %hi(two_to_31),%o7
92         ldd     [%o7+%lo(two_to_31)],%f4
93 #endif
94         fcmped  %f2,%f4
95         nop
96         fbge,a  LOC(251)
97         fsubd   %f2,%f4,%f2
98         fdtoi   %f2,%f2
99         st      %f2,[%fp-8]
100         b       LOC(252)
101         ld      [%fp-8],%i4
102 LOC(251):
103         fdtoi   %f2,%f2
104         st      %f2,[%fp-8]
105         ld      [%fp-8],%i4
106         sethi   %hi(-2147483648),%g2
107         xor     %i4,%g2,%i4
108 LOC(252):
109         wr      %g0,%i4,%y
110         sra     %i3,31,%g2
111         and     %i4,%g2,%g2
112         andcc   %g0,0,%g1
113         mulscc  %g1,%i3,%g1
114         mulscc  %g1,%i3,%g1
115         mulscc  %g1,%i3,%g1
116         mulscc  %g1,%i3,%g1
117         mulscc  %g1,%i3,%g1
118         mulscc  %g1,%i3,%g1
119         mulscc  %g1,%i3,%g1
120         mulscc  %g1,%i3,%g1
121         mulscc  %g1,%i3,%g1
122         mulscc  %g1,%i3,%g1
123         mulscc  %g1,%i3,%g1
124         mulscc  %g1,%i3,%g1
125         mulscc  %g1,%i3,%g1
126         mulscc  %g1,%i3,%g1
127         mulscc  %g1,%i3,%g1
128         mulscc  %g1,%i3,%g1
129         mulscc  %g1,%i3,%g1
130         mulscc  %g1,%i3,%g1
131         mulscc  %g1,%i3,%g1
132         mulscc  %g1,%i3,%g1
133         mulscc  %g1,%i3,%g1
134         mulscc  %g1,%i3,%g1
135         mulscc  %g1,%i3,%g1
136         mulscc  %g1,%i3,%g1
137         mulscc  %g1,%i3,%g1
138         mulscc  %g1,%i3,%g1
139         mulscc  %g1,%i3,%g1
140         mulscc  %g1,%i3,%g1
141         mulscc  %g1,%i3,%g1
142         mulscc  %g1,%i3,%g1
143         mulscc  %g1,%i3,%g1
144         mulscc  %g1,%i3,%g1
145         mulscc  %g1,0,%g1
146         add     %g1,%g2,%i0
147         rd      %y,%g3
148         subcc   %i2,%g3,%o7
149         subxcc  %i1,%i0,%g0
150         be      LOC(253)
151         cmp     %o7,%i3
153         add     %i4,-1,%i0
154         add     %o7,%i3,%o7
155         st      %o7,[%i5]
156         ret
157         restore
158 LOC(253):
159         blu     LOC(246)
160         mov     %i4,%i0
161         add     %i4,1,%i0
162         sub     %o7,%i3,%o7
163 LOC(246):
164         st      %o7,[%i5]
165         ret
166         restore
168 END(__udiv_qrnnd)