Upload Tizen:Base source
[external/gmp.git] / mpn / alpha / ev6 / nails / addmul_1.asm
1 dnl  Alpha ev6 nails mpn_addmul_1.
2
3 dnl  Copyright 2002, 2005, 2006 Free Software Foundation, Inc.
4 dnl
5 dnl  This file is part of the GNU MP Library.
6 dnl
7 dnl  The GNU MP Library is free software; you can redistribute it and/or
8 dnl  modify it under the terms of the GNU Lesser General Public License as
9 dnl  published by the Free Software Foundation; either version 3 of the
10 dnl  License, or (at your option) any later version.
11 dnl
12 dnl  The GNU MP Library is distributed in the hope that it will be useful,
13 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 dnl  Lesser General Public License for more details.
16 dnl
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 EV4:    42
24 C EV5:    18
25 C EV6:     4
26
27 C TODO
28 C  * Reroll loop for 3.75 c/l with current 4-way unrolling.
29 C  * The loop is overscheduled wrt loads and wrt multiplies, in particular
30 C    umulh.
31 C  * Use FP loop count and multiple exit points, that would simplify feed-in lp0
32 C    and would work since the loop structure is really regular.
33
34 C  INPUT PARAMETERS
35 define(`rp',`r16')
36 define(`up',`r17')
37 define(`n', `r18')
38 define(`vl0',`r19')
39
40 define(`numb_mask',`r6')
41
42 define(`m0a',`r0')
43 define(`m0b',`r1')
44 define(`m1a',`r2')
45 define(`m1b',`r3')
46 define(`m2a',`r20')
47 define(`m2b',`r21')
48 define(`m3a',`r22')
49 define(`m3b',`r23')
50
51 define(`acc0',`r25')
52 define(`acc1',`r27')
53
54 define(`ul0',`r4')
55 define(`ul1',`r5')
56 define(`ul2',`r4')
57 define(`ul3',`r5')
58
59 define(`rl0',`r24')
60 define(`rl1',`r24')
61 define(`rl2',`r24')
62 define(`rl3',`r24')
63
64 define(`t0',`r7')
65 define(`t1',`r8')
66
67 define(`NAIL_BITS',`GMP_NAIL_BITS')
68 define(`NUMB_BITS',`GMP_NUMB_BITS')
69
70 dnl  This declaration is munged by configure
71 NAILS_SUPPORT(2-63)
72
73 ASM_START()
74 PROLOGUE(mpn_addmul_1)
75         sll     vl0, NAIL_BITS, vl0
76         lda     numb_mask, -1(r31)
77         srl     numb_mask, NAIL_BITS, numb_mask
78
79         and     n,      3,      r25
80         cmpeq   r25,    1,      r21
81         bne     r21,    L(1m4)
82         cmpeq   r25,    2,      r21
83         bne     r21,    L(2m4)
84         beq     r25,    L(0m4)
85
86 L(3m4): ldq     ul3,    0(up)
87         lda     n,      -4(n)
88         ldq     ul0,    8(up)
89         mulq    vl0,    ul3,    m3a
90         umulh   vl0,    ul3,    m3b
91         ldq     ul1,    16(up)
92         lda     up,     24(up)
93         lda     rp,     -8(rp)
94         mulq    vl0,    ul0,    m0a
95         umulh   vl0,    ul0,    m0b
96         bge     n,      L(ge3)
97
98         mulq    vl0,    ul1,    m1a
99         umulh   vl0,    ul1,    m1b
100         ldq     rl3,    8(rp)
101         srl     m3a,NAIL_BITS,  t0
102         addq    t0,     r31,    acc1
103         addq    rl3,    acc1,   acc1
104         ldq     rl0,    16(rp)
105         srl     m0a,NAIL_BITS,  t0
106         addq    t0,     m3b,    acc0
107         srl     acc1,NUMB_BITS, t1
108         br      r31,    L(ta3)
109
110 L(ge3): ldq     ul2,    0(up)
111         mulq    vl0,    ul1,    m1a
112         umulh   vl0,    ul1,    m1b
113         ldq     rl3,    8(rp)
114         srl     m3a,NAIL_BITS,  t0
115         ldq     ul3,    8(up)
116         lda     n,      -4(n)
117         mulq    vl0,    ul2,    m2a
118         addq    t0,     r31,    acc1
119         umulh   vl0,    ul2,    m2b
120         addq    rl3,    acc1,   acc1
121         ldq     rl0,    16(rp)
122         srl     m0a,NAIL_BITS,  t0
123         ldq     ul0,    16(up)
124         mulq    vl0,    ul3,    m3a
125         addq    t0,     m3b,    acc0
126         srl     acc1,NUMB_BITS, t1
127         br      r31,    L(el3)
128
129 L(0m4): lda     n,      -8(n)
130         ldq     ul2,    0(up)
131         ldq     ul3,    8(up)
132         mulq    vl0,    ul2,    m2a
133         umulh   vl0,    ul2,    m2b
134         ldq     ul0,    16(up)
135         mulq    vl0,    ul3,    m3a
136         umulh   vl0,    ul3,    m3b
137         ldq     ul1,    24(up)
138         lda     up,     32(up)
139         mulq    vl0,    ul0,    m0a
140         umulh   vl0,    ul0,    m0b
141         bge     n,      L(ge4)
142
143         ldq     rl2,    0(rp)
144         srl     m2a,NAIL_BITS,  t0
145         mulq    vl0,    ul1,    m1a
146         addq    t0,     r31,    acc0
147         umulh   vl0,    ul1,    m1b
148         addq    rl2,    acc0,   acc0
149         ldq     rl3,    8(rp)
150         srl     m3a,NAIL_BITS,  t0
151         addq    t0,     m2b,    acc1
152         srl     acc0,NUMB_BITS, t1
153         br      r31,    L(ta4)
154
155 L(ge4): ldq     rl2,    0(rp)
156         srl     m2a,NAIL_BITS,  t0
157         ldq     ul2,    0(up)
158         mulq    vl0,    ul1,    m1a
159         addq    t0,     r31,    acc0
160         umulh   vl0,    ul1,    m1b
161         addq    rl2,    acc0,   acc0
162         ldq     rl3,    8(rp)
163         srl     m3a,NAIL_BITS,  t0
164         ldq     ul3,    8(up)
165         lda     n,      -4(n)
166         mulq    vl0,    ul2,    m2a
167         addq    t0,     m2b,    acc1
168         srl     acc0,NUMB_BITS, t1
169         br      r31,    L(el0)
170
171 L(2m4): lda     n,      -4(n)
172         ldq     ul0,    0(up)
173         ldq     ul1,    8(up)
174         lda     up,     16(up)
175         lda     rp,     -16(rp)
176         mulq    vl0,    ul0,    m0a
177         umulh   vl0,    ul0,    m0b
178         bge     n,      L(ge2)
179
180         mulq    vl0,    ul1,    m1a
181         umulh   vl0,    ul1,    m1b
182         ldq     rl0,    16(rp)
183         srl     m0a,NAIL_BITS,  t0
184         addq    t0,     r31,    acc0
185         addq    rl0,    acc0,   acc0
186         ldq     rl1,    24(rp)
187         srl     m1a,NAIL_BITS,  t0
188         addq    t0,     m0b,    acc1
189         srl     acc0,NUMB_BITS, t1
190         br      r31,    L(ta2)
191
192 L(ge2): ldq     ul2,    0(up)
193         mulq    vl0,    ul1,    m1a
194         umulh   vl0,    ul1,    m1b
195         ldq     ul3,    8(up)
196         lda     n,      -4(n)
197         mulq    vl0,    ul2,    m2a
198         umulh   vl0,    ul2,    m2b
199         ldq     rl0,    16(rp)
200         srl     m0a,NAIL_BITS,  t0
201         ldq     ul0,    16(up)
202         mulq    vl0,    ul3,    m3a
203         addq    t0,     r31,    acc0
204         umulh   vl0,    ul3,    m3b
205         addq    rl0,    acc0,   acc0
206         ldq     rl1,    24(rp)
207         srl     m1a,NAIL_BITS,  t0
208         ldq     ul1,    24(up)
209         lda     up,     32(up)
210         lda     rp,     32(rp)
211         mulq    vl0,    ul0,    m0a
212         addq    t0,     m0b,    acc1
213         srl     acc0,NUMB_BITS, t1
214         bge     n,      L(el2)
215
216         br      r31,    L(ta6)
217
218 L(1m4): lda     n,      -4(n)
219         ldq     ul1,    0(up)
220         lda     up,     8(up)
221         lda     rp,     -24(rp)
222         bge     n,      L(ge1)
223
224         mulq    vl0,    ul1,    m1a
225         umulh   vl0,    ul1,    m1b
226         ldq     rl1,    24(rp)
227         srl     m1a,NAIL_BITS,  t0
228         addq    rl1,    t0,     acc1
229         and     acc1,numb_mask, r28
230         srl     acc1,NUMB_BITS, t1
231         stq     r28,    24(rp)
232         addq    t1,     m1b,    r0
233         ret     r31,    (r26),  1
234
235 L(ge1): ldq     ul2,    0(up)
236         mulq    vl0,    ul1,    m1a
237         umulh   vl0,    ul1,    m1b
238         ldq     ul3,    8(up)
239         lda     n,      -4(n)
240         mulq    vl0,    ul2,    m2a
241         umulh   vl0,    ul2,    m2b
242         ldq     ul0,    16(up)
243         mulq    vl0,    ul3,    m3a
244         umulh   vl0,    ul3,    m3b
245         ldq     rl1,    24(rp)
246         srl     m1a,NAIL_BITS,  t0
247         ldq     ul1,    24(up)
248         lda     up,     32(up)
249         lda     rp,     32(rp)
250         mulq    vl0,    ul0,    m0a
251         addq    t0,     r31,    acc1
252         umulh   vl0,    ul0,    m0b
253         addq    rl1,    acc1,   acc1
254         ldq     rl2,    0(rp)
255         srl     m2a,NAIL_BITS,  t0
256         mulq    vl0,    ul1,    m1a
257         addq    t0,     m1b,    acc0
258         srl     acc1,NUMB_BITS, t1
259         blt     n,      L(ta5)
260
261 L(ge5): ldq     ul2,    0(up)
262         br      r31,    L(el1)
263
264         ALIGN(16)
265 L(top): mulq    vl0,    ul0,    m0a             C U1
266         addq    t0,     m0b,    acc1            C L0
267         srl     acc0,NUMB_BITS, t1              C U0
268         stq     r28,    -24(rp)                 C L1
269 C
270 L(el2): umulh   vl0,    ul0,    m0b             C U1
271         and     acc0,numb_mask, r28             C L0
272         addq    rl1,    acc1,   acc1            C U0
273         ldq     rl2,    0(rp)                   C L1
274 C
275         unop                                    C U1
276         addq    t1,     acc1,   acc1            C L0
277         srl     m2a,NAIL_BITS,  t0              C U0
278         ldq     ul2,    0(up)                   C L1
279 C
280         mulq    vl0,    ul1,    m1a             C U1
281         addq    t0,     m1b,    acc0            C L0
282         srl     acc1,NUMB_BITS, t1              C U0
283         stq     r28,    -16(rp)                 C L1
284 C
285 L(el1): umulh   vl0,    ul1,    m1b             C U1
286         and     acc1,numb_mask, r28             C L0
287         addq    rl2,    acc0,   acc0            C U0
288         ldq     rl3,    8(rp)                   C L1
289 C
290         lda     n,      -4(n)                   C L1
291         addq    t1,     acc0,   acc0            C L0
292         srl     m3a,NAIL_BITS,  t0              C U0
293         ldq     ul3,    8(up)                   C L1
294 C
295         mulq    vl0,    ul2,    m2a             C U1
296         addq    t0,     m2b,    acc1            C L0
297         srl     acc0,NUMB_BITS, t1              C U0
298         stq     r28,    -8(rp)                  C L1
299 C
300 L(el0): umulh   vl0,    ul2,    m2b             C U1
301         and     acc0,numb_mask, r28             C L0
302         addq    rl3,    acc1,   acc1            C U0
303         ldq     rl0,    16(rp)                  C L1
304 C
305         unop                                    C U1
306         addq    t1,     acc1,   acc1            C L0
307         srl     m0a,NAIL_BITS,  t0              C U0
308         ldq     ul0,    16(up)                  C L1
309 C
310         mulq    vl0,    ul3,    m3a             C U1
311         addq    t0,     m3b,    acc0            C L0
312         srl     acc1,NUMB_BITS, t1              C U0
313         stq     r28,    0(rp)                   C L1
314 C
315 L(el3): umulh   vl0,    ul3,    m3b             C U1
316         and     acc1,numb_mask, r28             C L0
317         addq    rl0,    acc0,   acc0            C U0
318         ldq     rl1,    24(rp)                  C L1
319 C
320         unop                                    C U1
321         addq    t1,     acc0,   acc0            C L0
322         srl     m1a,NAIL_BITS,  t0              C U0
323         ldq     ul1,    24(up)                  C L1
324 C
325         lda     up,     32(up)                  C L0
326         unop                                    C U1
327         lda     rp,     32(rp)                  C L1
328         bge     n,      L(top)                  C U0
329
330 L(end): mulq    vl0,    ul0,    m0a
331         addq    t0,     m0b,    acc1
332         srl     acc0,NUMB_BITS, t1
333         stq     r28,    -24(rp)
334 L(ta6): umulh   vl0,    ul0,    m0b
335         and     acc0,numb_mask, r28
336         addq    rl1,    acc1,   acc1
337         ldq     rl2,    0(rp)
338         addq    t1,     acc1,   acc1
339         srl     m2a,NAIL_BITS,  t0
340         mulq    vl0,    ul1,    m1a
341         addq    t0,     m1b,    acc0
342         srl     acc1,NUMB_BITS, t1
343         stq     r28,    -16(rp)
344 L(ta5): umulh   vl0,    ul1,    m1b
345         and     acc1,numb_mask, r28
346         addq    rl2,    acc0,   acc0
347         ldq     rl3,    8(rp)
348         addq    t1,     acc0,   acc0
349         srl     m3a,NAIL_BITS,  t0
350         addq    t0,     m2b,    acc1
351         srl     acc0,NUMB_BITS, t1
352         stq     r28,    -8(rp)
353         unop
354         ALIGN(16)
355 L(ta4): and     acc0,numb_mask, r28
356         addq    rl3,    acc1,   acc1
357         ldq     rl0,    16(rp)
358         addq    t1,     acc1,   acc1
359         srl     m0a,NAIL_BITS,  t0
360         addq    t0,     m3b,    acc0
361         srl     acc1,NUMB_BITS, t1
362         stq     r28,    0(rp)
363         unop
364         ALIGN(16)
365 L(ta3): and     acc1,numb_mask, r28
366         addq    rl0,    acc0,   acc0
367         ldq     rl1,    24(rp)
368         addq    t1,     acc0,   acc0
369         srl     m1a,NAIL_BITS,  t0
370         addq    t0,     m0b,    acc1
371         srl     acc0,NUMB_BITS, t1
372         stq     r28,    8(rp)
373         unop
374         ALIGN(16)
375 L(ta2): and     acc0,numb_mask, r28
376         addq    rl1,    acc1,   acc1
377         addq    t1,     acc1,   acc1
378         srl     acc1,NUMB_BITS, t1
379         stq     r28,    16(rp)
380         and     acc1,numb_mask, r28
381         addq    t1,     m1b,    r0
382         stq     r28,    24(rp)
383         ret     r31,    (r26),  1
384 EPILOGUE()
385 ASM_END()