xref: /aosp_15_r20/external/XNNPACK/src/x32-transposec/gen/4x4-multi-mov-wasmsimd.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/x32-transposec/wasmsimd.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 <wasm_simd128.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_mov_wasmsimd(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_mov_wasmsimd(
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 v128_t v2_0 = wasm_v128_load(i0);
51       i0 = (uint32_t*) ((uintptr_t) i0 + input_offset);
52       const v128_t v2_1 = wasm_v128_load(i1);
53       i1 = (uint32_t*) ((uintptr_t) i1 + input_offset);
54       const v128_t v2_2 = wasm_v128_load(i2);
55       i2 = (uint32_t*) ((uintptr_t) i2 + input_offset);
56       const v128_t v2_3 = wasm_v128_load(i3);
57       i3 = (uint32_t*) ((uintptr_t) i3 + input_offset);
58 
59       const v128_t v1_0 = wasm_v32x4_shuffle(v2_0, v2_2, 0, 4, 1, 5);
60       const v128_t v1_1 = wasm_v32x4_shuffle(v2_0, v2_2, 2, 6, 3, 7);
61       const v128_t v1_2 = wasm_v32x4_shuffle(v2_1, v2_3, 0, 4, 1, 5);
62       const v128_t v1_3 = wasm_v32x4_shuffle(v2_1, v2_3, 2, 6, 3, 7);
63       const v128_t v0_0 = wasm_v32x4_shuffle(v1_0, v1_2, 0, 4, 1, 5);
64       const v128_t v0_1 = wasm_v32x4_shuffle(v1_0, v1_2, 2, 6, 3, 7);
65       const v128_t v0_2 = wasm_v32x4_shuffle(v1_1, v1_3, 0, 4, 1, 5);
66       const v128_t v0_3 = wasm_v32x4_shuffle(v1_1, v1_3, 2, 6, 3, 7);
67 
68       o = (uint32_t*) ((uintptr_t) o + oN_offset);
69       wasm_v128_store(o, v0_3);
70       uint32_t *oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
71       if XNN_UNPREDICTABLE(block_width > 3) {
72         o = oN;
73       }
74       wasm_v128_store(o, v0_2);
75       oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
76       if XNN_UNPREDICTABLE(block_width >= 3) {
77         o = oN;
78       }
79       wasm_v128_store(o, v0_1);
80       oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
81       if XNN_UNPREDICTABLE(block_width > 1) {
82         o = oN;
83       }
84       wasm_v128_store(o, v0_0);
85     }
86     o = (uint32_t*) ((uintptr_t) o + tile_hbytes);
87 
88     if (bh != 0) {
89       const v128_t v2_0 = wasm_v128_load(i0);
90       if XNN_UNPREDICTABLE(bh < 2) {
91         i1 = i0;
92       }
93       const v128_t v2_1 = wasm_v128_load(i1);
94       if XNN_UNPREDICTABLE(bh <= 2) {
95         i2 = i0;
96       }
97       const v128_t v2_2 = wasm_v128_load(i2);
98       const v128_t v2_3 = wasm_v128_xor(v2_0, v2_0);
99 
100       const v128_t v1_0 = wasm_v32x4_shuffle(v2_0, v2_2, 0, 4, 1, 5);
101       const v128_t v1_1 = wasm_v32x4_shuffle(v2_0, v2_2, 2, 6, 3, 7);
102       const v128_t v1_2 = wasm_v32x4_shuffle(v2_1, v2_3, 0, 4, 1, 5);
103       const v128_t v1_3 = wasm_v32x4_shuffle(v2_1, v2_3, 2, 6, 3, 7);
104 
105       v128_t v0_0 = wasm_v32x4_shuffle(v1_0, v1_2, 0, 4, 1, 5);
106       v128_t v0_1 = wasm_v32x4_shuffle(v1_0, v1_2, 2, 6, 3, 7);
107       v128_t v0_2 = wasm_v32x4_shuffle(v1_1, v1_3, 0, 4, 1, 5);
108       v128_t v0_3 = wasm_v32x4_shuffle(v1_1, v1_3, 2, 6, 3, 7);
109 
110       if (bh & 2) {
111         o = (uint32_t*) ((uintptr_t) o + oN_stride);
112         *((double*) o) = wasm_f64x2_extract_lane(v0_3, 0);
113         uint32_t *oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
114         if XNN_UNPREDICTABLE(block_width > 3) {
115           o = oN;
116         }
117         *((double*) o) = wasm_f64x2_extract_lane(v0_2, 0);
118         oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
119         if XNN_UNPREDICTABLE(block_width >= 3) {
120           o = oN;
121         }
122         *((double*) o) = wasm_f64x2_extract_lane(v0_1, 0);
123         oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
124         if XNN_UNPREDICTABLE(block_width > 1) {
125           o = oN;
126         }
127         *((double*) o) = wasm_f64x2_extract_lane(v0_0, 0);
128         o += 2;
129         v0_0 = wasm_v64x2_shuffle(v0_0, v0_0, 1, 1);
130         v0_1 = wasm_v64x2_shuffle(v0_1, v0_1, 1, 1);
131         v0_2 = wasm_v64x2_shuffle(v0_2, v0_2, 1, 1);
132         v0_3 = wasm_v64x2_shuffle(v0_3, v0_3, 1, 1);
133       }
134 
135       if (bh & 1) {
136         o = (uint32_t*) ((uintptr_t) o + oN_stride);
137         *((float*) o) = wasm_f32x4_extract_lane(v0_3, 0);
138         uint32_t *oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
139         if XNN_UNPREDICTABLE(block_width > 3) {
140           o = oN;
141         }
142         *((float*) o) = wasm_f32x4_extract_lane(v0_2, 0);
143         oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
144         if XNN_UNPREDICTABLE(block_width >= 3) {
145           o = oN;
146         }
147         *((float*) o) = wasm_f32x4_extract_lane(v0_1, 0);
148         oN = (uint32_t*) ((uintptr_t) o + minus_output_stride);
149         if XNN_UNPREDICTABLE(block_width > 1) {
150           o = oN;
151         }
152         *((float*) o) = wasm_f32x4_extract_lane(v0_0, 0);
153       }
154     }
155 
156     i0 = (const uint32_t*) ((uintptr_t) i0 + input_reset);
157     i1 = (const uint32_t*) ((uintptr_t) i0 + input_stride);
158     i2 = (const uint32_t*) ((uintptr_t) i1 + input_stride);
159     i3 = (const uint32_t*) ((uintptr_t) i2 + input_stride);
160     o = (uint32_t*) ((uintptr_t) o + output_reset);
161     block_width = doz(block_width, tile_width);
162   } while (block_width != 0);
163 }
164