Debian Codegraph @

src/x32-transposec/gen/x32-transposec-4x4-reuse-switch-zip-neon.c

raw symbols SCIP
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
18 void xnn_x32_transposec_ukernel__4x4_reuse_switch_zip_neon(
19 const uint32_t* input,
20 uint32_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(block_width == 1 || output_stride >= block_height * sizeof(uint32_t));
27 assert(block_height == 1 || input_stride >= block_width * sizeof(uint32_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(uint32_t);
32 const size_t tile_wbytes = tile_width * sizeof(uint32_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(uint32_t);
35
36 const uint32_t* i0 = input;
37 uint32_t* o = (uint32_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 uint32x4_t v2_0 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
46 const uint32x4_t v2_1 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
47 const uint32x4_t v2_2 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
48 const uint32x4_t v2_3 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
49
50 const uint32x4x2_t v1_0 = vzipq_u32(v2_0, v2_2);
51 const uint32x4x2_t v1_1 = vzipq_u32(v2_1, v2_3);
52
53 const uint32x4x2_t v0_0 = vzipq_u32(v1_0.val[0], v1_1.val[0]);
54 const uint32x4x2_t v0_1 = vzipq_u32(v1_0.val[1], v1_1.val[1]);
55
56 uint32_t *oN = (uint32_t*) ((uintptr_t) o + oN_stride);
57 switch (rem) {
58 case 3:
59 vst1q_u32(oN, v0_1.val[1]); oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
60 XNN_FALLTHROUGH
61 case 2:
62 vst1q_u32(oN, v0_1.val[0]); oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
63 XNN_FALLTHROUGH
64 case 1:
65 vst1q_u32(oN, v0_0.val[1]);
66 XNN_FALLTHROUGH
67 case 0:
68 vst1q_u32(o, v0_0.val[0]); o = (uint32_t*) ((uintptr_t) o + tile_hbytes);
69 break;
70 default:
71 XNN_UNREACHABLE;
72 }
73 }
74
75 if (bh != 0) {
76 const uint32x4_t v2_0 = vld1q_u32(i0);
77 const uint32_t *i1 = (const uint32_t*) ((uintptr_t) i0 + input_stride);
78 if XNN_UNPREDICTABLE(bh < 2) {
79 i1 = i0;
80 }
81 const uint32x4_t v2_1 = vld1q_u32(i1);
82 const uint32_t *i2 = (const uint32_t*) ((uintptr_t) i1 + input_stride);
83 if XNN_UNPREDICTABLE(bh <= 2) {
84 i2 = i1;
85 }
86 const uint32x4_t v2_2 = vld1q_u32(i2);
87 const uint32x4_t v2_3 = vmovq_n_u32(0);
88
89 const uint32x4x2_t v1_0 = vzipq_u32(v2_0, v2_2);
90 const uint32x4x2_t v1_1 = vzipq_u32(v2_1, v2_3);
91
92 const uint32x4x2_t v0_0 = vzipq_u32(v1_0.val[0], v1_1.val[0]);
93 const uint32x4x2_t v0_1 = vzipq_u32(v1_0.val[1], v1_1.val[1]);
94
95 uint32x2_t v0_low = vget_low_u32(v0_0.val[0]);
96 uint32x2_t v1_low = vget_low_u32(v0_0.val[1]);
97 uint32x2_t v2_low = vget_low_u32(v0_1.val[0]);
98 uint32x2_t v3_low = vget_low_u32(v0_1.val[1]);
99
100 if (bh & 2) {
101 uint32_t* oN = (uint32_t*) ((uintptr_t) o + oN_stride);
102 switch (rem) {
103 case 3:
104 vst1_u32(oN, v3_low); oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
105 XNN_FALLTHROUGH
106 case 2:
107 vst1_u32(oN, v2_low); oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
108 XNN_FALLTHROUGH
109 case 1:
110 vst1_u32(oN, v1_low);
111 XNN_FALLTHROUGH
112 case 0:
113 vst1_u32(o, v0_low); o += 2;
114 break;
115 default:
116 XNN_UNREACHABLE;
117 }
118 v0_low = vget_high_u32(v0_0.val[0]);
119 v1_low = vget_high_u32(v0_0.val[1]);
120 v2_low = vget_high_u32(v0_1.val[0]);
121 v3_low = vget_high_u32(v0_1.val[1]);
122 }
123
124 if (bh & 1) {
125 uint32_t* oN = (uint32_t*) ((uintptr_t) o + oN_stride);
126 switch (rem) {
127 case 3:
128 vst1_lane_u32(oN, v3_low, 0); oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
129 XNN_FALLTHROUGH
130 case 2:
131 vst1_lane_u32(oN, v2_low, 0); oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
132 XNN_FALLTHROUGH
133 case 1:
134 vst1_lane_u32(oN, v1_low, 0);
135 XNN_FALLTHROUGH
136 case 0:
137 vst1_lane_u32(o, v0_low, 0);
138 break;
139 default:
140 XNN_UNREACHABLE;
141 }
142 }
143 }
144
145 i0 = (const uint32_t*) ((uintptr_t) i0 + input_reset);
146 o = (uint32_t*) ((uintptr_t) o + output_reset);
147 block_width = doz(block_width, tile_width);
148 } while (block_width != 0);
149 }