xref: /aosp_15_r20/external/XNNPACK/src/x32-transposec/gen/4x4-reuse-multi-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_reuse_multi_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_reuse_multi_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 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* o0 = (uint32_t*) output;
38   uint32_t* o1 = (uint32_t*) ((uintptr_t) o0 + output_stride);
39   uint32_t* o2 = (uint32_t*) ((uintptr_t) o1 + output_stride);
40   uint32_t* o3 = (uint32_t*) ((uintptr_t) o2 + output_stride);
41 
42   do {
43     if XNN_UNPREDICTABLE(block_width < 2) {
44       o1 = o0;
45     }
46     if XNN_UNPREDICTABLE(block_width <= 2) {
47       o2 = o0;
48     }
49     if XNN_UNPREDICTABLE(block_width < 4) {
50       o3 = o0;
51     }
52     size_t bh = block_height;
53     for (; bh >= 4; bh -= 4) {
54       const uint32x4_t v2_0 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
55       const uint32x4_t v2_1 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
56       const uint32x4_t v2_2 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
57       const uint32x4_t v2_3 = vld1q_u32(i0); i0 = (uint32_t*) ((uintptr_t) i0 + input_stride);
58 
59       const uint32x4x2_t v1_0 = vzipq_u32(v2_0, v2_2);
60       const uint32x4x2_t v1_1 = vzipq_u32(v2_1, v2_3);
61 
62       const uint32x4x2_t v0_0 = vzipq_u32(v1_0.val[0], v1_1.val[0]);
63       const uint32x4x2_t v0_1 = vzipq_u32(v1_0.val[1], v1_1.val[1]);
64 
65       vst1q_u32(o3, v0_1.val[1]); o3 = (uint32_t*) ((uintptr_t) o3 + tile_hbytes);
66       vst1q_u32(o2, v0_1.val[0]); o2 = (uint32_t*) ((uintptr_t) o2 + tile_hbytes);
67       vst1q_u32(o1, v0_0.val[1]); o1 = (uint32_t*) ((uintptr_t) o1 + tile_hbytes);
68       vst1q_u32(o0, v0_0.val[0]); o0 = (uint32_t*) ((uintptr_t) o0 + tile_hbytes);
69     }
70 
71     if (bh != 0) {
72       const uint32x4_t v2_0 = vld1q_u32(i0);
73       const uint32_t *i1 = (const uint32_t*) ((uintptr_t) i0 + input_stride);
74       if XNN_UNPREDICTABLE(bh < 2) {
75         i1 = i0;
76       }
77       const uint32x4_t v2_1 = vld1q_u32(i1);
78       const uint32_t *i2 = (const uint32_t*) ((uintptr_t) i1 + input_stride);
79       if XNN_UNPREDICTABLE(bh <= 2) {
80         i2 = i1;
81       }
82       const uint32x4_t v2_2 = vld1q_u32(i2);
83       const uint32x4_t v2_3 = vmovq_n_u32(0);
84 
85       const uint32x4x2_t v1_0 = vzipq_u32(v2_0, v2_2);
86       const uint32x4x2_t v1_1 = vzipq_u32(v2_1, v2_3);
87 
88       const uint32x4x2_t v0_0 = vzipq_u32(v1_0.val[0], v1_1.val[0]);
89       const uint32x4x2_t v0_1 = vzipq_u32(v1_0.val[1], v1_1.val[1]);
90 
91       uint32x2_t v0_low = vget_low_u32(v0_0.val[0]);
92       uint32x2_t v1_low = vget_low_u32(v0_0.val[1]);
93       uint32x2_t v2_low = vget_low_u32(v0_1.val[0]);
94       uint32x2_t v3_low = vget_low_u32(v0_1.val[1]);
95 
96       if (bh & 2) {
97         vst1_u32(o3, v3_low); o3 += 2;
98         vst1_u32(o2, v2_low); o2 += 2;
99         vst1_u32(o1, v1_low); o1 += 2;
100         vst1_u32(o0, v0_low); o0 += 2;
101         v0_low = vget_high_u32(v0_0.val[0]);
102         v1_low = vget_high_u32(v0_0.val[1]);
103         v2_low = vget_high_u32(v0_1.val[0]);
104         v3_low = vget_high_u32(v0_1.val[1]);
105       }
106 
107       if (bh & 1) {
108         vst1_lane_u32(o3, v3_low, 0);
109         vst1_lane_u32(o2, v2_low, 0);
110         vst1_lane_u32(o1, v1_low, 0);
111         vst1_lane_u32(o0, v0_low, 0);
112       }
113     }
114 
115     i0 = (const uint32_t*) ((uintptr_t) i0 + input_reset);
116     o0 = (uint32_t*) ((uintptr_t) o0 + output_reset);
117     o1 = (uint32_t*) ((uintptr_t) o1 + output_reset);
118     o2 = (uint32_t*) ((uintptr_t) o2 + output_reset);
119     o3 = (uint32_t*) ((uintptr_t) o3 + output_reset);
120     block_width = doz(block_width, tile_width);
121   } while (block_width != 0);
122 }
123