Upload Tizen:Base source
[external/gmp.git] / mpn / pa64 / udiv.asm
1 dnl  HP-PA 2.0 64-bit mpn_udiv_qrnnd_r.
2
3 dnl  Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
4
5 dnl  This file is part of the GNU MP Library.
6
7 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
8 dnl  it under the terms of the GNU Lesser General Public License as published
9 dnl  by the Free Software Foundation; either version 3 of the License, or (at
10 dnl  your option) any later version.
11
12 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
13 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 dnl  License for more details.
16
17 dnl  You should have received a copy of the GNU Lesser General Public License
18 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
19
20 include(`../config.m4')
21
22 C This runs at about 280 cycles on both PA8000 and PA8500, corresponding to a
23 C bit more than 4 cycles/bit.
24
25 C INPUT PARAMETERS
26 define(`n1',`%r26')
27 define(`n0',`%r25')
28 define(`d',`%r24')
29 define(`remptr',`%r23')
30
31 define(`q',`%r28')
32 define(`dn',`%r29')
33
34 define(`old_divstep',
35        `add,dc          n0,n0,n0
36         add,dc          n1,n1,n1
37         sub,*<<         n1,d,%r22
38         copy            %r22,n1')
39
40 define(`divstep',
41        `add             n0,n0,n0
42         add,dc          n1,n1,n1
43         sub             n1,d,%r1
44         add,dc          q,q,q
45         cmpclr,*<<      n1,d,%r0
46         copy            %r1,n1
47 ')
48
49 ifdef(`HAVE_ABI_2_0w',
50 `       .level  2.0w
51 ',`     .level  2.0
52 ')
53 PROLOGUE(mpn_udiv_qrnnd_r)
54 ifdef(`HAVE_ABI_2_0n',
55 `       depd            %r25,31,32,%r26
56         depd            %r23,31,32,%r24
57         copy            %r24,%r25
58         ldd             -56(%r30),%r24
59         ldw             -60(%r30),%r23
60 ')
61         ldi             0,q
62         cmpib,*>=       0,d,L(large_divisor)
63         ldi             8,%r31          C setup loop counter
64
65         sub             %r0,d,dn
66 LDEF(Loop)
67         divstep divstep divstep divstep divstep divstep divstep divstep
68         addib,<>        -1,%r31,L(Loop)
69         nop
70
71 ifdef(`HAVE_ABI_2_0n',
72 `       copy            %r28,%r29
73         extrd,u         %r28,31,32,%r28
74 ')
75         bve             (%r2)
76         std             n1,0(remptr)    C store remainder
77
78 LDEF(large_divisor)
79         extrd,u         n0,63,1,%r19    C save lsb of dividend
80         shrpd           n1,n0,1,n0      C n0 = lo(n1n0 >> 1)
81         shrpd           %r0,n1,1,n1     C n1 = hi(n1n0 >> 1)
82         extrd,u         d,63,1,%r20     C save lsb of divisor
83         shrpd           %r0,d,1,d       C d = floor(orig_d / 2)
84         add,l           %r20,d,d        C d = ceil(orig_d / 2)
85
86         sub             %r0,d,dn
87 LDEF(Loop2)
88         divstep divstep divstep divstep divstep divstep divstep divstep
89         addib,<>        -1,%r31,L(Loop2)
90         nop
91
92         cmpib,*=        0,%r20,L(even_divisor)
93         shladd          n1,1,%r19,n1    C shift in omitted dividend lsb
94
95         add             d,d,d           C restore orig...
96         sub             d,%r20,d        C ...d value
97         sub             %r0,d,dn        C r21 = -d
98
99         add,*nuv        n1,q,n1         C fix remainder for omitted divisor lsb
100         add,l           n1,dn,n1        C adjust remainder if rem. fix carried
101         add,dc          %r0,q,q         C adjust quotient accordingly
102
103         sub,*<<         n1,d,%r0        C remainder >= divisor?
104         add,l           n1,dn,n1        C adjust remainder
105         add,dc          %r0,q,q         C adjust quotient
106
107 LDEF(even_divisor)
108 ifdef(`HAVE_ABI_2_0n',
109 `       copy            %r28,%r29
110         extrd,u         %r28,31,32,%r28
111 ')
112         bve             (%r2)
113         std             n1,0(remptr)    C store remainder
114 EPILOGUE(mpn_udiv_qrnnd_r)