Upload Tizen:Base source
[external/gmp.git] / mpn / sparc32 / v8 / supersparc / udiv.asm
1 dnl  SuperSPARC mpn_udiv_qrnnd division support, used from longlong.h.
2 dnl  This is for SuperSPARC only, to compensate for its semi-functional
3 dnl  udiv instruction.
4
5 dnl  Copyright 1993, 1994, 1996, 2000 Free Software Foundation, Inc.
6
7 dnl  This file is part of the GNU MP Library.
8
9 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl  it under the terms of the GNU Lesser General Public License as published
11 dnl  by the Free Software Foundation; either version 3 of the License, or (at
12 dnl  your option) any later version.
13
14 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
15 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 dnl  License for more details.
18
19 dnl  You should have received a copy of the GNU Lesser General Public License
20 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
21
22
23 include(`../config.m4')
24
25 C INPUT PARAMETERS
26 C rem_ptr       i0
27 C n1            i1
28 C n0            i2
29 C d             i3
30
31 ASM_START()
32
33 ifdef(`PIC',
34 `       TEXT
35 L(getpc):
36         retl
37         nop')
38
39         TEXT
40         ALIGN(8)
41 L(C0):  .double 0r4294967296
42 L(C1):  .double 0r2147483648
43
44 PROLOGUE(mpn_udiv_qrnnd)
45         save    %sp,-104,%sp
46         st      %i1,[%fp-8]
47         ld      [%fp-8],%f10
48
49 ifdef(`PIC',
50 `L(pc): call    L(getpc)                C put address of this insn in %o7
51         ldd     [%o7+L(C0)-L(pc)],%f8',
52 `       sethi   %hi(L(C0)),%o7
53         ldd     [%o7+%lo(L(C0))],%f8')
54
55         fitod   %f10,%f4
56         cmp     %i1,0
57         bge     L(248)
58         mov     %i0,%i5
59         faddd   %f4,%f8,%f4
60 L(248):
61         st      %i2,[%fp-8]
62         ld      [%fp-8],%f10
63         fmuld   %f4,%f8,%f6
64         cmp     %i2,0
65         bge     L(249)
66         fitod   %f10,%f2
67         faddd   %f2,%f8,%f2
68 L(249):
69         st      %i3,[%fp-8]
70         faddd   %f6,%f2,%f2
71         ld      [%fp-8],%f10
72         cmp     %i3,0
73         bge     L(250)
74         fitod   %f10,%f4
75         faddd   %f4,%f8,%f4
76 L(250):
77         fdivd   %f2,%f4,%f2
78
79 ifdef(`PIC',
80 `       ldd     [%o7+L(C1)-L(pc)],%f4',
81 `       sethi   %hi(L(C1)),%o7
82         ldd     [%o7+%lo(L(C1))],%f4')
83
84         fcmped  %f2,%f4
85         nop
86         fbge,a  L(251)
87         fsubd   %f2,%f4,%f2
88         fdtoi   %f2,%f2
89         st      %f2,[%fp-8]
90         b       L(252)
91         ld      [%fp-8],%i4
92 L(251):
93         fdtoi   %f2,%f2
94         st      %f2,[%fp-8]
95         ld      [%fp-8],%i4
96         sethi   %hi(-2147483648),%g2
97         xor     %i4,%g2,%i4
98 L(252):
99         umul    %i3,%i4,%g3
100         rd      %y,%i0
101         subcc   %i2,%g3,%o7
102         subxcc  %i1,%i0,%g0
103         be      L(253)
104         cmp     %o7,%i3
105
106         add     %i4,-1,%i0
107         add     %o7,%i3,%o7
108         st      %o7,[%i5]
109         ret
110         restore
111 L(253):
112         blu     L(246)
113         mov     %i4,%i0
114         add     %i4,1,%i0
115         sub     %o7,%i3,%o7
116 L(246):
117         st      %o7,[%i5]
118         ret
119         restore
120 EPILOGUE(mpn_udiv_qrnnd)