1 // Auto-generated file. Do not edit!
2 // Template: src/x32-transposec/neon-zip.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9
10 #include <arm_neon.h>
11
12 #include <assert.h>
13
14 #include <xnnpack/common.h>
15 #include <xnnpack/math.h>
16 #include <xnnpack/transpose.h>
17
xnn_x16_transposec_ukernel__8x8_multi_dec_zip_neon(const uint16_t * input,uint16_t * output,size_t input_stride,size_t output_stride,size_t block_width,size_t block_height)18 void xnn_x16_transposec_ukernel__8x8_multi_dec_zip_neon(
19 const uint16_t* input,
20 uint16_t* output,
21 size_t input_stride,
22 size_t output_stride,
23 size_t block_width,
24 size_t block_height) XNN_OOB_READS
25 {
26 assert(output_stride >= block_height * sizeof(uint16_t));
27 assert(input_stride >= block_width * sizeof(uint16_t));
28
29 const size_t tile_height = 8;
30 const size_t tile_width = 8;
31 const size_t tile_hbytes = tile_height * sizeof(uint16_t);
32 const size_t tile_wbytes = tile_width * sizeof(uint16_t);
33 const size_t input_reset = tile_wbytes - round_down_po2(block_height, tile_height) * input_stride;
34 const size_t input_offset = tile_height * input_stride;
35 const size_t output_reset = tile_width * output_stride - round_down_po2(block_height, 2) * sizeof(uint16_t) - tile_hbytes;
36
37 const uint16_t* i0 = input;
38 const uint16_t* i1 = (const uint16_t*) ((uintptr_t) i0 + input_stride);
39 const uint16_t* i2 = (const uint16_t*) ((uintptr_t) i1 + input_stride);
40 const uint16_t* i3 = (const uint16_t*) ((uintptr_t) i2 + input_stride);
41 const uint16_t* i4 = (const uint16_t*) ((uintptr_t) i3 + input_stride);
42 const uint16_t* i5 = (const uint16_t*) ((uintptr_t) i4 + input_stride);
43 const uint16_t* i6 = (const uint16_t*) ((uintptr_t) i5 + input_stride);
44 const uint16_t* i7 = (const uint16_t*) ((uintptr_t) i6 + input_stride);
45 uint16_t* o = (uint16_t*) ((uintptr_t) output - tile_hbytes);
46 const size_t minus_output_stride = -output_stride;
47
48 do {
49 const size_t rem = min(block_width - 1, 7);
50 const size_t oN_stride = rem * output_stride;
51 const size_t oN_offset = oN_stride + tile_hbytes;
52 size_t bh = block_height;
53 for (; bh >= 8; bh -= 8) {
54 const uint16x8_t v3_0 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_offset);
55 const uint16x8_t v3_1 = vld1q_u16(i1); i1 = (uint16_t*) ((uintptr_t) i1 + input_offset);
56 const uint16x8_t v3_2 = vld1q_u16(i2); i2 = (uint16_t*) ((uintptr_t) i2 + input_offset);
57 const uint16x8_t v3_3 = vld1q_u16(i3); i3 = (uint16_t*) ((uintptr_t) i3 + input_offset);
58 const uint16x8_t v3_4 = vld1q_u16(i4); i4 = (uint16_t*) ((uintptr_t) i4 + input_offset);
59 const uint16x8_t v3_5 = vld1q_u16(i5); i5 = (uint16_t*) ((uintptr_t) i5 + input_offset);
60 const uint16x8_t v3_6 = vld1q_u16(i6); i6 = (uint16_t*) ((uintptr_t) i6 + input_offset);
61 const uint16x8_t v3_7 = vld1q_u16(i7); i7 = (uint16_t*) ((uintptr_t) i7 + input_offset);
62
63 const uint16x8x2_t v2_0 = vzipq_u16(v3_0, v3_4);
64 const uint16x8x2_t v2_1 = vzipq_u16(v3_1, v3_5);
65 const uint16x8x2_t v2_2 = vzipq_u16(v3_2, v3_6);
66 const uint16x8x2_t v2_3 = vzipq_u16(v3_3, v3_7);
67
68 const uint16x8x2_t v1_0 = vzipq_u16(v2_0.val[0], v2_2.val[0]);
69 const uint16x8x2_t v1_1 = vzipq_u16(v2_0.val[1], v2_2.val[1]);
70 const uint16x8x2_t v1_2 = vzipq_u16(v2_1.val[0], v2_3.val[0]);
71 const uint16x8x2_t v1_3 = vzipq_u16(v2_1.val[1], v2_3.val[1]);
72 const uint16x8x2_t v0_0 = vzipq_u16(v1_0.val[0], v1_2.val[0]);
73 const uint16x8x2_t v0_1 = vzipq_u16(v1_0.val[1], v1_2.val[1]);
74 const uint16x8x2_t v0_2 = vzipq_u16(v1_1.val[0], v1_3.val[0]);
75 const uint16x8x2_t v0_3 = vzipq_u16(v1_1.val[1], v1_3.val[1]);
76
77 o = (uint16_t*) ((uintptr_t) o + oN_offset);
78 vst1q_u16(o, v0_3.val[1]);
79 if XNN_UNPREDICTABLE(block_width > 7) {
80 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
81 }
82 vst1q_u16(o, v0_3.val[0]);
83 if XNN_UNPREDICTABLE(block_width >= 7) {
84 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
85 }
86 vst1q_u16(o, v0_2.val[1]);
87 if XNN_UNPREDICTABLE(block_width > 5) {
88 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
89 }
90 vst1q_u16(o, v0_2.val[0]);
91 if XNN_UNPREDICTABLE(block_width >= 5) {
92 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
93 }
94 vst1q_u16(o, v0_1.val[1]);
95 if XNN_UNPREDICTABLE(block_width > 3) {
96 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
97 }
98 vst1q_u16(o, v0_1.val[0]);
99 if XNN_UNPREDICTABLE(block_width >= 3) {
100 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
101 }
102 vst1q_u16(o, v0_0.val[1]);
103 if XNN_UNPREDICTABLE(block_width > 1) {
104 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
105 }
106 vst1q_u16(o, v0_0.val[0]);
107 }
108 o = (uint16_t*) ((uintptr_t) o + tile_hbytes);
109
110 if (bh != 0) {
111 const uint16x8_t v3_0 = vld1q_u16(i0);
112 if XNN_UNPREDICTABLE(bh < 2) {
113 i1 = i0;
114 }
115 const uint16x8_t v3_1 = vld1q_u16(i1);
116 if XNN_UNPREDICTABLE(bh <= 2) {
117 i2 = i0;
118 }
119 const uint16x8_t v3_2 = vld1q_u16(i2);
120 if XNN_UNPREDICTABLE(bh < 4) {
121 i3 = i0;
122 }
123 const uint16x8_t v3_3 = vld1q_u16(i3);
124 if XNN_UNPREDICTABLE(bh <= 4) {
125 i4 = i0;
126 }
127 const uint16x8_t v3_4 = vld1q_u16(i4);
128 if XNN_UNPREDICTABLE(bh < 6) {
129 i5 = i0;
130 }
131 const uint16x8_t v3_5 = vld1q_u16(i5);
132 if XNN_UNPREDICTABLE(bh <= 6) {
133 i6 = i0;
134 }
135 const uint16x8_t v3_6 = vld1q_u16(i6);
136 const uint16x8_t v3_7 = vmovq_n_u16(0);
137
138 const uint16x8x2_t v2_0 = vzipq_u16(v3_0, v3_4);
139 const uint16x8x2_t v2_1 = vzipq_u16(v3_1, v3_5);
140 const uint16x8x2_t v2_2 = vzipq_u16(v3_2, v3_6);
141 const uint16x8x2_t v2_3 = vzipq_u16(v3_3, v3_7);
142
143 const uint16x8x2_t v1_0 = vzipq_u16(v2_0.val[0], v2_2.val[0]);
144 const uint16x8x2_t v1_1 = vzipq_u16(v2_0.val[1], v2_2.val[1]);
145 const uint16x8x2_t v1_2 = vzipq_u16(v2_1.val[0], v2_3.val[0]);
146 const uint16x8x2_t v1_3 = vzipq_u16(v2_1.val[1], v2_3.val[1]);
147 const uint16x8x2_t v0_0 = vzipq_u16(v1_0.val[0], v1_2.val[0]);
148 const uint16x8x2_t v0_1 = vzipq_u16(v1_0.val[1], v1_2.val[1]);
149 const uint16x8x2_t v0_2 = vzipq_u16(v1_1.val[0], v1_3.val[0]);
150 const uint16x8x2_t v0_3 = vzipq_u16(v1_1.val[1], v1_3.val[1]);
151
152 uint16x4_t v0_low = vget_low_u16(v0_0.val[0]);
153 uint16x4_t v1_low = vget_low_u16(v0_0.val[1]);
154 uint16x4_t v2_low = vget_low_u16(v0_1.val[0]);
155 uint16x4_t v3_low = vget_low_u16(v0_1.val[1]);
156 uint16x4_t v4_low = vget_low_u16(v0_2.val[0]);
157 uint16x4_t v5_low = vget_low_u16(v0_2.val[1]);
158 uint16x4_t v6_low = vget_low_u16(v0_3.val[0]);
159 uint16x4_t v7_low = vget_low_u16(v0_3.val[1]);
160
161 if (bh & 4) {
162 o = (uint16_t*) ((uintptr_t) o + oN_stride);
163 vst1_u16(o, v7_low);
164 if XNN_UNPREDICTABLE(block_width > 7) {
165 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
166 }
167 vst1_u16(o, v6_low);
168 if XNN_UNPREDICTABLE(block_width >= 7) {
169 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
170 }
171 vst1_u16(o, v5_low);
172 if XNN_UNPREDICTABLE(block_width > 5) {
173 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
174 }
175 vst1_u16(o, v4_low);
176 if XNN_UNPREDICTABLE(block_width >= 5) {
177 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
178 }
179 vst1_u16(o, v3_low);
180 if XNN_UNPREDICTABLE(block_width > 3) {
181 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
182 }
183 vst1_u16(o, v2_low);
184 if XNN_UNPREDICTABLE(block_width >= 3) {
185 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
186 }
187 vst1_u16(o, v1_low);
188 if XNN_UNPREDICTABLE(block_width > 1) {
189 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
190 }
191 vst1_u16(o, v0_low); o += 4;
192 v0_low = vget_high_u16(v0_0.val[0]);
193 v1_low = vget_high_u16(v0_0.val[1]);
194 v2_low = vget_high_u16(v0_1.val[0]);
195 v3_low = vget_high_u16(v0_1.val[1]);
196 v4_low = vget_high_u16(v0_2.val[0]);
197 v5_low = vget_high_u16(v0_2.val[1]);
198 v6_low = vget_high_u16(v0_3.val[0]);
199 v7_low = vget_high_u16(v0_3.val[1]);
200 }
201
202 if (bh & 2) {
203 o = (uint16_t*) ((uintptr_t) o + oN_stride);
204 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v7_low), 0);
205 if XNN_UNPREDICTABLE(block_width > 7) {
206 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
207 }
208 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v6_low), 0);
209 if XNN_UNPREDICTABLE(block_width >= 7) {
210 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
211 }
212 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v5_low), 0);
213 if XNN_UNPREDICTABLE(block_width > 5) {
214 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
215 }
216 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v4_low), 0);
217 if XNN_UNPREDICTABLE(block_width >= 5) {
218 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
219 }
220 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v3_low), 0);
221 if XNN_UNPREDICTABLE(block_width > 3) {
222 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
223 }
224 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v2_low), 0);
225 if XNN_UNPREDICTABLE(block_width >= 3) {
226 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
227 }
228 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v1_low), 0);
229 if XNN_UNPREDICTABLE(block_width > 1) {
230 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
231 }
232 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v0_low), 0); o += 2;
233 v0_low = vext_u16(v0_low, v0_low, 2);
234 v1_low = vext_u16(v1_low, v1_low, 2);
235 v2_low = vext_u16(v2_low, v2_low, 2);
236 v3_low = vext_u16(v3_low, v3_low, 2);
237 v4_low = vext_u16(v4_low, v4_low, 2);
238 v5_low = vext_u16(v5_low, v5_low, 2);
239 v6_low = vext_u16(v6_low, v6_low, 2);
240 v7_low = vext_u16(v7_low, v7_low, 2);
241 }
242 if (bh & 1) {
243 o = (uint16_t*) ((uintptr_t) o + oN_stride);
244 vst1_lane_u16(o, v7_low, 0);
245 if XNN_UNPREDICTABLE(block_width > 7) {
246 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
247 }
248 vst1_lane_u16(o, v6_low, 0);
249 if XNN_UNPREDICTABLE(block_width >= 7) {
250 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
251 }
252 vst1_lane_u16(o, v5_low, 0);
253 if XNN_UNPREDICTABLE(block_width > 5) {
254 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
255 }
256 vst1_lane_u16(o, v4_low, 0);
257 if XNN_UNPREDICTABLE(block_width >= 5) {
258 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
259 }
260 vst1_lane_u16(o, v3_low, 0);
261 if XNN_UNPREDICTABLE(block_width > 3) {
262 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
263 }
264 vst1_lane_u16(o, v2_low, 0);
265 if XNN_UNPREDICTABLE(block_width >= 3) {
266 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
267 }
268 vst1_lane_u16(o, v1_low, 0);
269 if XNN_UNPREDICTABLE(block_width > 1) {
270 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
271 }
272 vst1_lane_u16(o, v0_low, 0);
273 }
274 }
275
276 i0 = (const uint16_t*) ((uintptr_t) i0 + input_reset);
277 i1 = (const uint16_t*) ((uintptr_t) i0 + input_stride);
278 i2 = (const uint16_t*) ((uintptr_t) i1 + input_stride);
279 i3 = (const uint16_t*) ((uintptr_t) i2 + input_stride);
280 i4 = (const uint16_t*) ((uintptr_t) i3 + input_stride);
281 i5 = (const uint16_t*) ((uintptr_t) i4 + input_stride);
282 i6 = (const uint16_t*) ((uintptr_t) i5 + input_stride);
283 i7 = (const uint16_t*) ((uintptr_t) i6 + input_stride);
284 o = (uint16_t*) ((uintptr_t) o + output_reset);
285 block_width = doz(block_width, tile_width);
286 } while (block_width != 0);
287 }
288