blob: 20f9d39f4eb3bc7348d9861969763dc9b397edd4 [file] [log] [blame]
Georgios Pinitas4ee8b152021-07-16 16:16:43 +01001/*
Michael Tylerba209752022-12-15 12:39:29 +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 Tylerba209752022-12-15 12:39:29 +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 Tylerba209752022-12-15 12:39:29 +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 __aarch64__
28
29namespace {
30
31void a64_transpose_interleave_24(uint16_t *out, const uint16_t *in, size_t width, size_t in_stride, size_t height)
32{
33 size_t out_stride = 12 * height * sizeof(uint16_t);
34
35 __asm__ __volatile__(
36 "cmp %x[height], #0x4\n"
37 "blt 10f\n"
38 "1:" // Main row loop: Head
Michael Tylerba209752022-12-15 12:39:29 +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 Tylerba209752022-12-15 12:39:29 +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 Tylerba209752022-12-15 12:39:29 +000050 "ldr q1, [x25], #0x10\n"
51 "ldr q0, [x22], #0x10\n"
52 "sub x24, x24, #0x18\n"
53 "cmp x24, #0x18\n"
54 "ldr q17, [x25], #0x10\n"
55 "ldr q31, [x23], #0x10\n"
56 "dup v30.2d, v17.d[0]\n"
57 "dup v29.2d, v31.d[1]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010058 "ldr q16, [x22], #0x10\n"
Michael Tylerba209752022-12-15 12:39:29 +000059 "ldr q28, [x20], #0x10\n"
60 "dup v27.2d, v16.d[0]\n"
61 "dup v26.2d, v28.d[1]\n"
62 "ldr q25, [x25], #0x10\n"
63 "ldr q24, [x22], #0x10\n"
64 "dup v23.2d, v17.d[1]\n"
65 "dup v22.2d, v25.d[1]\n"
66 "ldr q21, [x23], #0x10\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010067 "ldr q20, [x20], #0x10\n"
Michael Tylerba209752022-12-15 12:39:29 +000068 "dup v19.2d, v16.d[1]\n"
69 "dup v18.2d, v24.d[1]\n"
70 "ldr q17, [x23], #0x10\n"
71 "ldr q16, [x20], #0x10\n"
72 "mov v30.d[1], v31.d[0]\n"
73 "mov v29.d[1], v21.d[0]\n"
74 "mov v27.d[1], v28.d[0]\n"
75 "mov v26.d[1], v20.d[0]\n"
76 "str q1, [x21, #0x0]\n"
77 "str q30, [x21, #0x10]\n"
78 "mov v23.d[1], v25.d[0]\n"
79 "mov v22.d[1], v21.d[1]\n"
80 "str q29, [x21, #0x20]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010081 "mov v19.d[1], v24.d[0]\n"
Michael Tylerba209752022-12-15 12:39:29 +000082 "mov v18.d[1], v20.d[1]\n"
83 "str q0, [x21, #0x30]\n"
84 "str q27, [x21, #0x40]\n"
85 "str q26, [x21, #0x50]\n"
86 "add x21, x21, %x[out_stride]\n"
87 "str q23, [x21, #0x0]\n"
88 "str q22, [x21, #0x10]\n"
89 "str q17, [x21, #0x20]\n"
90 "str q19, [x21, #0x30]\n"
91 "str q18, [x21, #0x40]\n"
92 "str q16, [x21, #0x50]\n"
93 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010094 "bge 2b\n"
95 "3:" // Main row loop: Unroll column loop skip
Michael Tylerba209752022-12-15 12:39:29 +000096 "cmp x24, #0xc\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +010097 "blt 5f\n"
98 "4:" // Main row loop: Column loop
Michael Tylerba209752022-12-15 12:39:29 +000099 "ldr q17, [x23], #0x10\n"
100 "ldr q23, [x20], #0x10\n"
101 "dup v22.2d, v17.d[1]\n"
102 "dup v21.2d, v23.d[1]\n"
103 "ldr q20, [x25], #0x10\n"
104 "ldr q19, [x22], #0x10\n"
105 "sub x24, x24, #0xc\n"
106 "cmp x24, #0xc\n"
107 "ldr d18, [x25], #0x8\n"
108 "ldr d16, [x23], #0x8\n"
109 "mov v18.d[1], v17.d[0]\n"
110 "mov v22.d[1], v16.d[0]\n"
111 "ldr d17, [x22], #0x8\n"
112 "ldr d16, [x20], #0x8\n"
113 "mov v17.d[1], v23.d[0]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100114 "mov v21.d[1], v16.d[0]\n"
Michael Tylerba209752022-12-15 12:39:29 +0000115 "str q20, [x21, #0x0]\n"
116 "str q18, [x21, #0x10]\n"
117 "str q22, [x21, #0x20]\n"
118 "str q19, [x21, #0x30]\n"
119 "str q17, [x21, #0x40]\n"
120 "str q21, [x21, #0x50]\n"
121 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100122 "bge 4b\n"
123 "5:" // Main row loop: Column loop skip
Michael Tylerba209752022-12-15 12:39:29 +0000124 "cmp x24, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100125 "blt 7f\n"
126 "6:" // Main row loop: width 4 loop: loop
Michael Tylerba209752022-12-15 12:39:29 +0000127 "ldr d19, [x25], #0x8\n"
128 "ldr d18, [x23], #0x8\n"
129 "sub x24, x24, #0x4\n"
130 "cmp x24, #0x4\n"
131 "ldr d17, [x22], #0x8\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100132 "ldr d16, [x20], #0x8\n"
Michael Tylerba209752022-12-15 12:39:29 +0000133 "str d19, [x21, #0x0]\n"
134 "str d18, [x21, #0x18]\n"
135 "str d17, [x21, #0x30]\n"
136 "str d16, [x21, #0x48]\n"
137 "add x21, x21, #0x8\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100138 "bge 6b\n"
139 "7:" // Main row loop: width 4 loop: skip
Michael Tylerba209752022-12-15 12:39:29 +0000140 "cmp x24, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100141 "blt 9f\n"
142 "8:" // Main row loop: width 1 loop: loop
Michael Tylerba209752022-12-15 12:39:29 +0000143 "ldr h19, [x25], #0x2\n"
144 "ldr h18, [x23], #0x2\n"
145 "sub x24, x24, #0x1\n"
146 "cmp x24, #0x1\n"
147 "ldr h17, [x22], #0x2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100148 "ldr h16, [x20], #0x2\n"
Michael Tylerba209752022-12-15 12:39:29 +0000149 "str h19, [x21, #0x0]\n"
150 "str h18, [x21, #0x18]\n"
151 "str h17, [x21, #0x30]\n"
152 "str h16, [x21, #0x48]\n"
153 "add x21, x21, #0x2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100154 "bge 8b\n"
155 "9:" // Main row loop: width 1 loop: skip
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100156 "cmp %x[height], #0x4\n"
Michael Tylerba209752022-12-15 12:39:29 +0000157 "add %x[out], %x[out], #0x60\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100158 "bge 1b\n"
159 "cbz %x[height], 20f\n"
160 "10:" // Main loop skip
161
162 "11:" // Tail row loop: Head
Michael Tylerba209752022-12-15 12:39:29 +0000163 "mov x20, %x[width]\n"
164 "mov x25, %x[in]\n"
165 "cmp x20, #0x18\n"
166 "add %x[in], x25, %x[in_stride]\n"
167 "mov x21, %x[out]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100168 "sub %x[height], %x[height], #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100169 "blt 13f\n"
170 "12:" // Tail row loop: Unroll column loop
Michael Tylerba209752022-12-15 12:39:29 +0000171 "ldr q19, [x25], #0x10\n"
172 "ldr q16, [x25], #0x10\n"
173 "dup v18.2d, v16.d[1]\n"
174 "sub x20, x20, #0x18\n"
175 "ldr q17, [x25], #0x10\n"
176 "dup v16.2d, v16.d[0]\n"
177 "str q19, [x21, #0x0]\n"
178 "cmp x20, #0x18\n"
179 "str d16, [x21, #0x10]\n"
180 "add x21, x21, %x[out_stride]\n"
181 "mov v18.d[1], v17.d[0]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100182 "dup v16.2d, v17.d[1]\n"
Michael Tylerba209752022-12-15 12:39:29 +0000183 "str q18, [x21, #0x0]\n"
184 "str d16, [x21, #0x10]\n"
185 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100186 "bge 12b\n"
187 "13:" // Tail row loop: Unroll column loop skip
Michael Tylerba209752022-12-15 12:39:29 +0000188 "cmp x20, #0xc\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100189 "blt 15f\n"
190 "14:" // Tail row loop: Column loop
Michael Tylerba209752022-12-15 12:39:29 +0000191 "ldr q17, [x25], #0x10\n"
192 "ldr d16, [x25], #0x8\n"
193 "sub x20, x20, #0xc\n"
194 "cmp x20, #0xc\n"
195 "str q17, [x21, #0x0]\n"
196 "str d16, [x21, #0x10]\n"
197 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100198 "bge 14b\n"
199 "15:" // Tail row loop: Column loop skip
Michael Tylerba209752022-12-15 12:39:29 +0000200 "cmp x20, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100201 "blt 17f\n"
202 "16:" // Tail row loop: width 4 loop: loop
Michael Tylerba209752022-12-15 12:39:29 +0000203 "ldr d16, [x25], #0x8\n"
204 "sub x20, x20, #0x4\n"
205 "cmp x20, #0x4\n"
206 "str d16, [x21, #0x0]\n"
207 "add x21, x21, #0x8\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100208 "bge 16b\n"
209 "17:" // Tail row loop: width 4 loop: skip
Michael Tylerba209752022-12-15 12:39:29 +0000210 "cmp x20, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100211 "blt 19f\n"
212 "18:" // Tail row loop: width 1 loop: loop
Michael Tylerba209752022-12-15 12:39:29 +0000213 "ldr h16, [x25], #0x2\n"
214 "sub x20, x20, #0x1\n"
215 "cmp x20, #0x1\n"
216 "str h16, [x21, #0x0]\n"
217 "add x21, x21, #0x2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100218 "bge 18b\n"
219 "19:" // Tail row loop: width 1 loop: skip
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100220 "cmp %x[height], #0x1\n"
Michael Tylerba209752022-12-15 12:39:29 +0000221 "add %x[out], %x[out], #0x18\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100222 "bge 11b\n"
223 "20:" // Done
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100224 : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out)
225 : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [width] "r" (width)
Michael Tylerba209752022-12-15 12:39:29 +0000226 : "cc", "memory", "v0", "v1", "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 +0100227 );
228}
229
230} // anonymous namespace
231
232template<>
233void Transform<6, 1, true, VLType::None>(
234 float *out, const float *in, int stride, int x0, int xmax, int k0, int kmax)
235{
236 a64_transpose_interleave_24(
237 reinterpret_cast<uint16_t *>(out),
238 reinterpret_cast<const uint16_t *>(in + k0 * stride + x0),
239 (xmax-x0) * sizeof(float) / 2,
240 stride * sizeof(float),
241 (kmax-k0)
242 );
243}
244
245template<>
246void Transform<12, 1, true, VLType::None>(
247 int16_t *out, const int16_t *in, int stride, int x0, int xmax, int k0, int kmax)
248{
249 a64_transpose_interleave_24(
250 reinterpret_cast<uint16_t *>(out),
251 reinterpret_cast<const uint16_t *>(in + k0 * stride + x0),
252 (xmax-x0) * sizeof(int16_t) / 2,
253 stride * sizeof(int16_t),
254 (kmax-k0)
255 );
256}
257
258template<>
259void Transform<12, 1, true, VLType::None>(
260 uint16_t *out, const uint16_t *in, int stride, int x0, int xmax, int k0, int kmax)
261{
262 a64_transpose_interleave_24(
263 reinterpret_cast<uint16_t *>(out),
264 reinterpret_cast<const uint16_t *>(in + k0 * stride + x0),
265 (xmax-x0) * sizeof(uint16_t) / 2,
266 stride * sizeof(uint16_t),
267 (kmax-k0)
268 );
269}
270
271#endif