Debian Codegraph @

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