Tizen 2.1 base
[external/gmp.git] / mpn / powerpc64 / mode64 / mode1o.asm
1 dnl  PowerPC-64 mpn_modexact_1_odd -- mpn by limb exact remainder.
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  * Make more similar to dive_1.asm.
30
31 C INPUT PARAMETERS
32 define(`up', `r3')
33 define(`n',  `r4')
34 define(`d',  `r5')
35 define(`cy', `r6')
36
37
38 ASM_START()
39
40 EXTERN(binvert_limb_table)
41
42 PROLOGUE(mpn_modexact_1c_odd)
43         addic.  n, n, -1                C set carry as side effect
44         ld      r8, 0(up)
45         bne     cr0, L(2)
46         cmpld   cr7, r6, r8
47         bge     cr7, L(4)
48         subf    r8, r6, r8
49         divdu   r3, r8, d
50         mulld   r3, r3, d
51         subf.   r3, r3, r8
52         beqlr   cr0
53         subf    r3, r3, d
54         blr
55
56 L(4):   subf    r3, r8, r6
57         divdu   r8, r3, d
58         mulld   r8, r8, d
59         subf    r3, r8, r3
60         blr
61
62 L(2):   LEA(    r7, binvert_limb_table)
63         rldicl  r9, d, 63, 57
64         mtctr   n
65         lbzx    r0, r7, r9
66         mulld   r7, r0, r0
67         sldi    r0, r0, 1
68         mulld   r7, d, r7
69         subf    r0, r7, r0
70         mulld   r9, r0, r0
71         sldi    r0, r0, 1
72         mulld   r9, d, r9
73         subf    r0, r9, r0
74         mulld   r7, r0, r0
75         sldi    r0, r0, 1
76         mulld   r7, d, r7
77         subf    r9, r7, r0
78
79         ALIGN(16)
80 L(loop):
81         subfe   r0, r6, r8
82         ld      r8, 8(up)
83         addi    up, up, 8
84         mulld   r0, r9, r0
85         mulhdu  r6, r0, d
86         bdnz    L(loop)
87
88         cmpld   cr7, d, r8
89         blt     cr7, L(10)
90
91         subfe   r0, r0, r0
92         subf    r6, r0, r6
93         cmpld   cr7, r6, r8
94         subf    r3, r8, r6
95         bgelr   cr7
96         add     r3, d, r3
97         blr
98
99 L(10):  subfe   r0, r6, r8
100         mulld   r0, r9, r0
101         mulhdu  r3, r0, d
102         blr
103 EPILOGUE()
104 ASM_END()