Tizen 2.1 base
[external/gmp.git] / mpn / powerpc32 / aors_n.asm
1 dnl  PowerPC-32 mpn_add_n and mpn_sub_n.
2
3 dnl  Copyright 2002, 2005, 2007 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 603e:              ?
24 C 604e:              ?          old: 3.25
25 C 75x (G3):          ?          old: 3.5
26 C 7400,7410 (G4):    3.25
27 C 744x,745x (G4+):   4
28 C power4/ppc970:     ?          old: 2.0
29 C power5:            ?          old: 2.5
30
31 C INPUT PARAMETERS
32 define(`rp',    `r3')
33 define(`up',    `r4')
34 define(`vp',    `r5')
35 define(`n',     `r6')
36 define(`cy',    `r7')
37
38 ifdef(`OPERATION_add_n', `
39         define(ADCSBC,  adde)
40         define(func,    mpn_add_n)
41         define(func_nc, mpn_add_nc)
42         define(IFADD,   `$1')
43         define(IFSUB,   `')')
44 ifdef(`OPERATION_sub_n', `
45         define(ADCSBC,  subfe)
46         define(func,    mpn_sub_n)
47         define(func_nc, mpn_sub_nc)
48         define(IFADD,   `')
49         define(IFSUB,   `$1')')
50
51 MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
52
53 ASM_START()
54
55 PROLOGUE(func_nc)
56 IFADD(` addic   r0, cy, -1')            C set carry from argument
57 IFSUB(` subfic  r0, cy, 0')             C set carry from argument
58         b       L(ent)
59 EPILOGUE()
60
61 PROLOGUE(func)
62 IFADD(` addic   r0, n, 0')              C clear carry
63 IFSUB(` addic   r0, n, -1')             C set carry
64 L(ent): andi.   r0, n, 3
65         addi    r3, r3, -12
66         addi    n, n, 1
67         cmpwi   cr7, r0, 2
68         srwi    r0, n, 2
69         sub     r4, r4, r3
70         sub     r5, r5, r3
71         mtctr   r0
72         bne     cr0, L(n00)
73
74         lwzx    r7, r4, r3              C n = 4, 8, 12, ...
75         lwzx    r8, r5, r3
76         addi    r3, r3, 4
77         lwzx    r9, r4, r3
78         ADCSBC  r7, r8, r7
79         lwzx    r10, r5, r3
80         addi    r3, r3, 4
81         b       L(00)
82
83 L(n00): bge     cr7, L(n01)
84         cmpwi   cr0, r0, 0              C n = 1, 5, 9, 13, ...
85         lwzx    r0, r4, r3
86         lwzx    r6, r5, r3
87         addi    r3, r3, 4
88         ADCSBC  r0, r6, r0
89         ble     L(ret)
90 L(gt1): lwzx    r7, r4, r3
91         lwzx    r8, r5, r3
92         addi    r3, r3, 4
93         b       L(01)
94
95 L(n10):
96         lwzx    r9, r4, r3              C n = 3, 7, 11, 15, ...
97         lwzx    r10, r5, r3
98         addi    r3, r3, 4
99         lwzx    r11, r4, r3
100         ADCSBC  r9, r10, r9
101         lwzx    r12, r5, r3
102         addi    r3, r3, 4
103         b       L(11)
104
105 L(n01): bne     cr7, L(n10)
106         cmpwi   cr0, r0, 0              C n = 2, 6, 10, 14, ...
107         lwzx    r11, r4, r3
108         lwzx    r12, r5, r3
109         addi    r3, r3, 4
110         lwzx    r0, r4, r3
111         ADCSBC  r11, r12, r11
112         lwzx    r6, r5, r3
113         addi    r3, r3, 4
114         ble     cr0, L(end)
115
116
117 L(lp):  lwzx    r7, r4, r3
118         ADCSBC  r0, r6, r0
119         lwzx    r8, r5, r3
120         stwu    r11, 4(r3)
121 L(01):  lwzx    r9, r4, r3
122         ADCSBC  r7, r8, r7
123         lwzx    r10, r5, r3
124         stwu    r0, 4(r3)
125 L(00):  lwzx    r11, r4, r3
126         ADCSBC  r9, r10, r9
127         lwzx    r12, r5, r3
128         stwu    r7, 4(r3)
129 L(11):  lwzx    r0, r4, r3
130         ADCSBC  r11, r12, r11
131         lwzx    r6, r5, r3
132         stwu    r9, 4(r3)
133         bdnz    L(lp)
134
135 L(end): ADCSBC  r0, r6, r0
136         stw     r11, 4(r3)
137 L(ret): stw     r0, 8(r3)
138 IFADD(` li      r3, 0   ')
139 IFADD(` addze   r3, r3  ')
140 IFSUB(` subfe   r3, r0, r0')
141 IFSUB(` neg     r3, r3')
142         blr
143 EPILOGUE()