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_reuse_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_reuse_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 output_reset = tile_width * output_stride - round_down_po2(block_height, 2) * sizeof(uint16_t) - tile_hbytes;
35
36 const uint16_t* i0 = input;
37 uint16_t* o = (uint16_t*) ((uintptr_t) output - tile_hbytes);
38 const size_t minus_output_stride = -output_stride;
39
40 do {
41 const size_t rem = min(block_width - 1, 7);
42 const size_t oN_stride = rem * output_stride;
43 const size_t oN_offset = oN_stride + tile_hbytes;
44 size_t bh = block_height;
45 for (; bh >= 8; bh -= 8) {
46 const uint16x8_t v3_0 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
47 const uint16x8_t v3_1 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
48 const uint16x8_t v3_2 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
49 const uint16x8_t v3_3 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
50 const uint16x8_t v3_4 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
51 const uint16x8_t v3_5 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
52 const uint16x8_t v3_6 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
53 const uint16x8_t v3_7 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
54
55 const uint16x8x2_t v2_0 = vzipq_u16(v3_0, v3_4);
56 const uint16x8x2_t v2_1 = vzipq_u16(v3_1, v3_5);
57 const uint16x8x2_t v2_2 = vzipq_u16(v3_2, v3_6);
58 const uint16x8x2_t v2_3 = vzipq_u16(v3_3, v3_7);
59
60 const uint16x8x2_t v1_0 = vzipq_u16(v2_0.val[0], v2_2.val[0]);
61 const uint16x8x2_t v1_1 = vzipq_u16(v2_0.val[1], v2_2.val[1]);
62 const uint16x8x2_t v1_2 = vzipq_u16(v2_1.val[0], v2_3.val[0]);
63 const uint16x8x2_t v1_3 = vzipq_u16(v2_1.val[1], v2_3.val[1]);
64 const uint16x8x2_t v0_0 = vzipq_u16(v1_0.val[0], v1_2.val[0]);
65 const uint16x8x2_t v0_1 = vzipq_u16(v1_0.val[1], v1_2.val[1]);
66 const uint16x8x2_t v0_2 = vzipq_u16(v1_1.val[0], v1_3.val[0]);
67 const uint16x8x2_t v0_3 = vzipq_u16(v1_1.val[1], v1_3.val[1]);
68
69 o = (uint16_t*) ((uintptr_t) o + oN_offset);
70 vst1q_u16(o, v0_3.val[1]);
71 if XNN_UNPREDICTABLE(block_width > 7) {
72 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
73 }
74 vst1q_u16(o, v0_3.val[0]);
75 if XNN_UNPREDICTABLE(block_width >= 7) {
76 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
77 }
78 vst1q_u16(o, v0_2.val[1]);
79 if XNN_UNPREDICTABLE(block_width > 5) {
80 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
81 }
82 vst1q_u16(o, v0_2.val[0]);
83 if XNN_UNPREDICTABLE(block_width >= 5) {
84 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
85 }
86 vst1q_u16(o, v0_1.val[1]);
87 if XNN_UNPREDICTABLE(block_width > 3) {
88 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
89 }
90 vst1q_u16(o, v0_1.val[0]);
91 if XNN_UNPREDICTABLE(block_width >= 3) {
92 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
93 }
94 vst1q_u16(o, v0_0.val[1]);
95 if XNN_UNPREDICTABLE(block_width > 1) {
96 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
97 }
98 vst1q_u16(o, v0_0.val[0]);
99 }
100 o = (uint16_t*) ((uintptr_t) o + tile_hbytes);
101
102 if (bh != 0) {
103 const uint16x8_t v3_0 = vld1q_u16(i0);
104 const uint16_t *i1 = (const uint16_t*) ((uintptr_t) i0 + input_stride);
105 if XNN_UNPREDICTABLE(bh < 2) {
106 i1 = i0;
107 }
108 const uint16x8_t v3_1 = vld1q_u16(i1);
109 const uint16_t *i2 = (const uint16_t*) ((uintptr_t) i1 + input_stride);
110 if XNN_UNPREDICTABLE(bh <= 2) {
111 i2 = i1;
112 }
113 const uint16x8_t v3_2 = vld1q_u16(i2);
114 const uint16_t *i3 = (const uint16_t*) ((uintptr_t) i2 + input_stride);
115 if XNN_UNPREDICTABLE(bh < 4) {
116 i3 = i2;
117 }
118 const uint16x8_t v3_3 = vld1q_u16(i3);
119 const uint16_t *i4 = (const uint16_t*) ((uintptr_t) i3 + input_stride);
120 if XNN_UNPREDICTABLE(bh <= 4) {
121 i4 = i3;
122 }
123 const uint16x8_t v3_4 = vld1q_u16(i4);
124 const uint16_t *i5 = (const uint16_t*) ((uintptr_t) i4 + input_stride);
125 if XNN_UNPREDICTABLE(bh < 6) {
126 i5 = i4;
127 }
128 const uint16x8_t v3_5 = vld1q_u16(i5);
129 const uint16_t *i6 = (const uint16_t*) ((uintptr_t) i5 + input_stride);
130 if XNN_UNPREDICTABLE(bh <= 6) {
131 i6 = i5;
132 }
133 const uint16x8_t v3_6 = vld1q_u16(i6);
134 const uint16x8_t v3_7 = vmovq_n_u16(0);
135
136 const uint16x8x2_t v2_0 = vzipq_u16(v3_0, v3_4);
137 const uint16x8x2_t v2_1 = vzipq_u16(v3_1, v3_5);
138 const uint16x8x2_t v2_2 = vzipq_u16(v3_2, v3_6);
139 const uint16x8x2_t v2_3 = vzipq_u16(v3_3, v3_7);
140
141 const uint16x8x2_t v1_0 = vzipq_u16(v2_0.val[0], v2_2.val[0]);
142 const uint16x8x2_t v1_1 = vzipq_u16(v2_0.val[1], v2_2.val[1]);
143 const uint16x8x2_t v1_2 = vzipq_u16(v2_1.val[0], v2_3.val[0]);
144 const uint16x8x2_t v1_3 = vzipq_u16(v2_1.val[1], v2_3.val[1]);
145 const uint16x8x2_t v0_0 = vzipq_u16(v1_0.val[0], v1_2.val[0]);
146 const uint16x8x2_t v0_1 = vzipq_u16(v1_0.val[1], v1_2.val[1]);
147 const uint16x8x2_t v0_2 = vzipq_u16(v1_1.val[0], v1_3.val[0]);
148 const uint16x8x2_t v0_3 = vzipq_u16(v1_1.val[1], v1_3.val[1]);
149
150 uint16x4_t v0_low = vget_low_u16(v0_0.val[0]);
151 uint16x4_t v1_low = vget_low_u16(v0_0.val[1]);
152 uint16x4_t v2_low = vget_low_u16(v0_1.val[0]);
153 uint16x4_t v3_low = vget_low_u16(v0_1.val[1]);
154 uint16x4_t v4_low = vget_low_u16(v0_2.val[0]);
155 uint16x4_t v5_low = vget_low_u16(v0_2.val[1]);
156 uint16x4_t v6_low = vget_low_u16(v0_3.val[0]);
157 uint16x4_t v7_low = vget_low_u16(v0_3.val[1]);
158
159 if (bh & 4) {
160 o = (uint16_t*) ((uintptr_t) o + oN_stride);
161 vst1_u16(o, v7_low);
162 if XNN_UNPREDICTABLE(block_width > 7) {
163 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
164 }
165 vst1_u16(o, v6_low);
166 if XNN_UNPREDICTABLE(block_width >= 7) {
167 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
168 }
169 vst1_u16(o, v5_low);
170 if XNN_UNPREDICTABLE(block_width > 5) {
171 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
172 }
173 vst1_u16(o, v4_low);
174 if XNN_UNPREDICTABLE(block_width >= 5) {
175 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
176 }
177 vst1_u16(o, v3_low);
178 if XNN_UNPREDICTABLE(block_width > 3) {
179 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
180 }
181 vst1_u16(o, v2_low);
182 if XNN_UNPREDICTABLE(block_width >= 3) {
183 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
184 }
185 vst1_u16(o, v1_low);
186 if XNN_UNPREDICTABLE(block_width > 1) {
187 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
188 }
189 vst1_u16(o, v0_low); o += 4;
190 v0_low = vget_high_u16(v0_0.val[0]);
191 v1_low = vget_high_u16(v0_0.val[1]);
192 v2_low = vget_high_u16(v0_1.val[0]);
193 v3_low = vget_high_u16(v0_1.val[1]);
194 v4_low = vget_high_u16(v0_2.val[0]);
195 v5_low = vget_high_u16(v0_2.val[1]);
196 v6_low = vget_high_u16(v0_3.val[0]);
197 v7_low = vget_high_u16(v0_3.val[1]);
198 }
199
200 if (bh & 2) {
201 o = (uint16_t*) ((uintptr_t) o + oN_stride);
202 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v7_low), 0);
203 if XNN_UNPREDICTABLE(block_width > 7) {
204 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
205 }
206 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v6_low), 0);
207 if XNN_UNPREDICTABLE(block_width >= 7) {
208 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
209 }
210 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v5_low), 0);
211 if XNN_UNPREDICTABLE(block_width > 5) {
212 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
213 }
214 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v4_low), 0);
215 if XNN_UNPREDICTABLE(block_width >= 5) {
216 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
217 }
218 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v3_low), 0);
219 if XNN_UNPREDICTABLE(block_width > 3) {
220 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
221 }
222 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v2_low), 0);
223 if XNN_UNPREDICTABLE(block_width >= 3) {
224 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
225 }
226 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v1_low), 0);
227 if XNN_UNPREDICTABLE(block_width > 1) {
228 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
229 }
230 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v0_low), 0); o += 2;
231 v0_low = vext_u16(v0_low, v0_low, 2);
232 v1_low = vext_u16(v1_low, v1_low, 2);
233 v2_low = vext_u16(v2_low, v2_low, 2);
234 v3_low = vext_u16(v3_low, v3_low, 2);
235 v4_low = vext_u16(v4_low, v4_low, 2);
236 v5_low = vext_u16(v5_low, v5_low, 2);
237 v6_low = vext_u16(v6_low, v6_low, 2);
238 v7_low = vext_u16(v7_low, v7_low, 2);
239 }
240 if (bh & 1) {
241 o = (uint16_t*) ((uintptr_t) o + oN_stride);
242 vst1_lane_u16(o, v7_low, 0);
243 if XNN_UNPREDICTABLE(block_width > 7) {
244 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
245 }
246 vst1_lane_u16(o, v6_low, 0);
247 if XNN_UNPREDICTABLE(block_width >= 7) {
248 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
249 }
250 vst1_lane_u16(o, v5_low, 0);
251 if XNN_UNPREDICTABLE(block_width > 5) {
252 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
253 }
254 vst1_lane_u16(o, v4_low, 0);
255 if XNN_UNPREDICTABLE(block_width >= 5) {
256 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
257 }
258 vst1_lane_u16(o, v3_low, 0);
259 if XNN_UNPREDICTABLE(block_width > 3) {
260 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
261 }
262 vst1_lane_u16(o, v2_low, 0);
263 if XNN_UNPREDICTABLE(block_width >= 3) {
264 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
265 }
266 vst1_lane_u16(o, v1_low, 0);
267 if XNN_UNPREDICTABLE(block_width > 1) {
268 o = (uint16_t*) ((uintptr_t) o + minus_output_stride);
269 }
270 vst1_lane_u16(o, v0_low, 0);
271 }
272 }
273
274 i0 = (const uint16_t*) ((uintptr_t) i0 + input_reset);
275 o = (uint16_t*) ((uintptr_t) o + output_reset);
276 block_width = doz(block_width, tile_width);
277 } while (block_width != 0);
278 }
279