ed688ee1d24f50b66cb1c94bfa5b1861ca7c65b3
[ghc-hetmet.git] / ghc / rts / gmp / mpn / sparc32 / v8 / supersparc / udiv.S
1 ! SuperSPARC __udiv_qrnnd division support, used from longlong.h.
2 ! This is for SuperSPARC only, to compensate for its semi-functional
3 ! udiv instruction.
4
5 ! Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
6
7 ! This file is part of the GNU MP Library.
8
9 ! The GNU MP Library is free software; you can redistribute it and/or modify
10 ! it under the terms of the GNU Library General Public License as published by
11 ! the Free Software Foundation; either version 2 of the License, or (at your
12 ! option) any later version.
13
14 ! The GNU MP Library is distributed in the hope that it will be useful, but
15 ! WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 ! or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
17 ! License for more details.
18
19 ! You should have received a copy of the GNU Library General Public License
20 ! along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
21 ! the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 ! MA 02111-1307, USA.
23
24
25 ! INPUT PARAMETERS
26 ! rem_ptr       i0
27 ! n1            i1
28 ! n0            i2
29 ! d             i3
30
31 #include "sysdep.h"
32 #undef ret      /* Kludge for glibc */
33
34         .text
35         .align  8
36 LC0:    .double 0r4294967296
37 LC1:    .double 0r2147483648
38
39         .align  4
40         .global C_SYMBOL_NAME(__udiv_qrnnd)
41 C_SYMBOL_NAME(__udiv_qrnnd):
42         !#PROLOGUE# 0
43         save    %sp,-104,%sp
44         !#PROLOGUE# 1
45         st      %i1,[%fp-8]
46         ld      [%fp-8],%f10
47         sethi   %hi(LC0),%o7
48         fitod   %f10,%f4
49         ldd     [%o7+%lo(LC0)],%f8
50         cmp     %i1,0
51         bge     L248
52         mov     %i0,%i5
53         faddd   %f4,%f8,%f4
54 L248:
55         st      %i2,[%fp-8]
56         ld      [%fp-8],%f10
57         fmuld   %f4,%f8,%f6
58         cmp     %i2,0
59         bge     L249
60         fitod   %f10,%f2
61         faddd   %f2,%f8,%f2
62 L249:
63         st      %i3,[%fp-8]
64         faddd   %f6,%f2,%f2
65         ld      [%fp-8],%f10
66         cmp     %i3,0
67         bge     L250
68         fitod   %f10,%f4
69         faddd   %f4,%f8,%f4
70 L250:
71         fdivd   %f2,%f4,%f2
72         sethi   %hi(LC1),%o7
73         ldd     [%o7+%lo(LC1)],%f4
74         fcmped  %f2,%f4
75         nop
76         fbge,a  L251
77         fsubd   %f2,%f4,%f2
78         fdtoi   %f2,%f2
79         st      %f2,[%fp-8]
80         b       L252
81         ld      [%fp-8],%i4
82 L251:
83         fdtoi   %f2,%f2
84         st      %f2,[%fp-8]
85         ld      [%fp-8],%i4
86         sethi   %hi(-2147483648),%g2
87         xor     %i4,%g2,%i4
88 L252:
89         umul    %i3,%i4,%g3
90         rd      %y,%i0
91         subcc   %i2,%g3,%o7
92         subxcc  %i1,%i0,%g0
93         be      L253
94         cmp     %o7,%i3
95
96         add     %i4,-1,%i0
97         add     %o7,%i3,%o7
98         st      %o7,[%i5]
99         ret
100         restore
101 L253:
102         blu     L246
103         mov     %i4,%i0
104         add     %i4,1,%i0
105         sub     %o7,%i3,%o7
106 L246:
107         st      %o7,[%i5]
108         ret
109         restore