added dgemm-, dtrmm-, zgemm- and ztrmm-kernel for power8
[platform/upstream/openblas.git] / kernel / power / gemm_ncopy_4.S
1 /*********************************************************************/
2 /* Copyright 2009, 2010 The University of Texas at Austin.           */
3 /* All rights reserved.                                              */
4 /*                                                                   */
5 /* Redistribution and use in source and binary forms, with or        */
6 /* without modification, are permitted provided that the following   */
7 /* conditions are met:                                               */
8 /*                                                                   */
9 /*   1. Redistributions of source code must retain the above         */
10 /*      copyright notice, this list of conditions and the following  */
11 /*      disclaimer.                                                  */
12 /*                                                                   */
13 /*   2. Redistributions in binary form must reproduce the above      */
14 /*      copyright notice, this list of conditions and the following  */
15 /*      disclaimer in the documentation and/or other materials       */
16 /*      provided with the distribution.                              */
17 /*                                                                   */
18 /*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
19 /*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
20 /*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
21 /*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
22 /*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
23 /*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
24 /*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
25 /*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
26 /*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
27 /*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
28 /*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
29 /*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
30 /*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
31 /*    POSSIBILITY OF SUCH DAMAGE.                                    */
32 /*                                                                   */
33 /* The views and conclusions contained in the software and           */
34 /* documentation are those of the authors and should not be          */
35 /* interpreted as representing official policies, either expressed   */
36 /* or implied, of The University of Texas at Austin.                 */
37 /*********************************************************************/
38
39 #define ASSEMBLER
40 #include "common.h"
41
42 #define M       r3
43 #define N       r4
44 #define A       r5
45 #define LDA     r6
46 #define B       r7
47
48 #define AO1     r8
49 #define AO2     r9
50 #define AO3     r10
51 #define AO4     r11
52
53 #define J       r12
54
55 #define PREA    r14
56 #define PREB1   r15
57
58 #define c01     f0
59 #define c02     f1
60 #define c03     f2
61 #define c04     f3
62 #define c05     f4
63 #define c06     f5
64 #define c07     f6
65 #define c08     f7
66 #define c09     f8
67 #define c10     f9
68 #define c11     f10
69 #define c12     f11
70 #define c13     f12
71 #define c14     f13
72 #define c15     f14
73 #define c16     f15
74
75 #define STACKSIZE 32
76
77 #ifdef CELL
78 #define PREFETCHSIZE   16
79 #define PREFETCHWSIZE  72
80 #endif
81
82 #ifdef PPC970
83 #define PREFETCHSIZE   16
84 #define PREFETCHWSIZE  72
85 #endif
86
87 #ifdef PPC440
88 #define PREFETCHSIZE   16
89 #define PREFETCHWSIZE  72
90 #endif
91
92 #ifdef POWER4
93 #define PREFETCHSIZE   16
94 #define PREFETCHWSIZE  72
95 #endif
96
97 #ifdef POWER5
98 #define PREFETCHSIZE   16
99 #define PREFETCHWSIZE  72
100 #endif
101
102 #ifdef POWER6
103 #define PREFETCHSIZE   16
104 #define PREFETCHWSIZE  72
105 #endif
106
107 #ifdef PPCG4
108 #define PREFETCHSIZE   16
109 #define PREFETCHWSIZE  72
110 #endif
111
112 #ifdef POWER8
113 #define PREFETCHSIZE   16
114 #define PREFETCHWSIZE  72
115 #endif
116
117         PROLOGUE
118         PROFCODE
119
120         addi    SP, SP, -STACKSIZE
121         li      r0, 0
122
123         stfd    f14,    0(SP)
124         stfd    f15,    8(SP)
125
126 #ifdef __64BIT__
127         std     r14,   16(SP)
128         std     r15,   24(SP)
129 #else
130         stw     r14,   16(SP)
131         stw     r15,   20(SP)
132 #endif
133
134         slwi    LDA, LDA, BASE_SHIFT
135
136         li      PREA,  PREFETCHSIZE * SIZE
137         li      PREB1, (PREFETCHWSIZE +  0) * SIZE
138
139         cmpwi   cr0, M, 0
140         ble-    LL(999)
141         cmpwi   cr0, N, 0
142         ble-    LL(999)
143
144         srawi.  J,  N,  2
145         ble     LL(20)
146         .align 4
147
148 LL(10):
149         mr      AO1, A
150         add     AO2, A,   LDA
151         add     AO3, AO2, LDA
152         add     AO4, AO3, LDA
153         add     A,   AO4, LDA
154
155         srawi.  r0,  M,  2
156         mtspr   CTR, r0
157         ble     LL(15)
158         .align 4
159
160 LL(12):
161         LFD     c01,   0 * SIZE(AO1)
162         LFD     c02,   1 * SIZE(AO1)
163         LFD     c03,   2 * SIZE(AO1)
164         LFD     c04,   3 * SIZE(AO1)
165
166         LFD     c05,   0 * SIZE(AO2)
167         LFD     c06,   1 * SIZE(AO2)
168         LFD     c07,   2 * SIZE(AO2)
169         LFD     c08,   3 * SIZE(AO2)
170
171         LFD     c09,   0 * SIZE(AO3)
172         LFD     c10,   1 * SIZE(AO3)
173         LFD     c11,   2 * SIZE(AO3)
174         LFD     c12,   3 * SIZE(AO3)
175
176         LFD     c13,   0 * SIZE(AO4)
177         LFD     c14,   1 * SIZE(AO4)
178         LFD     c15,   2 * SIZE(AO4)
179         LFD     c16,   3 * SIZE(AO4)
180
181         STFD    c01,   0 * SIZE(B)
182         STFD    c05,   1 * SIZE(B)
183         STFD    c09,   2 * SIZE(B)
184         STFD    c13,   3 * SIZE(B)
185
186         STFD    c02,   4 * SIZE(B)
187         STFD    c06,   5 * SIZE(B)
188         STFD    c10,   6 * SIZE(B)
189         STFD    c14,   7 * SIZE(B)
190
191         STFD    c03,   8 * SIZE(B)
192         STFD    c07,   9 * SIZE(B)
193         STFD    c11,  10 * SIZE(B)
194         STFD    c15,  11 * SIZE(B)
195
196         STFD    c04,  12 * SIZE(B)
197         STFD    c08,  13 * SIZE(B)
198         STFD    c12,  14 * SIZE(B)
199         STFD    c16,  15 * SIZE(B)
200
201 #if defined(POWER6) || defined(POWER8)
202         dcbtst  PREA, AO1
203         dcbtst  PREA, AO2
204         dcbtst  PREA, AO3
205         dcbtst  PREA, AO4
206 #else
207         dcbt    PREA, AO1
208         dcbt    PREA, AO2
209         dcbt    PREA, AO3
210         dcbt    PREA, AO4
211 #endif
212
213         dcbtst  PREB1, B
214
215         addi    AO1, AO1,  4 * SIZE
216         addi    AO2, AO2,  4 * SIZE
217         addi    AO3, AO3,  4 * SIZE
218         addi    AO4, AO4,  4 * SIZE
219         addi    B,   B,   16 * SIZE
220         bdnz    LL(12)
221         .align 4
222
223 LL(15):
224         andi.   r0,  M,  3
225         mtspr   CTR, r0
226         ble     LL(17)
227         .align 4
228
229 LL(16):
230         LFD     c01,   0 * SIZE(AO1)
231         LFD     c05,   0 * SIZE(AO2)
232         LFD     c09,   0 * SIZE(AO3)
233         LFD     c13,   0 * SIZE(AO4)
234
235         STFD    c01,   0 * SIZE(B)
236         STFD    c05,   1 * SIZE(B)
237         STFD    c09,   2 * SIZE(B)
238         STFD    c13,   3 * SIZE(B)
239
240         addi    AO1, AO1,  1 * SIZE
241         addi    AO2, AO2,  1 * SIZE
242         addi    AO3, AO3,  1 * SIZE
243         addi    AO4, AO4,  1 * SIZE
244         addi    B,   B,    4 * SIZE
245         bdnz    LL(16)
246         .align 4
247
248 LL(17):
249         addic.  J, J, -1
250         bgt     LL(10)
251         .align 4
252
253 LL(20):
254         andi.   J,  N,  2
255         ble     LL(30)
256
257         mr      AO1, A
258         add     AO2, A,   LDA
259         add     A,   AO2, LDA
260
261         srawi.  r0,  M,  2
262         mtspr   CTR, r0
263         ble     LL(25)
264         .align 4
265
266 LL(22):
267         LFD     c01,   0 * SIZE(AO1)
268         LFD     c02,   1 * SIZE(AO1)
269         LFD     c03,   2 * SIZE(AO1)
270         LFD     c04,   3 * SIZE(AO1)
271
272         LFD     c05,   0 * SIZE(AO2)
273         LFD     c06,   1 * SIZE(AO2)
274         LFD     c07,   2 * SIZE(AO2)
275         LFD     c08,   3 * SIZE(AO2)
276
277         STFD    c01,   0 * SIZE(B)
278         STFD    c05,   1 * SIZE(B)
279         STFD    c02,   2 * SIZE(B)
280         STFD    c06,   3 * SIZE(B)
281
282         STFD    c03,   4 * SIZE(B)
283         STFD    c07,   5 * SIZE(B)
284         STFD    c04,   6 * SIZE(B)
285         STFD    c08,   7 * SIZE(B)
286
287         addi    AO1, AO1,  4 * SIZE
288         addi    AO2, AO2,  4 * SIZE
289         addi    B,   B,    8 * SIZE
290         bdnz    LL(22)
291         .align 4
292
293 LL(25):
294         andi.   r0,  M,  3
295         mtspr   CTR, r0
296         ble     LL(30)
297         .align 4
298
299 LL(26):
300         LFD     c01,   0 * SIZE(AO1)
301         LFD     c05,   0 * SIZE(AO2)
302
303         STFD    c01,   0 * SIZE(B)
304         STFD    c05,   1 * SIZE(B)
305
306         addi    AO1, AO1,  1 * SIZE
307         addi    AO2, AO2,  1 * SIZE
308         addi    B,   B,    2 * SIZE
309         bdnz    LL(26)
310         .align 4
311
312 LL(30):
313         andi.   J,  N,  1
314         ble     LL(999)
315
316         mr      AO1, A
317
318         srawi.  r0,  M,  2
319         mtspr   CTR, r0
320         ble     LL(35)
321         .align 4
322
323 LL(32):
324         LFD     c01,   0 * SIZE(AO1)
325         LFD     c02,   1 * SIZE(AO1)
326         LFD     c03,   2 * SIZE(AO1)
327         LFD     c04,   3 * SIZE(AO1)
328
329         STFD    c01,   0 * SIZE(B)
330         STFD    c02,   1 * SIZE(B)
331         STFD    c03,   2 * SIZE(B)
332         STFD    c04,   3 * SIZE(B)
333
334         addi    AO1, AO1,  4 * SIZE
335         addi    B,   B,    4 * SIZE
336         bdnz    LL(32)
337         .align 4
338
339 LL(35):
340         andi.   r0,  M,  3
341         mtspr   CTR, r0
342         ble     LL(999)
343         .align 4
344
345 LL(36):
346         LFD     c01,   0 * SIZE(AO1)
347
348         STFD    c01,   0 * SIZE(B)
349
350         addi    AO1, AO1,  1 * SIZE
351         addi    B,   B,    1 * SIZE
352         bdnz    LL(36)
353         .align 4
354
355 LL(999):
356         li      r3, 0
357
358         lfd     f14,    0(SP)
359         lfd     f15,    8(SP)
360
361 #ifdef __64BIT__
362         ld      r14,   16(SP)
363         ld      r15,   24(SP)
364 #else
365         lwz     r14,   16(SP)
366         lwz     r15,   20(SP)
367 #endif
368         addi    SP, SP, STACKSIZE
369
370         blr
371         EPILOGUE