Tizen 2.1 base
[external/gmp.git] / mpn / powerpc64 / mode64 / rsh1add_n.asm
1 dnl  PowerPC-64 mpn_rsh1add_n -- rp[] = (up[] + vp[]) >> 1
2
3 dnl  Copyright 2003, 2005 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:     2          (1.5 c/l should be possible)
24 C POWER4/PPC970:     4          (2.0 c/l should be possible)
25
26 C INPUT PARAMETERS
27 C rp    r3
28 C up    r4
29 C vp    r5
30 C n     r6
31
32 define(`rp',`r3')
33 define(`up',`r4')
34 define(`vp',`r5')
35
36 define(`s0',`r6')
37 define(`s1',`r7')
38 define(`x',`r0')
39 define(`u0',`r8')
40 define(`u1',`r9')
41 define(`v0',`r10')
42 define(`v1',`r11')
43
44
45 ASM_START()
46 PROLOGUE(mpn_rsh1add_n)
47         mtctr   r6              C copy size to count register
48         addi    rp, rp, -8
49
50         ld      u1, 0(up)
51         ld      v1, 0(vp)
52         addc    x, v1, u1
53         rldicl  r12, x, 0, 63   C return value
54         srdi    s1, x, 1
55
56         bdz     L(1)
57
58         ld      u0, 8(up)
59         ld      v0, 8(vp)
60
61         bdz     L(end)
62
63 L(oop): ldu     u1, 16(up)
64         ldu     v1, 16(vp)
65         adde    x, v0, u0
66         srdi    s0, x, 1
67         rldimi  s1, x, 63, 0
68         std     s1, 8(rp)
69
70         bdz     L(exit)
71
72         ld      u0, 8(up)
73         ld      v0, 8(vp)
74         adde    x, v1, u1
75         srdi    s1, x, 1
76         rldimi  s0, x, 63, 0
77         stdu    s0, 16(rp)
78
79         bdnz    L(oop)
80
81 L(end): adde    x, v0, u0
82         srdi    s0, x, 1
83         rldimi  s1, x, 63, 0
84         std     s1, 8(rp)
85
86         li      x, 0
87         addze   x, x
88         rldimi  s0, x, 63, 0
89         std     s0, 16(rp)
90         mr      r3, r12
91         blr
92
93 L(exit):        adde    x, v1, u1
94         srdi    s1, x, 1
95         rldimi  s0, x, 63, 0
96         stdu    s0, 16(rp)
97
98 L(1):   li      x, 0
99         addze   x, x
100         rldimi  s1, x, 63, 0
101         std     s1, 8(rp)
102         mr      r3, r12
103         blr
104 EPILOGUE()