Upload Tizen:Base source
[external/gmp.git] / mpn / powerpc64 / mode64 / dive_1.asm
1 dnl  PowerPC-64 mpn_divexact_1 -- mpn by limb exact division.
2
3 dnl  Copyright 2006 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               cycles/limb
23 C POWER3/PPC630:    13-19
24 C POWER4/PPC970:     16
25 C POWER5:            16
26
27 C TODO
28 C  * Check if n=1 code is really an improvement.  It probably isn't.
29 C  * Perhaps remove L(norm) code, it is currently unreachable.
30 C  * Make more similar to mode1o.asm.
31
32 C INPUT PARAMETERS
33 define(`rp', `r3')
34 define(`up', `r4')
35 define(`n',  `r5')
36 define(`d',  `r6')
37
38
39 ASM_START()
40
41 EXTERN(binvert_limb_table)
42
43 PROLOGUE(mpn_divexact_1)
44         addic.  n, n, -1
45         ld      r12, 0(up)
46         bne     cr0, L(2)
47         divdu   r0, r12, d
48         std     r0, 0(rp)
49         blr
50 L(2):
51         rldicl. r0, d, 0, 63
52         li      r10, 0
53         bne     cr0, L(7)
54         neg     r0, d
55         and     r0, d, r0
56         cntlzd  r0, r0
57         subfic  r0, r0, 63
58         rldicl  r10, r0, 0, 32
59         srd     d, d, r0
60 L(7):
61         mtctr   n
62         LEA(    r5, binvert_limb_table)
63         rldicl  r11, d, 63, 57
64 C       cmpdi   cr7, r0, 0
65         lbzx    r0, r5, r11
66         mulld   r9, r0, r0
67         sldi    r0, r0, 1
68         mulld   r9, d, r9
69         subf    r0, r9, r0
70         mulld   r5, r0, r0
71         sldi    r0, r0, 1
72         mulld   r5, d, r5
73         subf    r0, r5, r0
74         mulld   r9, r0, r0
75         sldi    r0, r0, 1
76         mulld   r9, d, r9
77         subf    r7, r9, r0              C r7 = 1/d mod 2^64
78 C       beq     cr7, L(norm)
79         subfic  r8, r10, 64             C set carry as side effect
80         li      r5, 0
81
82         ALIGN(16)
83 L(loop0):
84         srd     r11, r12, r10
85         ld      r12, 8(up)
86         addi    up, up, 8
87         sld     r0, r12, r8
88         or      r11, r11, r0
89         subfe   r9, r5, r11
90         mulld   r0, r7, r9
91         std     r0, 0(rp)
92         addi    rp, rp, 8
93         mulhdu  r5, r0, d
94         bdnz    L(loop0)
95
96         srd     r0, r12, r10
97         subfe   r0, r5, r0
98         mulld   r0, r7, r0
99         std     r0, 0(rp)
100         blr
101
102         ALIGN(16)
103 L(norm):
104         mulld   r11, r12, r7
105         std     r11, 0(rp)
106         ALIGN(16)
107 L(loop1):
108         mulhdu  r5, r11, d
109         ld      r9, 8(up)
110         addi    up, up, 8
111         subfe   r5, r5, r9
112         mulld   r11, r7, r5
113         std     r11, 8(rp)
114         addi    rp, rp, 8
115         bdnz    L(loop1)
116         blr
117 EPILOGUE()
118 ASM_END()