Debian Codegraph @

src/x32-transposec/gen/x32-transposec-4x4-multi-switch-wasmsimd.c

raw
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
18 void xnn_x32_transposec_ukernel__4x4_multi_switch_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(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 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);
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*) output;
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 size_t bh = block_height;
48 for (; bh >= 4; bh -= 4) {
49 const v128_t v2_0 = wasm_v128_load(i0);
50 i0 = (uint32_t*) ((uintptr_t) i0 + input_offset);
51 const v128_t v2_1 = wasm_v128_load(i1);
52 i1 = (uint32_t*) ((uintptr_t) i1 + input_offset);
53 const v128_t v2_2 = wasm_v128_load(i2);
54 i2 = (uint32_t*) ((uintptr_t) i2 + input_offset);
55 const v128_t v2_3 = wasm_v128_load(i3);
56 i3 = (uint32_t*) ((uintptr_t) i3 + input_offset);
57
58 const v128_t v1_0 = wasm_v32x4_shuffle(v2_0, v2_2, 0, 4, 1, 5);
59 const v128_t v1_1 = wasm_v32x4_shuffle(v2_0, v2_2, 2, 6, 3, 7);
60 const v128_t v1_2 = wasm_v32x4_shuffle(v2_1, v2_3, 0, 4, 1, 5);
61 const v128_t v1_3 = wasm_v32x4_shuffle(v2_1, v2_3, 2, 6, 3, 7);
62 const v128_t v0_0 = wasm_v32x4_shuffle(v1_0, v1_2, 0, 4, 1, 5);
63 const v128_t v0_1 = wasm_v32x4_shuffle(v1_0, v1_2, 2, 6, 3, 7);
64 const v128_t v0_2 = wasm_v32x4_shuffle(v1_1, v1_3, 0, 4, 1, 5);
65 const v128_t v0_3 = wasm_v32x4_shuffle(v1_1, v1_3, 2, 6, 3, 7);
66
67 uint32_t *oN = (uint32_t*) ((uintptr_t) o + oN_stride);
68 switch (rem) {
69 case 3:
70 wasm_v128_store(oN, v0_3);
71 oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
72 XNN_FALLTHROUGH
73 case 2:
74 wasm_v128_store(oN, v0_2);
75 oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
76 XNN_FALLTHROUGH
77 case 1:
78 wasm_v128_store(oN, v0_1);
79 XNN_FALLTHROUGH
80 case 0:
81 wasm_v128_store(o, v0_0);
82 o = (uint32_t*) ((uintptr_t) o + tile_hbytes);
83 break;
84 default:
85 XNN_UNREACHABLE;
86 }
87 }
88
89 if (bh != 0) {
90 const v128_t v2_0 = wasm_v128_load(i0);
91 if XNN_UNPREDICTABLE(bh < 2) {
92 i1 = i0;
93 }
94 const v128_t v2_1 = wasm_v128_load(i1);
95 if XNN_UNPREDICTABLE(bh <= 2) {
96 i2 = i0;
97 }
98 const v128_t v2_2 = wasm_v128_load(i2);
99 const v128_t v2_3 = wasm_v128_xor(v2_0, v2_0);
100
101 const v128_t v1_0 = wasm_v32x4_shuffle(v2_0, v2_2, 0, 4, 1, 5);
102 const v128_t v1_1 = wasm_v32x4_shuffle(v2_0, v2_2, 2, 6, 3, 7);
103 const v128_t v1_2 = wasm_v32x4_shuffle(v2_1, v2_3, 0, 4, 1, 5);
104 const v128_t v1_3 = wasm_v32x4_shuffle(v2_1, v2_3, 2, 6, 3, 7);
105
106 v128_t v0_0 = wasm_v32x4_shuffle(v1_0, v1_2, 0, 4, 1, 5);
107 v128_t v0_1 = wasm_v32x4_shuffle(v1_0, v1_2, 2, 6, 3, 7);
108 v128_t v0_2 = wasm_v32x4_shuffle(v1_1, v1_3, 0, 4, 1, 5);
109 v128_t v0_3 = wasm_v32x4_shuffle(v1_1, v1_3, 2, 6, 3, 7);
110
111 if (bh & 2) {
112 uint32_t* oN = (uint32_t*) ((uintptr_t) o + oN_stride);
113 switch (rem) {
114 case 3:
115 wasm_v128_store64_lane(oN, v0_3, 0);
116 oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
117 XNN_FALLTHROUGH
118 case 2:
119 wasm_v128_store64_lane(oN, v0_2, 0);
120 oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
121 XNN_FALLTHROUGH
122 case 1:
123 wasm_v128_store64_lane(oN, v0_1, 0);
124 XNN_FALLTHROUGH
125 case 0:
126 wasm_v128_store64_lane(o, v0_0, 0);
127 o += 2;
128 break;
129 default:
130 XNN_UNREACHABLE;
131 }
132 v0_0 = wasm_v64x2_shuffle(v0_0, v0_0, 1, 1);
133 v0_1 = wasm_v64x2_shuffle(v0_1, v0_1, 1, 1);
134 v0_2 = wasm_v64x2_shuffle(v0_2, v0_2, 1, 1);
135 v0_3 = wasm_v64x2_shuffle(v0_3, v0_3, 1, 1);
136 }
137
138 if (bh & 1) {
139 uint32_t* oN = (uint32_t*) ((uintptr_t) o + oN_stride);
140 switch (rem) {
141 case 3:
142 wasm_v128_store32_lane(oN, v0_3, 0);
143 oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
144 XNN_FALLTHROUGH
145 case 2:
146 wasm_v128_store32_lane(oN, v0_2, 0);
147 oN = (uint32_t*) ((uintptr_t) oN + minus_output_stride);
148 XNN_FALLTHROUGH
149 case 1:
150 wasm_v128_store32_lane(oN, v0_1, 0);
151 XNN_FALLTHROUGH
152 case 0:
153 wasm_v128_store32_lane(o, v0_0, 0);
154 break;
155 default:
156 XNN_UNREACHABLE;
157 }
158 }
159 }
160
161 i0 = (const uint32_t*) ((uintptr_t) i0 + input_reset);
162 i1 = (const uint32_t*) ((uintptr_t) i0 + input_stride);
163 i2 = (const uint32_t*) ((uintptr_t) i1 + input_stride);
164 i3 = (const uint32_t*) ((uintptr_t) i2 + input_stride);
165 o = (uint32_t*) ((uintptr_t) o + output_reset);
166 block_width = doz(block_width, tile_width);
167 } while (block_width != 0);
168 }