blob: 966b75664e146af26c5befa0937654731ab95c0a [file] [log] [blame]
Georgios Pinitas4ee8b152021-07-16 16:16:43 +01001/*
Michael Tyler7d9a6262023-02-01 16:37:07 +00002 * Copyright (c) 2021, 2023 Arm Limited.
Georgios Pinitas4ee8b152021-07-16 16:16:43 +01003 *
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 *
Michael Tyler7d9a6262023-02-01 16:37:07 +000013 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010015 *
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
Michael Tyler7d9a6262023-02-01 16:37:07 +000020 * 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.
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010023 */
24
25#pragma once
26
Michael Tyler74921ee2023-04-12 17:43:17 +010027#if defined(__aarch64__)
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010028
29namespace {
30
31void a64_transpose_interleave_24_fp16fp32(float *out, const __fp16 *in, size_t width, size_t in_stride, size_t height)
32{
33 size_t out_stride = 12 * height * sizeof(float);
34
35 __asm__ __volatile__(
36 "cmp %x[height], #0x4\n"
37 "blt 10f\n"
38 "1:" // Main row loop: Head
Michael Tyler7d9a6262023-02-01 16:37:07 +000039 "mov x25, %x[in]\n"
40 "mov x24, %x[width]\n"
41 "add x23, x25, %x[in_stride]\n"
42 "add x22, x23, %x[in_stride]\n"
43 "add x20, x22, %x[in_stride]\n"
44 "cmp x24, #0x18\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010045 "add %x[in], x20, %x[in_stride]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000046 "mov x21, %x[out]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010047 "sub %x[height], %x[height], #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010048 "blt 3f\n"
49 "2:" // Main row loop: Unroll column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +000050 "ldr q18, [x25], #0x10\n"
51 "ldr q17, [x23], #0x10\n"
52 "sub x24, x24, #0x18\n"
53 "fcvtl v26.4s, v18.4h\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000054 "ldr q16, [x22], #0x10\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000055 "ldr q25, [x20], #0x10\n"
56 "fcvtl2 v24.4s, v18.8h\n"
57 "fcvtl v5.4s, v17.4h\n"
58 "ldr q23, [x25], #0x10\n"
59 "ldr q22, [x23], #0x10\n"
60 "fcvtl v21.4s, v23.4h\n"
61 "fcvtl2 v4.4s, v17.8h\n"
62 "ldr q20, [x22], #0x10\n"
63 "ldr q3, [x20], #0x10\n"
64 "fcvtl v2.4s, v22.4h\n"
65 "fcvtl v1.4s, v16.4h\n"
66 "ldr q19, [x25], #0x10\n"
67 "ldr q18, [x23], #0x10\n"
68 "fcvtl2 v0.4s, v16.8h\n"
69 "fcvtl v31.4s, v20.4h\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000070 "ldr q17, [x22], #0x10\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000071 "ldr q16, [x20], #0x10\n"
72 "fcvtl v30.4s, v25.4h\n"
73 "fcvtl2 v29.4s, v25.8h\n"
74 "fcvtl v28.4s, v3.4h\n"
75 "str q26, [x21, #0x0]\n"
76 "cmp x24, #0x18\n"
77 "fcvtl2 v27.4s, v23.8h\n"
78 "str q24, [x21, #0x10]\n"
79 "fcvtl v26.4s, v19.4h\n"
80 "fcvtl2 v25.4s, v19.8h\n"
81 "str q21, [x21, #0x20]\n"
82 "fcvtl2 v24.4s, v22.8h\n"
83 "fcvtl v23.4s, v18.4h\n"
84 "str q5, [x21, #0x30]\n"
85 "fcvtl2 v22.4s, v18.8h\n"
86 "fcvtl2 v21.4s, v20.8h\n"
87 "str q4, [x21, #0x40]\n"
88 "fcvtl v20.4s, v17.4h\n"
89 "fcvtl2 v19.4s, v17.8h\n"
90 "str q2, [x21, #0x50]\n"
91 "fcvtl2 v18.4s, v3.8h\n"
92 "fcvtl v17.4s, v16.4h\n"
93 "str q1, [x21, #0x60]\n"
94 "fcvtl2 v16.4s, v16.8h\n"
95 "str q0, [x21, #0x70]\n"
96 "str q31, [x21, #0x80]\n"
97 "str q30, [x21, #0x90]\n"
98 "str q29, [x21, #0xa0]\n"
99 "str q28, [x21, #0xb0]\n"
100 "add x21, x21, %x[out_stride]\n"
101 "str q27, [x21, #0x0]\n"
102 "str q26, [x21, #0x10]\n"
103 "str q25, [x21, #0x20]\n"
104 "str q24, [x21, #0x30]\n"
105 "str q23, [x21, #0x40]\n"
106 "str q22, [x21, #0x50]\n"
107 "str q21, [x21, #0x60]\n"
108 "str q20, [x21, #0x70]\n"
109 "str q19, [x21, #0x80]\n"
110 "str q18, [x21, #0x90]\n"
111 "str q17, [x21, #0xa0]\n"
112 "str q16, [x21, #0xb0]\n"
113 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100114 "bge 2b\n"
115 "3:" // Main row loop: Unroll column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000116 "cmp x24, #0xc\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100117 "blt 5f\n"
118 "4:" // Main row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000119 "ldr q16, [x25], #0x10\n"
120 "ldr q21, [x23], #0x10\n"
121 "sub x24, x24, #0xc\n"
122 "cmp x24, #0xc\n"
123 "ldr q20, [x22], #0x10\n"
124 "ldr q27, [x20], #0x10\n"
125 "fcvtl v19.4s, v16.4h\n"
126 "fcvtl2 v26.4s, v16.8h\n"
127 "ldr d16, [x25], #0x8\n"
128 "ldr d18, [x23], #0x8\n"
129 "fcvtl v25.4s, v16.4h\n"
130 "fcvtl v24.4s, v21.4h\n"
131 "ldr d17, [x22], #0x8\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000132 "ldr d16, [x20], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000133 "fcvtl2 v23.4s, v21.8h\n"
134 "fcvtl v22.4s, v18.4h\n"
135 "fcvtl v21.4s, v20.4h\n"
136 "fcvtl2 v20.4s, v20.8h\n"
137 "str q19, [x21, #0x0]\n"
138 "fcvtl v19.4s, v17.4h\n"
139 "fcvtl v18.4s, v27.4h\n"
140 "str q26, [x21, #0x10]\n"
141 "fcvtl2 v17.4s, v27.8h\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100142 "fcvtl v16.4s, v16.4h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000143 "str q25, [x21, #0x20]\n"
144 "str q24, [x21, #0x30]\n"
145 "str q23, [x21, #0x40]\n"
146 "str q22, [x21, #0x50]\n"
147 "str q21, [x21, #0x60]\n"
148 "str q20, [x21, #0x70]\n"
149 "str q19, [x21, #0x80]\n"
150 "str q18, [x21, #0x90]\n"
151 "str q17, [x21, #0xa0]\n"
152 "str q16, [x21, #0xb0]\n"
153 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100154 "bge 4b\n"
155 "5:" // Main row loop: Column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000156 "cmp x24, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100157 "blt 7f\n"
158 "6:" // Main row loop: width 4 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000159 "ldr d19, [x25], #0x8\n"
160 "ldr d18, [x23], #0x8\n"
161 "sub x24, x24, #0x4\n"
162 "cmp x24, #0x4\n"
163 "ldr d17, [x22], #0x8\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100164 "ldr d16, [x20], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000165 "fcvtl v19.4s, v19.4h\n"
166 "fcvtl v18.4s, v18.4h\n"
167 "fcvtl v17.4s, v17.4h\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100168 "fcvtl v16.4s, v16.4h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000169 "str q19, [x21, #0x0]\n"
170 "str q18, [x21, #0x30]\n"
171 "str q17, [x21, #0x60]\n"
172 "str q16, [x21, #0x90]\n"
173 "add x21, x21, #0x10\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100174 "bge 6b\n"
175 "7:" // Main row loop: width 4 loop: skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000176 "cmp x24, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100177 "blt 9f\n"
178 "8:" // Main row loop: width 1 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000179 "ldr h19, [x25], #0x2\n"
180 "ldr h18, [x23], #0x2\n"
181 "sub x24, x24, #0x1\n"
182 "cmp x24, #0x1\n"
183 "ldr h17, [x22], #0x2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100184 "ldr h16, [x20], #0x2\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000185 "fcvtl v19.4s, v19.4h\n"
186 "fcvtl v18.4s, v18.4h\n"
187 "fcvtl v17.4s, v17.4h\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100188 "fcvtl v16.4s, v16.4h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000189 "str s19, [x21, #0x0]\n"
190 "str s18, [x21, #0x30]\n"
191 "str s17, [x21, #0x60]\n"
192 "str s16, [x21, #0x90]\n"
193 "add x21, x21, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100194 "bge 8b\n"
195 "9:" // Main row loop: width 1 loop: skip
Michael Tylerbe13cea2023-01-17 11:04:14 +0000196 "cmp %x[height], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000197 "add %x[out], %x[out], #0xc0\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100198 "bge 1b\n"
199 "cbz %x[height], 20f\n"
200 "10:" // Main loop skip
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100201 "11:" // Tail row loop: Head
Michael Tyler7d9a6262023-02-01 16:37:07 +0000202 "mov x20, %x[width]\n"
203 "mov x25, %x[in]\n"
204 "cmp x20, #0x18\n"
205 "add %x[in], x25, %x[in_stride]\n"
206 "mov x21, %x[out]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100207 "sub %x[height], %x[height], #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100208 "blt 13f\n"
209 "12:" // Tail row loop: Unroll column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000210 "ldr q16, [x25], #0x10\n"
211 "ldr q20, [x25], #0x10\n"
212 "sub x20, x20, #0x18\n"
213 "fcvtl v18.4s, v16.4h\n"
214 "ldr q19, [x25], #0x10\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100215 "fcvtl2 v17.4s, v16.8h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000216 "fcvtl v16.4s, v20.4h\n"
217 "str q18, [x21, #0x0]\n"
218 "str q17, [x21, #0x10]\n"
219 "cmp x20, #0x18\n"
220 "fcvtl2 v18.4s, v20.8h\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100221 "fcvtl v17.4s, v19.4h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000222 "str q16, [x21, #0x20]\n"
223 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100224 "fcvtl2 v16.4s, v19.8h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000225 "str q18, [x21, #0x0]\n"
226 "str q17, [x21, #0x10]\n"
227 "str q16, [x21, #0x20]\n"
228 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100229 "bge 12b\n"
230 "13:" // Tail row loop: Unroll column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000231 "cmp x20, #0xc\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100232 "blt 15f\n"
233 "14:" // Tail row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000234 "ldr q17, [x25], #0x10\n"
235 "ldr d18, [x25], #0x8\n"
236 "sub x20, x20, #0xc\n"
237 "cmp x20, #0xc\n"
238 "fcvtl v16.4s, v17.4h\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100239 "fcvtl2 v17.4s, v17.8h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000240 "str q16, [x21, #0x0]\n"
241 "fcvtl v16.4s, v18.4h\n"
242 "str q17, [x21, #0x10]\n"
243 "str q16, [x21, #0x20]\n"
244 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100245 "bge 14b\n"
246 "15:" // Tail row loop: Column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000247 "cmp x20, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100248 "blt 17f\n"
249 "16:" // Tail row loop: width 4 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000250 "ldr d16, [x25], #0x8\n"
251 "sub x20, x20, #0x4\n"
252 "cmp x20, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100253 "fcvtl v16.4s, v16.4h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000254 "str q16, [x21, #0x0]\n"
255 "add x21, x21, #0x10\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100256 "bge 16b\n"
257 "17:" // Tail row loop: width 4 loop: skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000258 "cmp x20, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100259 "blt 19f\n"
260 "18:" // Tail row loop: width 1 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000261 "ldr h16, [x25], #0x2\n"
262 "sub x20, x20, #0x1\n"
263 "cmp x20, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100264 "fcvtl v16.4s, v16.4h\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000265 "str s16, [x21, #0x0]\n"
266 "add x21, x21, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100267 "bge 18b\n"
268 "19:" // Tail row loop: width 1 loop: skip
Michael Tylerbe13cea2023-01-17 11:04:14 +0000269 "cmp %x[height], #0x1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000270 "add %x[out], %x[out], #0x30\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100271 "bge 11b\n"
272 "20:" // Done
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100273 : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out)
274 : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [width] "r" (width)
Michael Tyler7d9a6262023-02-01 16:37:07 +0000275 : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", "x20", "x21", "x22", "x23", "x24", "x25"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100276 );
277}
278
279} // anonymous namespace
280template<>
281void Transform<12, 1, true, VLType::None>(
282 float *out, const __fp16 *in, int stride, int x0, int xmax, int k0, int kmax)
283{
284 a64_transpose_interleave_24_fp16fp32(
285 out,
286 in + k0 * stride + x0,
287 (xmax-x0),
288 stride * sizeof(__fp16),
289 (kmax-k0)
290 );
291}
292
Michael Tyler74921ee2023-04-12 17:43:17 +0100293
294#endif // defined(__aarch64__)