xref: /aosp_15_r20/external/XNNPACK/src/x32-unpool/wasmsimd.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Copyright 2020 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <assert.h>
7 
8 #include <wasm_simd128.h>
9 
10 #include <xnnpack/unpool.h>
11 
12 
xnn_x32_unpool_ukernel__wasmsimd(size_t kernel_elements,size_t channels,uint32_t fill,const uint32_t * input,const uint32_t * index,uint32_t ** output)13 void xnn_x32_unpool_ukernel__wasmsimd(
14     size_t kernel_elements,
15     size_t channels,
16     uint32_t fill,
17     const uint32_t* input,
18     const uint32_t* index,
19     uint32_t** output)
20 {
21   // Pre-initialize outputs with constant.
22   const v128_t vfill = wasm_i32x4_splat(fill);
23   uint32_t** os = output;
24   do {
25     float* o = (float*) *os++;
26     size_t c = channels;
27     for (; c >= 4; c -= 4) {
28       wasm_v128_store(o, vfill);
29       o += 4;
30     }
31     if (c != 0) {
32       if (c & 2) {
33         *((double*) o) = wasm_f64x2_extract_lane(vfill, 0);
34         o += 2;
35       }
36       if (c & 1) {
37         *o = wasm_f32x4_extract_lane(vfill, 0);
38       }
39     }
40   } while (--kernel_elements != 0);
41 
42   // Copy indexed elements to output.
43   size_t offset = 0;
44   do {
45     const uint32_t i = *index++;
46     *((uint32_t*) ((uintptr_t) output[i] + offset)) = *input++;
47     offset += sizeof(uint32_t);
48   } while (--channels != 0);
49 }
50