blob: 4c66fb2c2fb54f7b96c996a3c9222187206ba3e3 [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 __aarch64__
28
29namespace {
30
31void a64_transpose_interleave_12_u8u16(uint16_t *out, const uint8_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 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 q3, [x25], #0x10\n"
51 "ldr q21, [x23], #0x10\n"
52 "ushll2 v20.8h, v3.16b, #0x0\n"
53 "ushll v2.8h, v21.8b, #0x0\n"
54 "ldr q1, [x22], #0x10\n"
55 "ldr q19, [x20], #0x10\n"
56 "ushll2 v18.8h, v1.16b, #0x0\n"
57 "ushll v0.8h, v19.8b, #0x0\n"
58 "ldr d17, [x25], #0x8\n"
59 "ldr d16, [x22], #0x8\n"
60 "ushll v31.8h, v17.8b, #0x0\n"
61 "ushll v30.8h, v16.8b, #0x0\n"
62 "ldr d29, [x23], #0x8\n"
63 "ldr d28, [x20], #0x8\n"
64 "ushll2 v27.8h, v21.16b, #0x0\n"
65 "ushll2 v26.8h, v19.16b, #0x0\n"
66 "dup v25.2d, v20.d[0]\n"
67 "dup v24.2d, v2.d[1]\n"
68 "sub x24, x24, #0x18\n"
69 "cmp x24, #0x18\n"
70 "dup v23.2d, v18.d[0]\n"
71 "dup v22.2d, v0.d[1]\n"
72 "dup v21.2d, v20.d[1]\n"
73 "dup v20.2d, v31.d[1]\n"
74 "dup v19.2d, v18.d[1]\n"
75 "dup v18.2d, v30.d[1]\n"
76 "ushll v17.8h, v3.8b, #0x0\n"
77 "ushll v16.8h, v1.8b, #0x0\n"
78 "str q17, [x21, #0x0]\n"
79 "mov v25.d[1], v2.d[0]\n"
80 "mov v24.d[1], v27.d[0]\n"
81 "str q25, [x21, #0x10]\n"
82 "mov v23.d[1], v0.d[0]\n"
83 "mov v22.d[1], v26.d[0]\n"
84 "str q24, [x21, #0x20]\n"
85 "str q16, [x21, #0x30]\n"
86 "ushll v17.8h, v29.8b, #0x0\n"
87 "ushll v16.8h, v28.8b, #0x0\n"
88 "str q23, [x21, #0x40]\n"
89 "mov v21.d[1], v31.d[0]\n"
90 "mov v20.d[1], v27.d[1]\n"
91 "str q22, [x21, #0x50]\n"
92 "add x21, x21, %x[out_stride]\n"
93 "mov v19.d[1], v30.d[0]\n"
94 "mov v18.d[1], v26.d[1]\n"
95 "str q21, [x21, #0x0]\n"
96 "str q20, [x21, #0x10]\n"
97 "str q17, [x21, #0x20]\n"
98 "str q19, [x21, #0x30]\n"
99 "str q18, [x21, #0x40]\n"
100 "str q16, [x21, #0x50]\n"
101 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100102 "bge 2b\n"
103 "3:" // Main row loop: Unroll column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000104 "cmp x24, #0xc\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100105 "blt 5f\n"
106 "4:" // Main row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000107 "ldr d19, [x23], #0x8\n"
108 "ldr d18, [x20], #0x8\n"
109 "sub x24, x24, #0xc\n"
110 "cmp x24, #0xc\n"
111 "ld1 { v19.s }[2], [x23], #0x4\n"
112 "ld1 { v18.s }[2], [x20], #0x4\n"
113 "ushll v25.8h, v19.8b, #0x0\n"
114 "ushll v24.8h, v18.8b, #0x0\n"
115 "ldr d17, [x25], #0x8\n"
116 "ldr d16, [x22], #0x8\n"
117 "ushll2 v23.8h, v19.16b, #0x0\n"
118 "ushll2 v22.8h, v18.16b, #0x0\n"
119 "ld1 { v17.s }[2], [x25], #0x4\n"
120 "ld1 { v16.s }[2], [x22], #0x4\n"
121 "ushll2 v21.8h, v17.16b, #0x0\n"
122 "ushll2 v20.8h, v16.16b, #0x0\n"
123 "dup v19.2d, v25.d[1]\n"
124 "dup v18.2d, v24.d[1]\n"
125 "ushll v17.8h, v17.8b, #0x0\n"
126 "ushll v16.8h, v16.8b, #0x0\n"
127 "str q17, [x21, #0x0]\n"
128 "mov v21.d[1], v25.d[0]\n"
129 "mov v19.d[1], v23.d[0]\n"
130 "str q21, [x21, #0x10]\n"
131 "mov v20.d[1], v24.d[0]\n"
132 "mov v18.d[1], v22.d[0]\n"
133 "str q19, [x21, #0x20]\n"
134 "str q16, [x21, #0x30]\n"
135 "str q20, [x21, #0x40]\n"
136 "str q18, [x21, #0x50]\n"
137 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100138 "bge 4b\n"
139 "5:" // Main row loop: Column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000140 "cmp x24, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100141 "blt 7f\n"
142 "6:" // Main row loop: width 4 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000143 "ldr s19, [x25], #0x4\n"
144 "ldr s18, [x23], #0x4\n"
145 "sub x24, x24, #0x4\n"
146 "cmp x24, #0x4\n"
147 "ldr s17, [x22], #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100148 "ldr s16, [x20], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000149 "ushll v19.8h, v19.8b, #0x0\n"
150 "ushll v18.8h, v18.8b, #0x0\n"
151 "ushll v17.8h, v17.8b, #0x0\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100152 "ushll v16.8h, v16.8b, #0x0\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000153 "str d19, [x21, #0x0]\n"
154 "str d18, [x21, #0x18]\n"
155 "str d17, [x21, #0x30]\n"
156 "str d16, [x21, #0x48]\n"
157 "add x21, x21, #0x8\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100158 "bge 6b\n"
159 "7:" // Main row loop: width 4 loop: skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000160 "cmp x24, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100161 "blt 9f\n"
162 "8:" // Main row loop: width 1 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000163 "ldr b19, [x25], #0x1\n"
164 "ldr b18, [x23], #0x1\n"
165 "sub x24, x24, #0x1\n"
166 "cmp x24, #0x1\n"
167 "ldr b17, [x22], #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100168 "ldr b16, [x20], #0x1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000169 "ushll v19.8h, v19.8b, #0x0\n"
170 "ushll v18.8h, v18.8b, #0x0\n"
171 "ushll v17.8h, v17.8b, #0x0\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100172 "ushll v16.8h, v16.8b, #0x0\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000173 "str h19, [x21, #0x0]\n"
174 "str h18, [x21, #0x18]\n"
175 "str h17, [x21, #0x30]\n"
176 "str h16, [x21, #0x48]\n"
177 "add x21, x21, #0x2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100178 "bge 8b\n"
179 "9:" // Main row loop: width 1 loop: skip
Michael Tylerbe13cea2023-01-17 11:04:14 +0000180 "cmp %x[height], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000181 "add %x[out], %x[out], #0x60\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100182 "bge 1b\n"
183 "cbz %x[height], 20f\n"
184 "10:" // Main loop skip
185
186 "11:" // Tail row loop: Head
Michael Tyler7d9a6262023-02-01 16:37:07 +0000187 "mov x20, %x[width]\n"
188 "mov x25, %x[in]\n"
189 "cmp x20, #0x18\n"
190 "add %x[in], x25, %x[in_stride]\n"
191 "mov x21, %x[out]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100192 "sub %x[height], %x[height], #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100193 "blt 13f\n"
194 "12:" // Tail row loop: Unroll column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000195 "ldr q20, [x25], #0x10\n"
196 "ldr d16, [x25], #0x8\n"
197 "ushll2 v19.8h, v20.16b, #0x0\n"
198 "ushll v18.8h, v16.8b, #0x0\n"
199 "dup v17.2d, v19.d[1]\n"
200 "sub x20, x20, #0x18\n"
201 "ushll v16.8h, v20.8b, #0x0\n"
202 "str q16, [x21, #0x0]\n"
203 "dup v16.2d, v19.d[0]\n"
204 "str d16, [x21, #0x10]\n"
205 "add x21, x21, %x[out_stride]\n"
206 "cmp x20, #0x18\n"
207 "mov v17.d[1], v18.d[0]\n"
208 "dup v16.2d, v18.d[1]\n"
209 "str q17, [x21, #0x0]\n"
210 "str d16, [x21, #0x10]\n"
211 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100212 "bge 12b\n"
213 "13:" // Tail row loop: Unroll column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000214 "cmp x20, #0xc\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100215 "blt 15f\n"
216 "14:" // Tail row loop: Column loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000217 "ldr d16, [x25], #0x8\n"
218 "ld1 { v16.s }[2], [x25], #0x4\n"
219 "sub x20, x20, #0xc\n"
220 "cmp x20, #0xc\n"
221 "ushll v17.8h, v16.8b, #0x0\n"
222 "ushll2 v16.8h, v16.16b, #0x0\n"
223 "str q17, [x21, #0x0]\n"
224 "str d16, [x21, #0x10]\n"
225 "add x21, x21, %x[out_stride]\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100226 "bge 14b\n"
227 "15:" // Tail row loop: Column loop skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000228 "cmp x20, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100229 "blt 17f\n"
230 "16:" // Tail row loop: width 4 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000231 "ldr s16, [x25], #0x4\n"
232 "sub x20, x20, #0x4\n"
233 "cmp x20, #0x4\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100234 "ushll v16.8h, v16.8b, #0x0\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000235 "str d16, [x21, #0x0]\n"
236 "add x21, x21, #0x8\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100237 "bge 16b\n"
238 "17:" // Tail row loop: width 4 loop: skip
Michael Tyler7d9a6262023-02-01 16:37:07 +0000239 "cmp x20, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100240 "blt 19f\n"
241 "18:" // Tail row loop: width 1 loop: loop
Michael Tyler7d9a6262023-02-01 16:37:07 +0000242 "ldr b16, [x25], #0x1\n"
243 "sub x20, x20, #0x1\n"
244 "cmp x20, #0x1\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100245 "ushll v16.8h, v16.8b, #0x0\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000246 "str h16, [x21, #0x0]\n"
247 "add x21, x21, #0x2\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100248 "bge 18b\n"
249 "19:" // Tail row loop: width 1 loop: skip
Michael Tylerbe13cea2023-01-17 11:04:14 +0000250 "cmp %x[height], #0x1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000251 "add %x[out], %x[out], #0x18\n"
Georgios Pinitas4ee8b152021-07-16 16:16:43 +0100252 "bge 11b\n"
253 "20:" // Done
254
255 : [height] "+&r" (height), [in] "+&r" (in), [out] "+&r" (out)
256 : [in_stride] "r" (in_stride), [out_stride] "r" (out_stride), [width] "r" (width)
Michael Tyler7d9a6262023-02-01 16:37:07 +0000257 : "cc", "memory", "v0", "v1", "v2", "v3", "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 +0100258 );
259}
260
261} // anonymous namespace
262template<>
263void Transform<12, 1, true, VLType::None>(
264 uint16_t *out, const uint8_t *in, int stride, int x0, int xmax, int k0, int kmax)
265{
266 a64_transpose_interleave_12_u8u16(
267 out,
268 in + k0 * stride + x0,
269 (xmax-x0),
270 stride * sizeof(uint8_t),
271 (kmax-k0)
272 );
273}
274
275#endif