aors_n.asm revision 1.1.1.2 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 POWER3/PPC630 2
29 C POWER4/PPC970 2.4
30 C POWER5 2.75
31 C POWER6 40-140
32 C POWER7 3
33
34 C INPUT PARAMETERS
35 define(`rp', `r3')
36 define(`up', `r4')
37 define(`vp', `r5')
38 define(`n', `r6')
39 define(`cy', `r7')
40
41 ifdef(`OPERATION_add_n', `
42 define(ADCSBC, adde)
43 define(func, mpn_add_n)
44 define(func_nc, mpn_add_nc)
45 define(IFADD, `$1')
46 define(IFSUB, `')')
47 ifdef(`OPERATION_sub_n', `
48 define(ADCSBC, subfe)
49 define(func, mpn_sub_n)
50 define(func_nc, mpn_sub_nc)
51 define(IFADD, `')
52 define(IFSUB, `$1')')
53
54 MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc)
55
56 ASM_START()
57
58 PROLOGUE(func_nc)
59 IFADD(` addic r0, cy, -1') C set carry from argument
60 IFSUB(` subfic r0, cy, 0') C set carry from argument
61 b L(ent)
62 EPILOGUE()
63
64 PROLOGUE(func)
65 IFADD(` addic r0, n, 0') C clear carry
66 IFSUB(` addic r0, n, -1') C set carry
67 L(ent): andi. r0, n, 3
68 addi r3, r3, -12
69 addi n, n, 1
70 cmpwi cr7, r0, 2
71 srwi r0, n, 2
72 sub r4, r4, r3
73 sub r5, r5, r3
74 mtctr r0
75 bne cr0, L(n00)
76
77 lwzx r7, r4, r3 C n = 4, 8, 12, ...
78 lwzx r8, r5, r3
79 addi r3, r3, 4
80 lwzx r9, r4, r3
81 ADCSBC r7, r8, r7
82 lwzx r10, r5, r3
83 addi r3, r3, 4
84 b L(00)
85
86 L(n00): bge cr7, L(n01)
87 cmpwi cr0, r0, 0 C n = 1, 5, 9, 13, ...
88 lwzx r0, r4, r3
89 lwzx r6, r5, r3
90 addi r3, r3, 4
91 ADCSBC r0, r6, r0
92 ble L(ret)
93 L(gt1): lwzx r7, r4, r3
94 lwzx r8, r5, r3
95 addi r3, r3, 4
96 b L(01)
97
98 L(n10):
99 lwzx r9, r4, r3 C n = 3, 7, 11, 15, ...
100 lwzx r10, r5, r3
101 addi r3, r3, 4
102 lwzx r11, r4, r3
103 ADCSBC r9, r10, r9
104 lwzx r12, r5, r3
105 addi r3, r3, 4
106 b L(11)
107
108 L(n01): bne cr7, L(n10)
109 cmpwi cr0, r0, 0 C n = 2, 6, 10, 14, ...
110 lwzx r11, r4, r3
111 lwzx r12, r5, r3
112 addi r3, r3, 4
113 lwzx r0, r4, r3
114 ADCSBC r11, r12, r11
115 lwzx r6, r5, r3
116 addi r3, r3, 4
117 ble cr0, L(end)
118
119
120 L(lp): lwzx r7, r4, r3
121 ADCSBC r0, r6, r0
122 lwzx r8, r5, r3
123 stwu r11, 4(r3)
124 L(01): lwzx r9, r4, r3
125 ADCSBC r7, r8, r7
126 lwzx r10, r5, r3
127 stwu r0, 4(r3)
128 L(00): lwzx r11, r4, r3
129 ADCSBC r9, r10, r9
130 lwzx r12, r5, r3
131 stwu r7, 4(r3)
132 L(11): lwzx r0, r4, r3
133 ADCSBC r11, r12, r11
134 lwzx r6, r5, r3
135 stwu r9, 4(r3)
136 bdnz L(lp)
137
138 L(end): ADCSBC r0, r6, r0
139 stw r11, 4(r3)
140 L(ret): stw r0, 8(r3)
141 IFADD(` li r3, 0 ')
142 IFADD(` addze r3, r3 ')
143 IFSUB(` subfe r3, r0, r0')
144 IFSUB(` neg r3, r3')
145 blr
146 EPILOGUE()
147