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__4x4_reuse_switch_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__4x4_reuse_switch_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 = 4;
30 const size_t tile_width = 4;
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* o = (uint16_t*) output;
38 const size_t minus_output_stride = -output_stride;
39
40 do {
41 const size_t rem = min(block_width - 1, 3);
42 const size_t oN_stride = rem * output_stride;
43 size_t bh = block_height;
44 for (; bh >= 4; bh -= 4) {
45 const uint16x4_t v2_0 = vld1_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
46 const uint16x4_t v2_1 = vld1_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
47 const uint16x4_t v2_2 = vld1_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
48 const uint16x4_t v2_3 = vld1_u16(i0); i0 = (uint16_t*) ((uintptr_t) i0 + input_stride);
49
50 const uint16x4x2_t v1_0 = vzip_u16(v2_0, v2_2);
51 const uint16x4x2_t v1_1 = vzip_u16(v2_1, v2_3);
52
53 const uint16x4x2_t v0_0 = vzip_u16(v1_0.val[0], v1_1.val[0]);
54 const uint16x4x2_t v0_1 = vzip_u16(v1_0.val[1], v1_1.val[1]);
55
56 uint16_t *oN = (uint16_t*) ((uintptr_t) o + oN_stride);
57 switch (rem) {
58 case 3:
59 vst1_u16(oN, v0_1.val[1]); oN = (uint16_t*) ((uintptr_t) oN + minus_output_stride);
60 case 2:
61 vst1_u16(oN, v0_1.val[0]); oN = (uint16_t*) ((uintptr_t) oN + minus_output_stride);
62 case 1:
63 vst1_u16(oN, v0_0.val[1]);
64 case 0:
65 vst1_u16(o, v0_0.val[0]); o = (uint16_t*) ((uintptr_t) o + tile_hbytes);
66 break;
67 default:
68 XNN_UNREACHABLE;
69 }
70 }
71
72 if (bh != 0) {
73 const uint16x4_t v2_0 = vld1_u16(i0);
74 const uint16_t *i1 = (const uint16_t*) ((uintptr_t) i0 + input_stride);
75 if XNN_UNPREDICTABLE(bh < 2) {
76 i1 = i0;
77 }
78 const uint16x4_t v2_1 = vld1_u16(i1);
79 const uint16_t *i2 = (const uint16_t*) ((uintptr_t) i1 + input_stride);
80 if XNN_UNPREDICTABLE(bh <= 2) {
81 i2 = i1;
82 }
83 const uint16x4_t v2_2 = vld1_u16(i2);
84 const uint16x4_t v2_3 = vmov_n_u16(0);
85
86 const uint16x4x2_t v1_0 = vzip_u16(v2_0, v2_2);
87 const uint16x4x2_t v1_1 = vzip_u16(v2_1, v2_3);
88
89 const uint16x4x2_t v0_0 = vzip_u16(v1_0.val[0], v1_1.val[0]);
90 const uint16x4x2_t v0_1 = vzip_u16(v1_0.val[1], v1_1.val[1]);
91
92 uint16x4_t v0_low = v0_0.val[0];
93 uint16x4_t v1_low = v0_0.val[1];
94 uint16x4_t v2_low = v0_1.val[0];
95 uint16x4_t v3_low = v0_1.val[1];
96
97 if (bh & 2) {
98 uint16_t* oN = (uint16_t*) ((uintptr_t) o + oN_stride);
99 switch (rem) {
100 case 3:
101 vst1_lane_u32((void*) oN, vreinterpret_u32_u16(v3_low), 0); oN = (uint16_t*) ((uintptr_t) oN + minus_output_stride);
102 case 2:
103 vst1_lane_u32((void*) oN, vreinterpret_u32_u16(v2_low), 0); oN = (uint16_t*) ((uintptr_t) oN + minus_output_stride);
104 case 1:
105 vst1_lane_u32((void*) oN, vreinterpret_u32_u16(v1_low), 0);
106 case 0:
107 vst1_lane_u32((void*) o, vreinterpret_u32_u16(v0_low), 0); o += 2;
108 break;
109 default:
110 XNN_UNREACHABLE;
111 }
112 v0_low = vext_u16(v0_low, v0_low, 2);
113 v1_low = vext_u16(v1_low, v1_low, 2);
114 v2_low = vext_u16(v2_low, v2_low, 2);
115 v3_low = vext_u16(v3_low, v3_low, 2);
116 }
117 if (bh & 1) {
118 uint16_t* oN = (uint16_t*) ((uintptr_t) o + oN_stride);
119 switch (rem) {
120 case 3:
121 vst1_lane_u16(oN, v3_low, 0); oN = (uint16_t*) ((uintptr_t) oN + minus_output_stride);
122 case 2:
123 vst1_lane_u16(oN, v2_low, 0); oN = (uint16_t*) ((uintptr_t) oN + minus_output_stride);
124 case 1:
125 vst1_lane_u16(oN, v1_low, 0);
126 case 0:
127 vst1_lane_u16(o, v0_low, 0);
128 break;
129 default:
130 XNN_UNREACHABLE;
131 }
132 }
133 }
134
135 i0 = (const uint16_t*) ((uintptr_t) i0 + input_reset);
136 o = (uint16_t*) ((uintptr_t) o + output_reset);
137 block_width = doz(block_width, tile_width);
138 } while (block_width != 0);
139 }
140