blob: 88b40d7c1e0c45709125feb67484c246cbd3cb5d [file] [log] [blame]
Pablo Telloeb82fd22018-02-23 13:43:50 +00001/*
2 * Copyright (c) 2017-2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#pragma once
25
Pablo Tello99ef8402018-03-20 16:46:55 +000026#if defined(__aarch64__) && defined(__ARM_FP16_ARGS)
Pablo Telloeb82fd22018-02-23 13:43:50 +000027
28#include <arm_neon.h>
29
30#include "../asmlib.hpp"
31
Anthony Barbier5f707732018-07-03 16:22:02 +010032template<>
33template<>
David Manselld93991e2018-07-06 14:52:52 +010034inline void TransformImpl<8, 1, false, 4, 2, false>::Transform(float *out, const __fp16 *in, int ldin, int y0, int ymax, int k0, int kmax) {
Anthony Barbier5f707732018-07-03 16:22:02 +010035 float *outptr = out;
36 const __fp16 *inptr = in;
Pablo Telloeb82fd22018-02-23 13:43:50 +000037
Georgios Pinitasd636bc52018-11-07 16:35:35 +000038 __fp16 zerobuff[16]; // 8 for asm loop plus up to 7 for overflow loop
Pablo Telloeb82fd22018-02-23 13:43:50 +000039
Anthony Barbier5f707732018-07-03 16:22:02 +010040 for (int y=y0; y<ymax; y+=8) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000041 const __fp16 *inptr0 = inptr + y * ldin + k0;
42 const __fp16 *inptr1 = inptr0 + ldin;
43 const __fp16 *inptr2 = inptr1 + ldin;
44 const __fp16 *inptr3 = inptr2 + ldin;
45 const __fp16 *inptr4 = inptr3 + ldin;
46 const __fp16 *inptr5 = inptr4 + ldin;
47 const __fp16 *inptr6 = inptr5 + ldin;
48 const __fp16 *inptr7 = inptr6 + ldin;
49
50 prefetch_2x(inptr0);
51 prefetch_2x(inptr1);
52 prefetch_2x(inptr2);
53 prefetch_2x(inptr3);
54 prefetch_2x(inptr4);
55 prefetch_2x(inptr5);
56 prefetch_2x(inptr6);
57 prefetch_2x(inptr7);
58
Anthony Barbier5f707732018-07-03 16:22:02 +010059 int x=(kmax-k0);
60 for (;x>7;x-=8) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000061 /* Cope with ragged cases by copying from a buffer of zeroes instead */
Anthony Barbier5f707732018-07-03 16:22:02 +010062 if ((y + 7) >= ymax) {
63 switch ((y + 7) - ymax) {
Pablo Telloeb82fd22018-02-23 13:43:50 +000064 /* Everything falls through in here */
65 case 6:
66 inptr1 = zerobuff;
67 case 5:
68 inptr2 = zerobuff;
69 case 4:
70 inptr3 = zerobuff;
71 case 3:
72 inptr4 = zerobuff;
73 case 2:
74 inptr5 = zerobuff;
75 case 1:
76 inptr6 = zerobuff;
77 case 0:
78 inptr7 = zerobuff;
79 break;
80
81 default:
82 UNREACHABLE("Impossible.");
83 }
84 }
85
Anthony Barbier5f707732018-07-03 16:22:02 +010086 __asm __volatile (
Pablo Telloeb82fd22018-02-23 13:43:50 +000087 // Load up 8 elements (2 vectors) from each of 8 sources.
Anthony Barbier5f707732018-07-03 16:22:02 +010088 "LDR q0, [%[inptr0]], #16\n"
89 "LDR q2, [%[inptr1]], #16\n"
90 "FCVTL2 v1.4s, v0.8h\n"
91 "FCVTL v0.4s, v0.4h\n"
92 "LDR q4, [%[inptr2]], #16\n" // q4=C0C1C2C3
93 "FCVTL2 v3.4s, v2.8h\n"
94 "FCVTL v2.4s, v2.4h\n"
95 "FCVTL2 v5.4s, v4.8h\n"
96 "FCVTL v4.4s, v4.4h\n"
97 "ZIP1 v16.4s, v0.4s, v4.4s\n" // q16=A0C0A1C1
Pablo Telloeb82fd22018-02-23 13:43:50 +000098 ASM_PREFETCH("[%[inptr0], #128]")
Anthony Barbier5f707732018-07-03 16:22:02 +010099 "LDR q6, [%[inptr3]], #16\n" // q6=D0D1D2D3
100 "FCVTL2 v7.4s, v6.8h\n"
101 "FCVTL v6.4s, v6.4h\n"
102 "ZIP1 v17.4s, v2.4s, v6.4s\n" // q17=B0D0B1D1
103 "LDR q8, [%[inptr4]], #16\n"
104 "LDR q10, [%[inptr5]], #16\n"
105 "FCVTL2 v9.4s, v8.8h\n"
106 "FCVTL v8.4s, v8.4h\n"
107 ASM_PREFETCH("[%[inptr1], #128]")
108 "LDR q12, [%[inptr6]], #16\n"
109 "FCVTL2 v11.4s, v10.8h\n"
110 "FCVTL v10.4s, v10.4h\n"
111 "FCVTL2 v13.4s, v12.8h\n"
112 "FCVTL v12.4s, v12.4h\n"
113 "ZIP1 v18.4s, v8.4s, v12.4s\n"
114 "LDR q14, [%[inptr7]], #16\n"
115 "FCVTL2 v15.4s, v14.8h\n"
116 "FCVTL v14.4s, v14.4h\n"
117 "ZIP1 v19.4s, v10.4s, v14.4s\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000118
119 ASM_PREFETCH("[%[inptr2], #128]")
Anthony Barbier5f707732018-07-03 16:22:02 +0100120 "ZIP1 v20.4s, v16.4s, v17.4s\n" // q20=A0B0C0D0
121 "ZIP1 v21.4s, v18.4s, v19.4s\n"
122 "ZIP2 v22.4s, v16.4s, v17.4s\n"
123 "ZIP2 v23.4s, v18.4s, v19.4s\n"
124 ASM_PREFETCH("[%[inptr3], #128]")
Pablo Telloeb82fd22018-02-23 13:43:50 +0000125
Anthony Barbier5f707732018-07-03 16:22:02 +0100126 "ZIP2 v16.4s, v0.4s, v4.4s\n"
127 "ZIP2 v17.4s, v2.4s, v6.4s\n"
128 "STP q20, q21, [%[outptr]], #32\n" // Write back the first element of each source
Pablo Telloeb82fd22018-02-23 13:43:50 +0000129
Anthony Barbier5f707732018-07-03 16:22:02 +0100130 "ZIP2 v18.4s, v8.4s, v12.4s\n"
131 ASM_PREFETCH("[%[inptr4], #128]")
132 "ZIP2 v19.4s, v10.4s, v14.4s\n"
133 "STP q22, q23, [%[outptr]], #32\n" // Write back the second element of each source
Pablo Telloeb82fd22018-02-23 13:43:50 +0000134
Anthony Barbier5f707732018-07-03 16:22:02 +0100135 "ZIP1 v20.4s, v16.4s, v17.4s\n"
136 "ZIP1 v21.4s, v18.4s, v19.4s\n"
137 ASM_PREFETCH("[%[inptr5], #128]")
138 "ZIP2 v22.4s, v16.4s, v17.4s\n"
139 "ZIP2 v23.4s, v18.4s, v19.4s\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000140
Anthony Barbier5f707732018-07-03 16:22:02 +0100141 "ZIP1 v16.4s, v1.4s, v5.4s\n"
142 "ZIP1 v17.4s, v3.4s, v7.4s\n"
143 ASM_PREFETCH("[%[inptr6], #128]")
144 "STP q20, q21, [%[outptr]], #32\n" // Third element
Pablo Telloeb82fd22018-02-23 13:43:50 +0000145
Anthony Barbier5f707732018-07-03 16:22:02 +0100146 "ZIP1 v18.4s, v9.4s, v13.4s\n"
147 "ZIP1 v19.4s, v11.4s, v15.4s\n"
148 "STP q22, q23, [%[outptr]], #32\n" // Fourth element
Pablo Telloeb82fd22018-02-23 13:43:50 +0000149 ASM_PREFETCH("[%[inptr7], #128]")
150
Anthony Barbier5f707732018-07-03 16:22:02 +0100151 "ZIP1 v20.4s, v16.4s, v17.4s\n"
152 "ZIP1 v21.4s, v18.4s, v19.4s\n"
153 "ZIP2 v22.4s, v16.4s, v17.4s\n"
154 "ZIP2 v23.4s, v18.4s, v19.4s\n"
Pablo Telloeb82fd22018-02-23 13:43:50 +0000155
Anthony Barbier5f707732018-07-03 16:22:02 +0100156 "ZIP2 v16.4s, v1.4s, v5.4s\n"
157 "ZIP2 v17.4s, v3.4s, v7.4s\n"
158 "STP q20, q21, [%[outptr]], #32\n" // Fifth element
Pablo Telloeb82fd22018-02-23 13:43:50 +0000159
Anthony Barbier5f707732018-07-03 16:22:02 +0100160 "ZIP2 v18.4s, v9.4s, v13.4s\n"
161 "ZIP2 v19.4s, v11.4s, v15.4s\n"
162 "STP q22, q23, [%[outptr]], #32\n" // Sixth element
Pablo Telloeb82fd22018-02-23 13:43:50 +0000163
Anthony Barbier5f707732018-07-03 16:22:02 +0100164 "ZIP1 v20.4s, v16.4s, v17.4s\n"
165 "ZIP1 v21.4s, v18.4s, v19.4s\n"
166 "STP q20, q21, [%[outptr]], #32\n" // Seventh element
Pablo Telloeb82fd22018-02-23 13:43:50 +0000167
Anthony Barbier5f707732018-07-03 16:22:02 +0100168 "ZIP2 v22.4s, v16.4s, v17.4s\n"
169 "ZIP2 v23.4s, v18.4s, v19.4s\n"
170 "STP q22, q23, [%[outptr]], #32\n" // Eighth element
171 : [inptr0] "+r" (inptr0), [inptr1] "+r" (inptr1), [inptr2] "+r" (inptr2), [inptr3] "+r" (inptr3),
172 [inptr4] "+r" (inptr4), [inptr5] "+r" (inptr5), [inptr6] "+r" (inptr6), [inptr7] "+r" (inptr7), [outptr] "+r" (outptr)
Pablo Telloeb82fd22018-02-23 13:43:50 +0000173 :
174 : "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12",
Georgios Pinitasd636bc52018-11-07 16:35:35 +0000175 "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "memory"
Anthony Barbier5f707732018-07-03 16:22:02 +0100176 );
Pablo Telloeb82fd22018-02-23 13:43:50 +0000177 }
178
Anthony Barbier5f707732018-07-03 16:22:02 +0100179 for (;x>0;x--) {
Pablo Telloeb82fd22018-02-23 13:43:50 +0000180 *outptr++ = *inptr0++;
181 *outptr++ = *inptr1++;
182 *outptr++ = *inptr2++;
183 *outptr++ = *inptr3++;
184 *outptr++ = *inptr4++;
185 *outptr++ = *inptr5++;
186 *outptr++ = *inptr6++;
187 *outptr++ = *inptr7++;
188 }
189 }
190}
191
Pablo Tello99ef8402018-03-20 16:46:55 +0000192#endif // __aarch64__ && __ARM_FP16_ARGS