blob: 767d468ad1767fd7f919272ed855ed130c6d85f7 [file] [log] [blame]
Georgios Pinitasc0b6f762020-11-02 01:37:17 +00001/*
Michael Tyler7d9a6262023-02-01 16:37:07 +00002 * Copyright (c) 2019-2021, 2023 Arm Limited.
Georgios Pinitasc0b6f762020-11-02 01:37:17 +00003 *
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 Pinitasc0b6f762020-11-02 01:37:17 +000015 *
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 Pinitasc0b6f762020-11-02 01:37:17 +000023 */
24
25#ifdef __aarch64__
26
27template<>
28void interleave_block<8, 1, VLType::None, false>(
29 int16_t * &out_ptr, const int16_t * const * in, size_t width, size_t height,
30 size_t row_offset, bool
31)
32{
33 __asm__ __volatile__(
Michael Tyler7d9a6262023-02-01 16:37:07 +000034 "ldr x28, [%x[in], #0x0]\n"
35 "ldr x27, [%x[in], #0x8]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000036 "cmp %x[height], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000037 "add x28, x28, %x[row_offset], LSL #1\n"
38 "ldr x26, [%x[in], #0x10]\n"
39 "ldr x25, [%x[in], #0x18]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000040 "add x27, x27, %x[row_offset], LSL #1\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000041 "add x26, x26, %x[row_offset], LSL #1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000042 "ldr x24, [%x[in], #0x20]\n"
43 "ldr x23, [%x[in], #0x28]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000044 "add x25, x25, %x[row_offset], LSL #1\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000045 "add x24, x24, %x[row_offset], LSL #1\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000046 "ldr x22, [%x[in], #0x30]\n"
47 "ldr x21, [%x[in], #0x38]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000048 "add x23, x23, %x[row_offset], LSL #1\n"
49 "add x22, x22, %x[row_offset], LSL #1\n"
50 "add x21, x21, %x[row_offset], LSL #1\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000051 "beq 1f\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000052 "cmp %x[height], #0x2\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000053 "csel x27, x27, x28, GE\n"
54 "csel x26, x26, x28, GT\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000055 "cmp %x[height], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000056 "csel x25, x25, x28, GE\n"
57 "csel x24, x24, x28, GT\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000058 "cmp %x[height], #0x6\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000059 "mov x21, x28\n"
60 "csel x23, x23, x28, GE\n"
61 "csel x22, x22, x28, GT\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000062 "1:" // no_pointer_adj
Michael Tylerbe13cea2023-01-17 11:04:14 +000063 "cmp %x[width], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000064 "prfm pldl1keep, [x28, #0x0]\n"
65 "prfm pldl1keep, [x27, #0x0]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000066 "prfm pldl1keep, [x26, #0x0]\n"
67 "prfm pldl1keep, [x25, #0x0]\n"
68 "prfm pldl1keep, [x24, #0x0]\n"
69 "prfm pldl1keep, [x23, #0x0]\n"
70 "prfm pldl1keep, [x22, #0x0]\n"
71 "prfm pldl1keep, [x21, #0x0]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000072 "prfm pldl1keep, [x28, #0x40]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000073 "prfm pldl1keep, [x27, #0x40]\n"
74 "prfm pldl1keep, [x26, #0x40]\n"
75 "prfm pldl1keep, [x25, #0x40]\n"
76 "prfm pldl1keep, [x24, #0x40]\n"
77 "prfm pldl1keep, [x23, #0x40]\n"
78 "prfm pldl1keep, [x22, #0x40]\n"
79 "prfm pldl1keep, [x21, #0x40]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000080 "blt 3f\n"
81 "2:" // Main loop head
Michael Tyler7d9a6262023-02-01 16:37:07 +000082 "ldr q25, [x28], #0x10\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000083 "ldr q30, [x27], #0x10\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000084 "subs %x[width], %x[width], #0x8\n"
Michael Tylerbe13cea2023-01-17 11:04:14 +000085 "cmp %x[width], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000086 "ldr q29, [x26], #0x10\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +000087 "ldr q28, [x25], #0x10\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +000088 "ldr q21, [x24], #0x10\n"
89 "ldr q27, [x23], #0x10\n"
90 "zip1 v23.8h, v25.8h, v21.8h\n"
91 "zip1 v26.8h, v30.8h, v27.8h\n"
92 "ldr q20, [x22], #0x10\n"
93 "ldr q22, [x21], #0x10\n"
94 "zip1 v19.8h, v29.8h, v20.8h\n"
95 "zip1 v18.8h, v28.8h, v22.8h\n"
96 "zip2 v25.8h, v25.8h, v21.8h\n"
97 "zip2 v21.8h, v29.8h, v20.8h\n"
98 "prfm pldl1keep, [x28, #0x70]\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +000099 "prfm pldl1keep, [x27, #0x70]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000100 "zip2 v20.8h, v30.8h, v27.8h\n"
101 "zip2 v16.8h, v28.8h, v22.8h\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000102 "prfm pldl1keep, [x26, #0x70]\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000103 "prfm pldl1keep, [x25, #0x70]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000104 "zip1 v24.8h, v23.8h, v19.8h\n"
105 "zip1 v17.8h, v26.8h, v18.8h\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000106 "prfm pldl1keep, [x24, #0x70]\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000107 "prfm pldl1keep, [x23, #0x70]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000108 "zip2 v23.8h, v23.8h, v19.8h\n"
109 "zip2 v19.8h, v26.8h, v18.8h\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000110 "prfm pldl1keep, [x22, #0x70]\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000111 "prfm pldl1keep, [x21, #0x70]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000112 "zip1 v22.8h, v25.8h, v21.8h\n"
113 "zip1 v18.8h, v20.8h, v16.8h\n"
114 "zip2 v21.8h, v25.8h, v21.8h\n"
115 "zip2 v20.8h, v20.8h, v16.8h\n"
116 "zip1 v16.8h, v24.8h, v17.8h\n"
117 "str q16, [%x[out_ptr], #0x0]\n"
118 "zip2 v16.8h, v24.8h, v17.8h\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000119 "str q16, [%x[out_ptr], #0x10]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000120 "zip1 v17.8h, v23.8h, v19.8h\n"
121 "zip2 v16.8h, v23.8h, v19.8h\n"
122 "str q17, [%x[out_ptr], #0x20]\n"
123 "zip1 v19.8h, v22.8h, v18.8h\n"
124 "zip2 v18.8h, v22.8h, v18.8h\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000125 "str q16, [%x[out_ptr], #0x30]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000126 "zip1 v17.8h, v21.8h, v20.8h\n"
127 "zip2 v16.8h, v21.8h, v20.8h\n"
128 "str q19, [%x[out_ptr], #0x40]\n"
129 "str q18, [%x[out_ptr], #0x50]\n"
130 "str q17, [%x[out_ptr], #0x60]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000131 "str q16, [%x[out_ptr], #0x70]\n"
132 "add %x[out_ptr], %x[out_ptr], #0x80\n"
133 "bge 2b\n"
134 "3:" // Main loop skip
135 "cbz %x[width], 8f\n"
136 "tbz %x[width], #2, 5f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000137 "ldr d25, [x28], #0x8\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000138 "ldr d30, [x27], #0x8\n"
139 "ldr d29, [x26], #0x8\n"
140 "ldr d28, [x25], #0x8\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000141 "ldr d21, [x24], #0x8\n"
142 "ldr d27, [x23], #0x8\n"
143 "ldr d20, [x22], #0x8\n"
144 "ldr d22, [x21], #0x8\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000145 "tbz %x[width], #1, 4f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000146 "ld1 { v25.s }[2], [x28], #0x4\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000147 "ld1 { v30.s }[2], [x27], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000148 "mov x20, #0x6\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000149 "ld1 { v29.s }[2], [x26], #0x4\n"
150 "ld1 { v28.s }[2], [x25], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000151 "ld1 { v21.s }[2], [x24], #0x4\n"
152 "ld1 { v27.s }[2], [x23], #0x4\n"
153 "ld1 { v20.s }[2], [x22], #0x4\n"
154 "ld1 { v22.s }[2], [x21], #0x4\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000155 "tbz %x[width], #0, 7f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000156 "ld1 { v25.h }[6], [x28]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000157 "ld1 { v30.h }[6], [x27]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000158 "mov x20, #0x7\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000159 "ld1 { v29.h }[6], [x26]\n"
160 "ld1 { v28.h }[6], [x25]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000161 "ld1 { v21.h }[6], [x24]\n"
162 "ld1 { v27.h }[6], [x23]\n"
163 "ld1 { v20.h }[6], [x22]\n"
164 "ld1 { v22.h }[6], [x21]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000165 "b 7f\n"
166 "4:" // odd_loads_1_4
Michael Tyler7d9a6262023-02-01 16:37:07 +0000167 "mov x20, #0x4\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000168 "tbz %x[width], #0, 7f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000169 "ld1 { v25.h }[4], [x28]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000170 "ld1 { v30.h }[4], [x27]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000171 "mov x20, #0x5\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000172 "ld1 { v29.h }[4], [x26]\n"
173 "ld1 { v28.h }[4], [x25]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000174 "ld1 { v21.h }[4], [x24]\n"
175 "ld1 { v27.h }[4], [x23]\n"
176 "ld1 { v20.h }[4], [x22]\n"
177 "ld1 { v22.h }[4], [x21]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000178 "b 7f\n"
179 "5:" // odd_loads_2_0
180 "tbz %x[width], #1, 6f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000181 "ldr s25, [x28], #0x4\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000182 "ldr s30, [x27], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000183 "mov x20, #0x2\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000184 "ldr s29, [x26], #0x4\n"
185 "ldr s28, [x25], #0x4\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000186 "ldr s21, [x24], #0x4\n"
187 "ldr s27, [x23], #0x4\n"
188 "ldr s20, [x22], #0x4\n"
189 "ldr s22, [x21], #0x4\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000190 "tbz %x[width], #0, 7f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000191 "ld1 { v25.h }[2], [x28]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000192 "ld1 { v30.h }[2], [x27]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000193 "mov x20, #0x3\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000194 "ld1 { v29.h }[2], [x26]\n"
195 "ld1 { v28.h }[2], [x25]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000196 "ld1 { v21.h }[2], [x24]\n"
197 "ld1 { v27.h }[2], [x23]\n"
198 "ld1 { v20.h }[2], [x22]\n"
199 "ld1 { v22.h }[2], [x21]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000200 "b 7f\n"
201 "6:" // odd_loads_1_0
Michael Tyler7d9a6262023-02-01 16:37:07 +0000202 "ldr h25, [x28, #0x0]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000203 "ldr h30, [x27, #0x0]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000204 "mov x20, #0x1\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000205 "ldr h29, [x26, #0x0]\n"
206 "ldr h28, [x25, #0x0]\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000207 "ldr h21, [x24, #0x0]\n"
208 "ldr h27, [x23, #0x0]\n"
209 "ldr h20, [x22, #0x0]\n"
210 "ldr h22, [x21, #0x0]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000211 "7:" // Odd load end
Michael Tyler7d9a6262023-02-01 16:37:07 +0000212 "zip1 v23.8h, v25.8h, v21.8h\n"
213 "zip1 v19.8h, v29.8h, v20.8h\n"
214 "subs x20, x20, #0x1\n"
215 "zip1 v26.8h, v30.8h, v27.8h\n"
216 "zip1 v18.8h, v28.8h, v22.8h\n"
217 "zip1 v24.8h, v23.8h, v19.8h\n"
218 "zip1 v17.8h, v26.8h, v18.8h\n"
219 "zip1 v16.8h, v24.8h, v17.8h\n"
220 "str q16, [%x[out_ptr], #0x0]\n"
221 "add %x[out_ptr], %x[out_ptr], #0x10\n"
222 "beq 8f\n"
223 "subs x20, x20, #0x1\n"
224 "zip2 v16.8h, v24.8h, v17.8h\n"
225 "str q16, [%x[out_ptr], #0x0]\n"
226 "add %x[out_ptr], %x[out_ptr], #0x10\n"
227 "beq 8f\n"
228 "zip2 v23.8h, v23.8h, v19.8h\n"
229 "zip2 v19.8h, v26.8h, v18.8h\n"
230 "subs x20, x20, #0x1\n"
231 "zip1 v17.8h, v23.8h, v19.8h\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000232 "str q17, [%x[out_ptr], #0x0]\n"
233 "add %x[out_ptr], %x[out_ptr], #0x10\n"
234 "beq 8f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000235 "subs x20, x20, #0x1\n"
236 "zip2 v16.8h, v23.8h, v19.8h\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000237 "str q16, [%x[out_ptr], #0x0]\n"
238 "add %x[out_ptr], %x[out_ptr], #0x10\n"
239 "beq 8f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000240 "zip2 v25.8h, v25.8h, v21.8h\n"
241 "zip2 v21.8h, v29.8h, v20.8h\n"
242 "subs x20, x20, #0x1\n"
243 "zip2 v20.8h, v30.8h, v27.8h\n"
244 "zip2 v16.8h, v28.8h, v22.8h\n"
245 "zip1 v22.8h, v25.8h, v21.8h\n"
246 "zip1 v18.8h, v20.8h, v16.8h\n"
247 "zip1 v19.8h, v22.8h, v18.8h\n"
248 "str q19, [%x[out_ptr], #0x0]\n"
Georgios Pinitase28cf392021-01-31 05:18:43 +0000249 "add %x[out_ptr], %x[out_ptr], #0x10\n"
250 "beq 8f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000251 "subs x20, x20, #0x1\n"
252 "zip2 v18.8h, v22.8h, v18.8h\n"
253 "str q18, [%x[out_ptr], #0x0]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000254 "add %x[out_ptr], %x[out_ptr], #0x10\n"
255 "beq 8f\n"
Michael Tyler7d9a6262023-02-01 16:37:07 +0000256 "zip2 v21.8h, v25.8h, v21.8h\n"
257 "zip2 v20.8h, v20.8h, v16.8h\n"
258 "zip1 v17.8h, v21.8h, v20.8h\n"
259 "str q17, [%x[out_ptr], #0x0]\n"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000260 "add %x[out_ptr], %x[out_ptr], #0x10\n"
261 "8:" // Odds skip
262
Georgios Pinitase28cf392021-01-31 05:18:43 +0000263 : [out_ptr] "+&r" (out_ptr), [width] "+&r" (width)
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000264 : [height] "r" (height), [in] "r" (in), [row_offset] "r" (row_offset)
Michael Tyler7d9a6262023-02-01 16:37:07 +0000265 : "cc", "memory", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28"
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000266 );
267}
268
269template<>
270void interleave_block<8, 1, VLType::None, false>(
271 uint16_t * &out_ptr, const uint16_t * const * in, size_t width, size_t height,
272 size_t row_offset, bool
273)
274{
275 int16_t * &out_cast = reinterpret_cast<int16_t * &>(out_ptr);
276 const int16_t * const * in_cast = reinterpret_cast<const int16_t * const *>(in);
277
278 interleave_block<8, 1, VLType::None, false>(out_cast, in_cast, width, height, row_offset, false);
279}
280
281
282#endif // __aarch64__