Upload Tizen:Base source
[external/gmp.git] / mpn / alpha / ev6 / aorsmul_1.asm
1 dnl  Alpha ev6 mpn_addmul_1 and mpn_submul_1.
2
3 dnl  Copyright 2000, 2003, 2004, 2005, 2008 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 EV4:    42
24 C EV5:    18
25 C EV6:     3.5
26
27 C  INPUT PARAMETERS
28 define(`rp',    `r16')
29 define(`up',    `r17')
30 define(`n',     `r18')
31 define(`v0',    `r19')
32
33 dnl  This code was written in cooperation with ev6 pipeline expert Steve Root.
34
35 dnl  The stores can issue a cycle late so we have paired no-op's to 'catch'
36 dnl  them, so that further disturbance to the schedule is damped.
37
38 dnl  We couldn't pair the loads, because the entangled schedule of the carry's
39 dnl  has to happen on one side {0} of the machine.
40
41 dnl  This is a great schedule for the d_cache, a poor schedule for the b_cache.
42 dnl  The lockup on U0 means that any stall can't be recovered from.  Consider a
43 dnl  ldq in L1, say that load gets stalled because it collides with a fill from
44 dnl  the b_cache.  On the next cycle, this load gets priority.  If first looks
45 dnl  at L0, and goes there.  The instruction we intended for L0 gets to look at
46 dnl  L1, which is NOT where we want it.  It either stalls 1, because it can't
47 dnl  go in L0, or goes there, and causes a further instruction to stall.
48
49 dnl  So for b_cache, we're likely going to want to put one or more cycles back
50 dnl  into the code! And, of course, put in lds prefetch for the rp[] operand.
51 dnl  At a place where we have an mt followed by a bookkeeping, put the
52 dnl  bookkeeping in upper, and the prefetch into lower.
53
54 dnl  Note, the ldq's and stq's are at the end of the quadpacks.  Note, we'd
55 dnl  like not to have an ldq or an stq to preceded a conditional branch in a
56 dnl  quadpack.  The conditional branch moves the retire pointer one cycle
57 dnl  later.
58
59 ifdef(`OPERATION_addmul_1',`
60     define(`ADDSUB',    `addq')
61     define(`CMPCY',     `cmpult $2,$1')
62     define(`func',      `mpn_addmul_1')
63 ')
64 ifdef(`OPERATION_submul_1',`
65     define(`ADDSUB',    `subq')
66     define(`CMPCY',     `cmpult $1,$2')
67     define(`func',      `mpn_submul_1')
68 ')
69
70 MULFUNC_PROLOGUE(mpn_addmul_1 mpn_submul_1)
71
72 ASM_START()
73 PROLOGUE(func)
74         ldq     r3,     0(up)           C
75         and     r18,    7,      r20     C
76         lda     r18,    -9(r18)         C
77         cmpeq   r20,    1,      r21     C
78         beq     r21,    $L1             C
79
80 $1mod8: ldq     r5,     0(rp)           C
81         mulq    v0,     r3,     r7      C
82         umulh   v0,     r3,     r8      C
83         ADDSUB  r5,     r7,     r23     C
84         CMPCY(  r5,     r23),   r20     C
85         addq    r8,     r20,    r0      C
86         stq     r23,    0(rp)           C
87         bge     r18,    $ent1           C
88         ret     r31,    (r26),  1       C
89
90 $L1:    lda     r8,     0(r31)          C zero carry reg
91         lda     r24,    0(r31)          C zero carry reg
92         cmpeq   r20,    2,      r21     C
93         bne     r21,    $2mod8          C
94         cmpeq   r20,    3,      r21     C
95         bne     r21,    $3mod8          C
96         cmpeq   r20,    4,      r21     C
97         bne     r21,    $4mod8          C
98         cmpeq   r20,    5,      r21     C
99         bne     r21,    $5mod8          C
100         cmpeq   r20,    6,      r21     C
101         bne     r21,    $6mod8          C
102         cmpeq   r20,    7,      r21     C
103         beq     r21,    $0mod8          C
104
105 $7mod8: ldq     r5,     0(rp)           C
106         lda     up,     8(up)           C
107         mulq    v0,     r3,     r7      C
108         umulh   v0,     r3,     r24     C
109         ADDSUB  r5,     r7,     r23     C
110         CMPCY(  r5,     r23),   r20     C
111         addq    r24,    r20,    r24     C
112         stq     r23,    0(rp)           C
113         lda     rp,     8(rp)           C
114         ldq     r3,     0(up)           C
115 $6mod8: ldq     r1,     8(up)           C
116         mulq    v0,     r3,     r25     C
117         umulh   v0,     r3,     r3      C
118         mulq    v0,     r1,     r28     C
119         ldq     r0,     16(up)          C
120         ldq     r4,     0(rp)           C
121         umulh   v0,     r1,     r8      C
122         ldq     r1,     24(up)          C
123         lda     up,     48(up)          C L1 bookkeeping
124         mulq    v0,     r0,     r2      C
125         ldq     r5,     8(rp)           C
126         lda     rp,     -32(rp)         C L1 bookkeeping
127         umulh   v0,     r0,     r6      C
128         ADDSUB  r4,     r25,    r25     C lo + acc
129         mulq    v0,     r1,     r7      C
130         br      r31,    $ent6           C
131
132 $ent1:  lda     up,     8(up)           C
133         lda     rp,     8(rp)           C
134         lda     r8,     0(r0)           C
135         ldq     r3,     0(up)           C
136 $0mod8: ldq     r1,     8(up)           C
137         mulq    v0,     r3,     r2      C
138         umulh   v0,     r3,     r6      C
139         mulq    v0,     r1,     r7      C
140         ldq     r0,     16(up)          C
141         ldq     r4,     0(rp)           C
142         umulh   v0,     r1,     r24     C
143         ldq     r1,     24(up)          C
144         mulq    v0,     r0,     r25     C
145         ldq     r5,     8(rp)           C
146         umulh   v0,     r0,     r3      C
147         ADDSUB  r4,     r2,     r2      C lo + acc
148         mulq    v0,     r1,     r28     C
149         lda     rp,     -16(rp)         C
150         br      r31,    $ent0           C
151
152 $3mod8: ldq     r5,     0(rp)           C
153         lda     up,     8(up)           C
154         mulq    v0,     r3,     r7      C
155         umulh   v0,     r3,     r8      C
156         ADDSUB  r5,     r7,     r23     C
157         CMPCY(  r5,     r23),   r20     C
158         addq    r8,     r20,    r24     C
159         stq     r23,    0(rp)           C
160         lda     rp,     8(rp)           C
161         ldq     r3,     0(up)           C
162 $2mod8: ldq     r1,     8(up)           C
163         mulq    v0,     r3,     r25     C
164         umulh   v0,     r3,     r3      C
165         mulq    v0,     r1,     r28     C
166         ble     r18,    $n23            C
167         ldq     r0,     16(up)          C
168         ldq     r4,     0(rp)           C
169         umulh   v0,     r1,     r8      C
170         ldq     r1,     24(up)          C
171         lda     up,     16(up)          C L1 bookkeeping
172         mulq    v0,     r0,     r2      C
173         ldq     r5,     8(rp)           C
174         lda     rp,     0(rp)           C L1 bookkeeping
175         umulh   v0,     r0,     r6      C
176         ADDSUB  r4,     r25,    r25     C lo + acc
177         mulq    v0,     r1,     r7      C
178         br      r31,    $ent2           C
179
180 $5mod8: ldq     r5,     0(rp)           C
181         lda     up,     8(up)           C
182         mulq    v0,     r3,     r7      C
183         umulh   v0,     r3,     r24     C
184         ADDSUB  r5,     r7,     r23     C
185         CMPCY(  r5,     r23),   r20     C
186         addq    r24,    r20,    r8      C
187         stq     r23,    0(rp)           C
188         lda     rp,     8(rp)           C
189         ldq     r3,     0(up)           C
190 $4mod8: ldq     r1,     8(up)           C
191         mulq    v0,     r3,     r2      C
192         umulh   v0,     r3,     r6      C
193         mulq    v0,     r1,     r7      C
194         ldq     r0,     16(up)          C
195         ldq     r4,     0(rp)           C
196         umulh   v0,     r1,     r24     C
197         ldq     r1,     24(up)          C
198         lda     up,     32(up)          C L1 bookkeeping
199         mulq    v0,     r0,     r25     C
200         ldq     r5,     8(rp)           C
201         lda     rp,     16(rp)          C L1 bookkeeping
202         umulh   v0,     r0,     r3      C
203         ADDSUB  r4,     r2,     r2      C lo + acc
204         mulq    v0,     r1,     r28     C
205         CMPCY(  r4,     r2),    r20     C L0 lo add => carry
206         ADDSUB  r2,     r8,     r22     C U0 hi add => answer
207         ble     r18,    $Lend           C
208         ALIGN(16)
209 $Loop:
210         bis     r31,    r31,    r31     C U1 mt
211         CMPCY(  r2,     r22),   r21     C L0 hi add => carry
212         addq    r6,     r20,    r6      C U0 hi mul + carry
213         ldq     r0,     0(up)           C
214
215         bis     r31,    r31,    r31     C U1 mt
216         ADDSUB  r5,     r7,     r7      C L0 lo + acc
217         addq    r6,     r21,    r6      C U0 hi mul + carry
218         ldq     r4,     0(rp)           C L1
219
220         umulh   v0,     r1,     r8      C U1
221         CMPCY(  r5,     r7),    r20     C L0 lo add => carry
222         ADDSUB  r7,     r6,     r23     C U0 hi add => answer
223         ldq     r1,     8(up)           C L1
224
225         mulq    v0,     r0,     r2      C U1
226         CMPCY(  r7,     r23),   r21     C L0 hi add => carry
227         addq    r24,    r20,    r24     C U0 hi mul + carry
228         ldq     r5,     8(rp)           C L1
229
230         umulh   v0,     r0,     r6      C U1
231         ADDSUB  r4,     r25,    r25     C U0 lo + acc
232         stq     r22,    -16(rp)         C L0
233         stq     r23,    -8(rp)          C L1
234
235         bis     r31,    r31,    r31     C L0 st slosh
236         mulq    v0,     r1,     r7      C U1
237         bis     r31,    r31,    r31     C L1 st slosh
238         addq    r24,    r21,    r24     C U0 hi mul + carry
239 $ent2:
240         CMPCY(  r4,     r25),   r20     C L0 lo add => carry
241         bis     r31,    r31,    r31     C U1 mt
242         lda     r18,    -8(r18)         C L1 bookkeeping
243         ADDSUB  r25,    r24,    r22     C U0 hi add => answer
244
245         bis     r31,    r31,    r31     C U1 mt
246         CMPCY(  r25,    r22),   r21     C L0 hi add => carry
247         addq    r3,     r20,    r3      C U0 hi mul + carry
248         ldq     r0,     16(up)          C L1
249
250         bis     r31,    r31,    r31     C U1 mt
251         ADDSUB  r5,     r28,    r28     C L0 lo + acc
252         addq    r3,     r21,    r3      C U0 hi mul + carry
253         ldq     r4,     16(rp)          C L1
254
255         umulh   v0,     r1,     r24     C U1
256         CMPCY(  r5,     r28),   r20     C L0 lo add => carry
257         ADDSUB  r28,    r3,     r23     C U0 hi add => answer
258         ldq     r1,     24(up)          C L1
259
260         mulq    v0,     r0,     r25     C U1
261         CMPCY(  r28,    r23),   r21     C L0 hi add => carry
262         addq    r8,     r20,    r8      C U0 hi mul + carry
263         ldq     r5,     24(rp)          C L1
264
265         umulh   v0,     r0,     r3      C U1
266         ADDSUB  r4,     r2,     r2      C U0 lo + acc
267         stq     r22,    0(rp)           C L0
268         stq     r23,    8(rp)           C L1
269
270         bis     r31,    r31,    r31     C L0 st slosh
271         mulq    v0,     r1,     r28     C U1
272         bis     r31,    r31,    r31     C L1 st slosh
273         addq    r8,     r21,    r8      C U0 hi mul + carry
274 $ent0:
275         CMPCY(  r4,     r2),    r20     C L0 lo add => carry
276         bis     r31,    r31,    r31     C U1 mt
277         lda     up,     64(up)          C L1 bookkeeping
278         ADDSUB  r2,     r8,     r22     C U0 hi add => answer
279
280         bis     r31,    r31,    r31     C U1 mt
281         CMPCY(  r2,     r22),   r21     C L0 hi add => carry
282         addq    r6,     r20,    r6      C U0 hi mul + carry
283         ldq     r0,     -32(up)         C L1
284
285         bis     r31,    r31,    r31     C U1 mt
286         ADDSUB  r5,     r7,     r7      C L0 lo + acc
287         addq    r6,     r21,    r6      C U0 hi mul + carry
288         ldq     r4,     32(rp)          C L1
289
290         umulh   v0,     r1,     r8      C U1
291         CMPCY(  r5,     r7),    r20     C L0 lo add => carry
292         ADDSUB  r7,     r6,     r23     C U0 hi add => answer
293         ldq     r1,     -24(up)         C L1
294
295         mulq    v0,     r0,     r2      C U1
296         CMPCY(  r7,     r23),   r21     C L0 hi add => carry
297         addq    r24,    r20,    r24     C U0 hi mul + carry
298         ldq     r5,     40(rp)          C L1
299
300         umulh   v0,     r0,     r6      C U1
301         ADDSUB  r4,     r25,    r25     C U0 lo + acc
302         stq     r22,    16(rp)          C L0
303         stq     r23,    24(rp)          C L1
304
305         bis     r31,    r31,    r31     C L0 st slosh
306         mulq    v0,     r1,     r7      C U1
307         bis     r31,    r31,    r31     C L1 st slosh
308         addq    r24,    r21,    r24     C U0 hi mul + carry
309 $ent6:
310         CMPCY(  r4,     r25),   r20     C L0 lo add => carry
311         bis     r31,    r31,    r31     C U1 mt
312         lda     rp,     64(rp)          C L1 bookkeeping
313         ADDSUB  r25,    r24,    r22     C U0 hi add => answer
314
315         bis     r31,    r31,    r31     C U1 mt
316         CMPCY(  r25,    r22),   r21     C L0 hi add => carry
317         addq    r3,     r20,    r3      C U0 hi mul + carry
318         ldq     r0,     -16(up)         C L1
319
320         bis     r31,    r31,    r31     C U1 mt
321         ADDSUB  r5,     r28,    r28     C L0 lo + acc
322         addq    r3,     r21,    r3      C U0 hi mul + carry
323         ldq     r4,     -16(rp)         C L1
324
325         umulh   v0,     r1,     r24     C U1
326         CMPCY(  r5,     r28),   r20     C L0 lo add => carry
327         ADDSUB  r28,    r3,     r23     C U0 hi add => answer
328         ldq     r1,     -8(up)          C L1
329
330         mulq    v0,     r0,     r25     C U1
331         CMPCY(  r28,    r23),   r21     C L0 hi add => carry
332         addq    r8,     r20,    r8      C U0 hi mul + carry
333         ldq     r5,     -8(rp)          C L1
334
335         umulh   v0,     r0,     r3      C U1
336         ADDSUB  r4,     r2,     r2      C U0 lo + acc
337         stq     r22,    -32(rp)         C L0
338         stq     r23,    -24(rp)         C L1
339
340         bis     r31,    r31,    r31     C L0 st slosh
341         mulq    v0,     r1,     r28     C U1
342         bis     r31,    r31,    r31     C L1 st slosh
343         addq    r8,     r21,    r8      C U0 hi mul + carry
344
345         CMPCY(  r4,     r2),    r20     C L0 lo add => carry
346         ADDSUB  r2,     r8,     r22     C U0 hi add => answer
347         ldl     r31,    256(up)         C prefetch up[]
348         bgt     r18,    $Loop           C U1 bookkeeping
349
350 $Lend:  CMPCY(  r2,     r22),   r21     C
351         addq    r6,     r20,    r6      C
352         ADDSUB  r5,     r7,     r7      C
353         addq    r6,     r21,    r6      C
354         ldq     r4,     0(rp)           C
355         umulh   v0,     r1,     r8      C
356         CMPCY(  r5,     r7),    r20     C
357         ADDSUB  r7,     r6,     r23     C
358         CMPCY(r7,       r23),   r21     C
359         addq    r24,    r20,    r24     C
360         ldq     r5,     8(rp)           C
361         ADDSUB  r4,     r25,    r25     C
362         stq     r22,    -16(rp)         C
363         stq     r23,    -8(rp)          C
364         addq    r24,    r21,    r24     C
365         br      L(x)
366
367         ALIGN(16)
368 $n23:   ldq     r4,     0(rp)           C
369         ldq     r5,     8(rp)           C
370         umulh   v0,     r1,     r8      C
371         ADDSUB  r4,     r25,    r25     C
372 L(x):   CMPCY(  r4,     r25),   r20     C
373         ADDSUB  r25,    r24,    r22     C
374         CMPCY(  r25,    r22),   r21     C
375         addq    r3,     r20,    r3      C
376         ADDSUB  r5,     r28,    r28     C
377         addq    r3,     r21,    r3      C
378         CMPCY(  r5,     r28),   r20     C
379         ADDSUB  r28,    r3,     r23     C
380         CMPCY(  r28,    r23),   r21     C
381         addq    r8,     r20,    r8      C
382         stq     r22,    0(rp)           C
383         stq     r23,    8(rp)           C
384         addq    r8,     r21,    r0      C
385         ret     r31,    (r26),  1       C
386 EPILOGUE()
387 ASM_END()