blob: a034be5e748c6da3541642342b197e1c86ff8ff9 [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
27#ifdef __ARM_FEATURE_SVE
28
29
30namespace {
31
32void sve_transpose_interleave_1VL_1x4(uint8_t *out, const uint8_t *in, size_t width, size_t in_stride, size_t height)
33{
34 uint8_t *pad_row = reinterpret_cast<uint8_t *>(alloca(width * sizeof(uint8_t)));
35
36 if (height % 4) {
37 memset(pad_row, 0, width * sizeof(uint8_t));
38 }
39
40 size_t out_stride = 1 * roundup<size_t>(height, 4) * get_vector_length<uint32_t>();
41
42 __asm__ __volatile__(
Michael Tylerbe13cea2023-01-17 11:04:14 +000043 "cmp %x[height], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000044 "ptrue p1.b\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010045 "blt 6f\n"
46 "1:" // Main row loop: Head
Michael Tyler7d9a6262023-02-01 16:37:07 +000047 "mov x10, %x[in]\n"
48 "add x9, x10, %x[in_stride]\n"
49 "add x28, x9, %x[in_stride]\n"
50 "add x27, x28, %x[in_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010051 "add x26, x27, %x[in_stride]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000052 "mov x25, %x[width]\n"
53 "cntb x24, ALL, MUL #2\n"
54 "add x23, x26, %x[in_stride]\n"
55 "add x21, x23, %x[in_stride]\n"
56 "add x20, x21, %x[in_stride]\n"
57 "cmp x25, x24\n"
58 "add %x[in], x20, %x[in_stride]\n"
59 "mov x22, %x[out]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010060 "sub %x[height], %x[height], #0x8\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010061 "blt 3f\n"
62 "2:" // Main row loop: Unroll column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +000063 "ld1b { z20.b }, p1/Z, [x10]\n"
64 "ld1b { z18.b }, p1/Z, [x9]\n"
65 "sub x25, x25, x24\n"
66 "cmp x25, x24\n"
67 "ld1b { z17.b }, p1/Z, [x28]\n"
68 "ld1b { z16.b }, p1/Z, [x27]\n"
69 "zip1 z25.b, z20.b, z17.b\n"
70 "zip1 z24.b, z18.b, z16.b\n"
71 "ld1b { z21.b }, p1/Z, [x26]\n"
72 "ld1b { z19.b }, p1/Z, [x23]\n"
73 "zip2 z2.b, z20.b, z17.b\n"
74 "zip2 z1.b, z18.b, z16.b\n"
75 "ld1b { z18.b }, p1/Z, [x21]\n"
76 "ld1b { z17.b }, p1/Z, [x20]\n"
77 "zip1 z20.b, z21.b, z18.b\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000078 "zip1 z16.b, z19.b, z17.b\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000079 "ld1b { z0.b }, p1/Z, [x10, #1, MUL VL]\n"
80 "ld1b { z31.b }, p1/Z, [x9, #1, MUL VL]\n"
81 "zip2 z30.b, z21.b, z18.b\n"
82 "zip2 z29.b, z19.b, z17.b\n"
83 "ld1b { z23.b }, p1/Z, [x28, #1, MUL VL]\n"
84 "ld1b { z22.b }, p1/Z, [x27, #1, MUL VL]\n"
85 "zip1 z19.b, z25.b, z24.b\n"
86 "zip1 z18.b, z20.b, z16.b\n"
87 "ld1b { z28.b }, p1/Z, [x26, #1, MUL VL]\n"
88 "ld1b { z27.b }, p1/Z, [x23, #1, MUL VL]\n"
89 "zip2 z17.b, z25.b, z24.b\n"
90 "zip2 z16.b, z20.b, z16.b\n"
91 "ld1b { z21.b }, p1/Z, [x21, #1, MUL VL]\n"
92 "ld1b { z20.b }, p1/Z, [x20, #1, MUL VL]\n"
93 "st1b { z19.b }, p1, [x22]\n"
94 "zip1 z26.b, z0.b, z23.b\n"
95 "st1b { z18.b }, p1, [x22, #1, MUL VL]\n"
96 "add x22, x22, %x[out_stride]\n"
97 "zip1 z25.b, z31.b, z22.b\n"
98 "zip1 z24.b, z28.b, z21.b\n"
99 "st1b { z17.b }, p1, [x22]\n"
100 "zip1 z19.b, z27.b, z20.b\n"
101 "zip1 z17.b, z2.b, z1.b\n"
102 "addvl x10, x10, #2\n"
103 "st1b { z16.b }, p1, [x22, #1, MUL VL]\n"
104 "add x22, x22, %x[out_stride]\n"
105 "zip1 z18.b, z30.b, z29.b\n"
106 "zip2 z16.b, z2.b, z1.b\n"
107 "st1b { z17.b }, p1, [x22]\n"
108 "zip2 z17.b, z30.b, z29.b\n"
109 "zip2 z23.b, z0.b, z23.b\n"
110 "addvl x9, x9, #2\n"
111 "st1b { z18.b }, p1, [x22, #1, MUL VL]\n"
112 "add x22, x22, %x[out_stride]\n"
113 "zip2 z22.b, z31.b, z22.b\n"
114 "zip2 z21.b, z28.b, z21.b\n"
115 "st1b { z16.b }, p1, [x22]\n"
116 "zip2 z20.b, z27.b, z20.b\n"
117 "zip1 z16.b, z26.b, z25.b\n"
118 "addvl x28, x28, #2\n"
119 "st1b { z17.b }, p1, [x22, #1, MUL VL]\n"
120 "add x22, x22, %x[out_stride]\n"
121 "zip1 z18.b, z24.b, z19.b\n"
122 "zip2 z17.b, z26.b, z25.b\n"
123 "st1b { z16.b }, p1, [x22]\n"
124 "zip2 z16.b, z24.b, z19.b\n"
125 "zip1 z19.b, z23.b, z22.b\n"
126 "addvl x27, x27, #2\n"
127 "st1b { z18.b }, p1, [x22, #1, MUL VL]\n"
128 "add x22, x22, %x[out_stride]\n"
129 "zip1 z18.b, z21.b, z20.b\n"
130 "addvl x26, x26, #2\n"
131 "st1b { z17.b }, p1, [x22]\n"
132 "addvl x23, x23, #2\n"
133 "addvl x21, x21, #2\n"
134 "zip2 z17.b, z23.b, z22.b\n"
135 "st1b { z16.b }, p1, [x22, #1, MUL VL]\n"
136 "add x22, x22, %x[out_stride]\n"
137 "addvl x20, x20, #2\n"
138 "zip2 z16.b, z21.b, z20.b\n"
139 "st1b { z19.b }, p1, [x22]\n"
140 "st1b { z18.b }, p1, [x22, #1, MUL VL]\n"
141 "add x22, x22, %x[out_stride]\n"
142 "st1b { z17.b }, p1, [x22]\n"
143 "st1b { z16.b }, p1, [x22, #1, MUL VL]\n"
144 "add x22, x22, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100145 "bge 2b\n"
146 "3:" // Main row loop: Unroll column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000147 "cbz x25, 5f\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100148 "4:" // Main row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000149 "whilelt p0.b, XZR, x25\n"
150 "ld1b { z19.b }, p0/Z, [x10]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100151 "ld1b { z18.b }, p0/Z, [x9]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000152 "decw x25\n"
153 "ld1b { z17.b }, p0/Z, [x28]\n"
154 "ld1b { z16.b }, p0/Z, [x27]\n"
155 "zip1 z21.b, z19.b, z17.b\n"
156 "zip1 z20.b, z18.b, z16.b\n"
157 "ld1b { z18.b }, p0/Z, [x26]\n"
158 "ld1b { z19.b }, p0/Z, [x23]\n"
159 "cmp x25, #0x0\n"
160 "incd x10, ALL, MUL #2\n"
161 "ld1b { z17.b }, p0/Z, [x21]\n"
162 "ld1b { z16.b }, p0/Z, [x20]\n"
163 "zip1 z18.b, z18.b, z17.b\n"
164 "zip1 z16.b, z19.b, z16.b\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100165 "incd x9, ALL, MUL #2\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000166 "incd x28, ALL, MUL #2\n"
167 "zip1 z17.b, z21.b, z20.b\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000168 "zip1 z16.b, z18.b, z16.b\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000169 "incd x27, ALL, MUL #2\n"
170 "incd x26, ALL, MUL #2\n"
171 "st1b { z17.b }, p1, [x22]\n"
172 "incd x23, ALL, MUL #2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100173 "incd x21, ALL, MUL #2\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000174 "st1b { z16.b }, p1, [x22, #1, MUL VL]\n"
175 "incd x20, ALL, MUL #2\n"
176 "add x22, x22, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100177 "bgt 4b\n"
178 "5:" // Main row loop: Column loop skip
Michael Tylerbe13cea2023-01-17 11:04:14 +0000179 "cmp %x[height], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000180 "addvl %x[out], %x[out], #2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100181 "bge 1b\n"
182 "cbz %x[height], 12f\n"
183 "6:" // Main loop skip
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100184 "7:" // Tail row loop: Head
Michael Tyler7d9a6262023-02-01 16:37:07 +0000185 "mov x10, %x[in]\n"
186 "add x9, x10, %x[in_stride]\n"
187 "add x28, x9, %x[in_stride]\n"
188 "mov x21, %x[width]\n"
189 "cntb x20, ALL, MUL #2\n"
190 "add x27, x28, %x[in_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100191 "cmp %x[height], #0x3\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000192 "add %x[in], x27, %x[in_stride]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000193 "csel x27, x27, %x[pad_row], GT\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000194 "csel x28, x28, %x[pad_row], GE\n"
195 "cmp %x[height], #0x1\n"
196 "csel x9, x9, %x[pad_row], GT\n"
197 "cmp x21, x20\n"
198 "mov x22, %x[out]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100199 "sub %x[height], %x[height], #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100200 "blt 9f\n"
201 "8:" // Tail row loop: Unroll column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000202 "ld1b { z21.b }, p1/Z, [x10]\n"
203 "ld1b { z18.b }, p1/Z, [x9]\n"
204 "sub x21, x21, x20\n"
205 "cmp x21, x20\n"
206 "ld1b { z17.b }, p1/Z, [x28]\n"
207 "ld1b { z16.b }, p1/Z, [x27]\n"
208 "zip1 z20.b, z21.b, z17.b\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000209 "zip1 z19.b, z18.b, z16.b\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000210 "ld1b { z24.b }, p1/Z, [x10, #1, MUL VL]\n"
211 "ld1b { z23.b }, p1/Z, [x9, #1, MUL VL]\n"
212 "zip2 z22.b, z21.b, z17.b\n"
213 "zip2 z21.b, z18.b, z16.b\n"
214 "ld1b { z18.b }, p1/Z, [x28, #1, MUL VL]\n"
215 "ld1b { z17.b }, p1/Z, [x27, #1, MUL VL]\n"
216 "zip1 z16.b, z20.b, z19.b\n"
217 "st1b { z16.b }, p1, [x22]\n"
218 "add x22, x22, %x[out_stride]\n"
219 "zip2 z16.b, z20.b, z19.b\n"
220 "st1b { z16.b }, p1, [x22]\n"
221 "add x22, x22, %x[out_stride]\n"
222 "zip1 z20.b, z24.b, z18.b\n"
223 "zip1 z19.b, z23.b, z17.b\n"
224 "addvl x10, x10, #2\n"
225 "addvl x9, x9, #2\n"
226 "zip1 z16.b, z22.b, z21.b\n"
227 "st1b { z16.b }, p1, [x22]\n"
228 "add x22, x22, %x[out_stride]\n"
229 "zip2 z16.b, z22.b, z21.b\n"
230 "st1b { z16.b }, p1, [x22]\n"
231 "add x22, x22, %x[out_stride]\n"
232 "zip2 z18.b, z24.b, z18.b\n"
233 "zip2 z17.b, z23.b, z17.b\n"
234 "zip1 z16.b, z20.b, z19.b\n"
235 "st1b { z16.b }, p1, [x22]\n"
236 "add x22, x22, %x[out_stride]\n"
237 "zip2 z16.b, z20.b, z19.b\n"
238 "st1b { z16.b }, p1, [x22]\n"
239 "add x22, x22, %x[out_stride]\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000240 "zip1 z16.b, z18.b, z17.b\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000241 "addvl x28, x28, #2\n"
242 "st1b { z16.b }, p1, [x22]\n"
243 "add x22, x22, %x[out_stride]\n"
244 "addvl x27, x27, #2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100245 "zip2 z16.b, z18.b, z17.b\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000246 "st1b { z16.b }, p1, [x22]\n"
247 "add x22, x22, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100248 "bge 8b\n"
249 "9:" // Tail row loop: Unroll column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000250 "cbz x21, 11f\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100251 "10:" // Tail row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000252 "whilelt p0.b, XZR, x21\n"
253 "ld1b { z19.b }, p0/Z, [x10]\n"
254 "ld1b { z18.b }, p0/Z, [x9]\n"
255 "decw x21\n"
256 "ld1b { z17.b }, p0/Z, [x28]\n"
257 "ld1b { z16.b }, p0/Z, [x27]\n"
258 "zip1 z17.b, z19.b, z17.b\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000259 "zip1 z16.b, z18.b, z16.b\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000260 "cmp x21, #0x0\n"
261 "incd x10, ALL, MUL #2\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +0000262 "zip1 z16.b, z17.b, z16.b\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000263 "st1b { z16.b }, p1, [x22]\n"
264 "incd x9, ALL, MUL #2\n"
265 "incd x28, ALL, MUL #2\n"
266 "incd x27, ALL, MUL #2\n"
267 "add x22, x22, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100268 "bgt 10b\n"
269 "11:" // Tail row loop: Column loop skip
Michael Tylerbe13cea2023-01-17 11:04:14 +0000270 "cmp %x[height], #0x1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000271 "addvl %x[out], %x[out], #1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100272 "bge 7b\n"
273 "12:" // Done
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100274 : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out)
275 : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [pad_row] "r" (pad_row), [width] "r" (width)
Michael Tyler7d9a6262023-02-01 16:37:07 +0000276 : "cc", "memory", "p0", "p1", "x9", "x10", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "z0", "z1", "z2", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100277 );
278}
279
280} // anonymous namespace
281
282template<>
283void Transform<1, 4, true, VLType::SVE>(
284 uint8_t *out, const uint8_t *in, int stride, int x0, int xmax, int k0, int kmax)
285{
286 sve_transpose_interleave_1VL_1x4(
287 reinterpret_cast<uint8_t *>(out),
288 reinterpret_cast<const uint8_t *>(in + k0 * stride + x0),
289 (xmax-x0) * sizeof(uint8_t) / 1,
290 stride * sizeof(uint8_t),
291 (kmax-k0)
292 );
293}
294
295template<>
296void Transform<1, 4, true, VLType::SVE>(
297 int8_t *out, const int8_t *in, int stride, int x0, int xmax, int k0, int kmax)
298{
299 sve_transpose_interleave_1VL_1x4(
300 reinterpret_cast<uint8_t *>(out),
301 reinterpret_cast<const uint8_t *>(in + k0 * stride + x0),
302 (xmax-x0) * sizeof(int8_t) / 1,
303 stride * sizeof(int8_t),
304 (kmax-k0)
305 );
306}
307
308#endif