xref: /aosp_15_r20/external/XNNPACK/src/x32-transposec/gen/4x4-multi-dec-zip-neon.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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_x32_transposec_ukernel__4x4_multi_dec_zip_neon(const uint32_t * input,uint32_t * output,size_t input_stride,size_t output_stride,size_t block_width,size_t block_height)18 void xnn_x32_transposec_ukernel__4x4_multi_dec_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(output_stride >= block_height * sizeof(uint32_t));
27   assert(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 input_offset = tile_height * input_stride;
35   const size_t output_reset = tile_width * output_stride - round_down_po2(block_height, 2) * sizeof(uint32_t) - tile_hbytes;
36 
37   const uint32_t* i0 = input;
38   const uint32_t* i1 = (const uint32_t*) ((uintptr_t) i0 + input_stride);
39   const uint32_t* i2 = (const uint32_t*) ((uintptr_t) i1 + input_stride);
40   const uint32_t* i3 = (const uint32_t*) ((uintptr_t) i2 + input_stride);
41   uint32_t* o = (uint32_t*) ((uintptr_t) output - tile_hbytes);
42   const size_t minus_output_stride = -output_stride;
43 
44   do {
45     const size_t rem = min(block_width - 1, 3);
46     const size_t oN_stride = rem * output_stride;
47     const size_t oN_offset = oN_stride + tile_hbytes;
48     size_t bh = block_height;
49     for (; bh >= 4; bh -= 4) {
50       const uint32x4_t v2_0 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_offset);
51       const uint32x4_t v2_1 = vld1q_u32(i1); i1 = (uint32_t*) ((uintptr_t) i1 + input_offset);
52       const uint32x4_t v2_2 = vld1q_u32(i2); i2 = (uint32_t*) ((uintptr_t) i2 + input_offset);
53       const uint32x4_t v2_3 = vld1q_u32(i3); i3 = (uint32_t*) ((uintptr_t) i3 + input_offset);
54 
55       const uint32x4x2_t v1_0 = vzipq_u32(v2_0, v2_2);
56       const uint32x4x2_t v1_1 = vzipq_u32(v2_1, v2_3);
57 
58       const uint32x4x2_t v0_0 = vzipq_u32(v1_0.val[0], v1_1.val[0]);
59       const uint32x4x2_t v0_1 = vzipq_u32(v1_0.val[1], v1_1.val[1]);
60 
61       o = (uint32_t*) ((uintptr_t) o + oN_offset);
62       vst1q_u32(o, v0_1.val[1]);
63       if XNN_UNPREDICTABLE(block_width > 3) {
64         o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
65       }
66       vst1q_u32(o, v0_1.val[0]);
67       if XNN_UNPREDICTABLE(block_width >= 3) {
68         o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
69       }
70       vst1q_u32(o, v0_0.val[1]);
71       if XNN_UNPREDICTABLE(block_width > 1) {
72         o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
73       }
74       vst1q_u32(o, v0_0.val[0]);
75     }
76     o = (uint32_t*) ((uintptr_t) o + tile_hbytes);
77 
78     if (bh != 0) {
79       const uint32x4_t v2_0 = vld1q_u32(i0);
80       if XNN_UNPREDICTABLE(bh < 2) {
81         i1 = i0;
82       }
83       const uint32x4_t v2_1 = vld1q_u32(i1);
84       if XNN_UNPREDICTABLE(bh <= 2) {
85         i2 = i0;
86       }
87       const uint32x4_t v2_2 = vld1q_u32(i2);
88       const uint32x4_t v2_3 = vmovq_n_u32(0);
89 
90       const uint32x4x2_t v1_0 = vzipq_u32(v2_0, v2_2);
91       const uint32x4x2_t v1_1 = vzipq_u32(v2_1, v2_3);
92 
93       const uint32x4x2_t v0_0 = vzipq_u32(v1_0.val[0], v1_1.val[0]);
94       const uint32x4x2_t v0_1 = vzipq_u32(v1_0.val[1], v1_1.val[1]);
95 
96       uint32x2_t v0_low = vget_low_u32(v0_0.val[0]);
97       uint32x2_t v1_low = vget_low_u32(v0_0.val[1]);
98       uint32x2_t v2_low = vget_low_u32(v0_1.val[0]);
99       uint32x2_t v3_low = vget_low_u32(v0_1.val[1]);
100 
101       if (bh & 2) {
102         o = (uint32_t*) ((uintptr_t) o + oN_stride);
103         vst1_u32(o, v3_low);
104         if XNN_UNPREDICTABLE(block_width > 3) {
105           o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
106         }
107         vst1_u32(o, v2_low);
108         if XNN_UNPREDICTABLE(block_width >= 3) {
109           o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
110         }
111         vst1_u32(o, v1_low);
112         if XNN_UNPREDICTABLE(block_width > 1) {
113           o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
114         }
115         vst1_u32(o, v0_low); o += 2;
116         v0_low = vget_high_u32(v0_0.val[0]);
117         v1_low = vget_high_u32(v0_0.val[1]);
118         v2_low = vget_high_u32(v0_1.val[0]);
119         v3_low = vget_high_u32(v0_1.val[1]);
120       }
121 
122       if (bh & 1) {
123         o = (uint32_t*) ((uintptr_t) o + oN_stride);
124         vst1_lane_u32(o, v3_low, 0);
125         if XNN_UNPREDICTABLE(block_width > 3) {
126           o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
127         }
128         vst1_lane_u32(o, v2_low, 0);
129         if XNN_UNPREDICTABLE(block_width >= 3) {
130           o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
131         }
132         vst1_lane_u32(o, v1_low, 0);
133         if XNN_UNPREDICTABLE(block_width > 1) {
134           o = (uint32_t*) ((uintptr_t) o + minus_output_stride);
135         }
136         vst1_lane_u32(o, v0_low, 0);
137       }
138     }
139 
140     i0 = (const uint32_t*) ((uintptr_t) i0 + input_reset);
141     i1 = (const uint32_t*) ((uintptr_t) i0 + input_stride);
142     i2 = (const uint32_t*) ((uintptr_t) i1 + input_stride);
143     i3 = (const uint32_t*) ((uintptr_t) i2 + input_stride);
144     o = (uint32_t*) ((uintptr_t) o + output_reset);
145     block_width = doz(block_width, tile_width);
146   } while (block_width != 0);
147 }
148