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_multi_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_multi_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);
35
36 const uint16_t* i0 = input;
37 uint16_t* o0 = (uint16_t*) output;
38 uint16_t* o1 = (uint16_t*) ((uintptr_t) o0 + output_stride);
39 uint16_t* o2 = (uint16_t*) ((uintptr_t) o1 + output_stride);
40 uint16_t* o3 = (uint16_t*) ((uintptr_t) o2 + output_stride);
41 uint16_t* o4 = (uint16_t*) ((uintptr_t) o3 + output_stride);
42 uint16_t* o5 = (uint16_t*) ((uintptr_t) o4 + output_stride);
43 uint16_t* o6 = (uint16_t*) ((uintptr_t) o5 + output_stride);
44 uint16_t* o7 = (uint16_t*) ((uintptr_t) o6 + output_stride);
45
46 do {
47 if XNN_UNPREDICTABLE(block_width < 2) {
48 o1 = o0;
49 }
50 if XNN_UNPREDICTABLE(block_width <= 2) {
51 o2 = o0;
52 }
53 if XNN_UNPREDICTABLE(block_width < 4) {
54 o3 = o0;
55 }
56 if XNN_UNPREDICTABLE(block_width <= 4) {
57 o4 = o0;
58 }
59 if XNN_UNPREDICTABLE(block_width < 6) {
60 o5 = o0;
61 }
62 if XNN_UNPREDICTABLE(block_width <= 6) {
63 o6 = o0;
64 }
65 if XNN_UNPREDICTABLE(block_width < 8) {
66 o7 = o0;
67 }
68 size_t bh = block_height;
69 for (; bh >= 8; bh -= 8) {
70 const uint16x8_t v3_0 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
71 const uint16x8_t v3_1 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
72 const uint16x8_t v3_2 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
73 const uint16x8_t v3_3 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
74 const uint16x8_t v3_4 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
75 const uint16x8_t v3_5 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
76 const uint16x8_t v3_6 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
77 const uint16x8_t v3_7 = vld1q_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
78
79 const uint16x8x2_t v2_0 = vzipq_u16(v3_0, v3_4);
80 const uint16x8x2_t v2_1 = vzipq_u16(v3_1, v3_5);
81 const uint16x8x2_t v2_2 = vzipq_u16(v3_2, v3_6);
82 const uint16x8x2_t v2_3 = vzipq_u16(v3_3, v3_7);
83
84 const uint16x8x2_t v1_0 = vzipq_u16(v2_0.val[0], v2_2.val[0]);
85 const uint16x8x2_t v1_1 = vzipq_u16(v2_0.val[1], v2_2.val[1]);
86 const uint16x8x2_t v1_2 = vzipq_u16(v2_1.val[0], v2_3.val[0]);
87 const uint16x8x2_t v1_3 = vzipq_u16(v2_1.val[1], v2_3.val[1]);
88 const uint16x8x2_t v0_0 = vzipq_u16(v1_0.val[0], v1_2.val[0]);
89 const uint16x8x2_t v0_1 = vzipq_u16(v1_0.val[1], v1_2.val[1]);
90 const uint16x8x2_t v0_2 = vzipq_u16(v1_1.val[0], v1_3.val[0]);
91 const uint16x8x2_t v0_3 = vzipq_u16(v1_1.val[1], v1_3.val[1]);
92
93 vst1q_u16(o7, v0_3.val[1]); o7 = (uint16_t*) ((uintptr_t) o7 + tile_hbytes);
94 vst1q_u16(o6, v0_3.val[0]); o6 = (uint16_t*) ((uintptr_t) o6 + tile_hbytes);
95 vst1q_u16(o5, v0_2.val[1]); o5 = (uint16_t*) ((uintptr_t) o5 + tile_hbytes);
96 vst1q_u16(o4, v0_2.val[0]); o4 = (uint16_t*) ((uintptr_t) o4 + tile_hbytes);
97 vst1q_u16(o3, v0_1.val[1]); o3 = (uint16_t*) ((uintptr_t) o3 + tile_hbytes);
98 vst1q_u16(o2, v0_1.val[0]); o2 = (uint16_t*) ((uintptr_t) o2 + tile_hbytes);
99 vst1q_u16(o1, v0_0.val[1]); o1 = (uint16_t*) ((uintptr_t) o1 + tile_hbytes);
100 vst1q_u16(o0, v0_0.val[0]); o0 = (uint16_t*) ((uintptr_t) o0 + tile_hbytes);
101 }
102
103 if (bh != 0) {
104 const uint16x8_t v3_0 = vld1q_u16(i0);
105 const uint16_t *i1 = (const uint16_t*) ((uintptr_t) i0 + input_stride);
106 if XNN_UNPREDICTABLE(bh < 2) {
107 i1 = i0;
108 }
109 const uint16x8_t v3_1 = vld1q_u16(i1);
110 const uint16_t *i2 = (const uint16_t*) ((uintptr_t) i1 + input_stride);
111 if XNN_UNPREDICTABLE(bh <= 2) {
112 i2 = i1;
113 }
114 const uint16x8_t v3_2 = vld1q_u16(i2);
115 const uint16_t *i3 = (const uint16_t*) ((uintptr_t) i2 + input_stride);
116 if XNN_UNPREDICTABLE(bh < 4) {
117 i3 = i2;
118 }
119 const uint16x8_t v3_3 = vld1q_u16(i3);
120 const uint16_t *i4 = (const uint16_t*) ((uintptr_t) i3 + input_stride);
121 if XNN_UNPREDICTABLE(bh <= 4) {
122 i4 = i3;
123 }
124 const uint16x8_t v3_4 = vld1q_u16(i4);
125 const uint16_t *i5 = (const uint16_t*) ((uintptr_t) i4 + input_stride);
126 if XNN_UNPREDICTABLE(bh < 6) {
127 i5 = i4;
128 }
129 const uint16x8_t v3_5 = vld1q_u16(i5);
130 const uint16_t *i6 = (const uint16_t*) ((uintptr_t) i5 + input_stride);
131 if XNN_UNPREDICTABLE(bh <= 6) {
132 i6 = i5;
133 }
134 const uint16x8_t v3_6 = vld1q_u16(i6);
135 const uint16x8_t v3_7 = vmovq_n_u16(0);
136
137 const uint16x8x2_t v2_0 = vzipq_u16(v3_0, v3_4);
138 const uint16x8x2_t v2_1 = vzipq_u16(v3_1, v3_5);
139 const uint16x8x2_t v2_2 = vzipq_u16(v3_2, v3_6);
140 const uint16x8x2_t v2_3 = vzipq_u16(v3_3, v3_7);
141
142 const uint16x8x2_t v1_0 = vzipq_u16(v2_0.val[0], v2_2.val[0]);
143 const uint16x8x2_t v1_1 = vzipq_u16(v2_0.val[1], v2_2.val[1]);
144 const uint16x8x2_t v1_2 = vzipq_u16(v2_1.val[0], v2_3.val[0]);
145 const uint16x8x2_t v1_3 = vzipq_u16(v2_1.val[1], v2_3.val[1]);
146 const uint16x8x2_t v0_0 = vzipq_u16(v1_0.val[0], v1_2.val[0]);
147 const uint16x8x2_t v0_1 = vzipq_u16(v1_0.val[1], v1_2.val[1]);
148 const uint16x8x2_t v0_2 = vzipq_u16(v1_1.val[0], v1_3.val[0]);
149 const uint16x8x2_t v0_3 = vzipq_u16(v1_1.val[1], v1_3.val[1]);
150
151 uint16x4_t v0_low = vget_low_u16(v0_0.val[0]);
152 uint16x4_t v1_low = vget_low_u16(v0_0.val[1]);
153 uint16x4_t v2_low = vget_low_u16(v0_1.val[0]);
154 uint16x4_t v3_low = vget_low_u16(v0_1.val[1]);
155 uint16x4_t v4_low = vget_low_u16(v0_2.val[0]);
156 uint16x4_t v5_low = vget_low_u16(v0_2.val[1]);
157 uint16x4_t v6_low = vget_low_u16(v0_3.val[0]);
158 uint16x4_t v7_low = vget_low_u16(v0_3.val[1]);
159
160 if (bh & 4) {
161 vst1_u16(o7, v7_low); o7 += 4;
162 vst1_u16(o6, v6_low); o6 += 4;
163 vst1_u16(o5, v5_low); o5 += 4;
164 vst1_u16(o4, v4_low); o4 += 4;
165 vst1_u16(o3, v3_low); o3 += 4;
166 vst1_u16(o2, v2_low); o2 += 4;
167 vst1_u16(o1, v1_low); o1 += 4;
168 vst1_u16(o0, v0_low); o0 += 4;
169 v0_low = vget_high_u16(v0_0.val[0]);
170 v1_low = vget_high_u16(v0_0.val[1]);
171 v2_low = vget_high_u16(v0_1.val[0]);
172 v3_low = vget_high_u16(v0_1.val[1]);
173 v4_low = vget_high_u16(v0_2.val[0]);
174 v5_low = vget_high_u16(v0_2.val[1]);
175 v6_low = vget_high_u16(v0_3.val[0]);
176 v7_low = vget_high_u16(v0_3.val[1]);
177 }
178
179 if (bh & 2) {
180 vst1_lane_u32((void*) o7, vreinterpret_u32_u16(v7_low), 0); o7 += 2;
181 vst1_lane_u32((void*) o6, vreinterpret_u32_u16(v6_low), 0); o6 += 2;
182 vst1_lane_u32((void*) o5, vreinterpret_u32_u16(v5_low), 0); o5 += 2;
183 vst1_lane_u32((void*) o4, vreinterpret_u32_u16(v4_low), 0); o4 += 2;
184 vst1_lane_u32((void*) o3, vreinterpret_u32_u16(v3_low), 0); o3 += 2;
185 vst1_lane_u32((void*) o2, vreinterpret_u32_u16(v2_low), 0); o2 += 2;
186 vst1_lane_u32((void*) o1, vreinterpret_u32_u16(v1_low), 0); o1 += 2;
187 vst1_lane_u32((void*) o0, vreinterpret_u32_u16(v0_low), 0); o0 += 2;
188 v0_low = vext_u16(v0_low, v0_low, 2);
189 v1_low = vext_u16(v1_low, v1_low, 2);
190 v2_low = vext_u16(v2_low, v2_low, 2);
191 v3_low = vext_u16(v3_low, v3_low, 2);
192 v4_low = vext_u16(v4_low, v4_low, 2);
193 v5_low = vext_u16(v5_low, v5_low, 2);
194 v6_low = vext_u16(v6_low, v6_low, 2);
195 v7_low = vext_u16(v7_low, v7_low, 2);
196 }
197 if (bh & 1) {
198 vst1_lane_u16(o7, v7_low, 0);
199 vst1_lane_u16(o6, v6_low, 0);
200 vst1_lane_u16(o5, v5_low, 0);
201 vst1_lane_u16(o4, v4_low, 0);
202 vst1_lane_u16(o3, v3_low, 0);
203 vst1_lane_u16(o2, v2_low, 0);
204 vst1_lane_u16(o1, v1_low, 0);
205 vst1_lane_u16(o0, v0_low, 0);
206 }
207 }
208
209 i0 = (const uint16_t*) ((uintptr_t) i0 + input_reset);
210 o0 = (uint16_t*) ((uintptr_t) o0 + output_reset);
211 o1 = (uint16_t*) ((uintptr_t) o1 + output_reset);
212 o2 = (uint16_t*) ((uintptr_t) o2 + output_reset);
213 o3 = (uint16_t*) ((uintptr_t) o3 + output_reset);
214 o4 = (uint16_t*) ((uintptr_t) o4 + output_reset);
215 o5 = (uint16_t*) ((uintptr_t) o5 + output_reset);
216 o6 = (uint16_t*) ((uintptr_t) o6 + output_reset);
217 o7 = (uint16_t*) ((uintptr_t) o7 + output_reset);
218 block_width = doz(block_width, tile_width);
219 } while (block_width != 0);
220 }
221