• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fill.h>
11 
12 
xnn_x32_fill_ukernel__wasmsimd(size_t rows,size_t channels,uint32_t * output,size_t output_stride,const uint32_t * fill_value)13 void xnn_x32_fill_ukernel__wasmsimd(
14     size_t rows,
15     size_t channels,
16     uint32_t* output,
17     size_t output_stride,
18     const uint32_t* fill_value)
19 {
20   assert(rows != 0);
21   assert(channels != 0);
22   assert(channels % sizeof(uint32_t) == 0);
23   assert(fill_value != NULL);
24 
25   const size_t output_increment = output_stride - channels;
26 
27   const v128_t vfill = wasm_v32x4_load_splat(fill_value);
28   do {
29     size_t c = channels;
30     for (; c >= 16 * sizeof(uint32_t); c -= 16 * sizeof(uint32_t)) {
31       wasm_v128_store(output, vfill);
32       wasm_v128_store(output + 4, vfill);
33       wasm_v128_store(output + 8, vfill);
34       wasm_v128_store(output + 12, vfill);
35       output += 16;
36     }
37     for (; c >= 4 * sizeof(uint32_t); c -= 4 * sizeof(uint32_t)) {
38       wasm_v128_store(output, vfill);
39       output += 4;
40     }
41     if XNN_UNLIKELY(c != 0) {
42       if XNN_LIKELY(c & (2 * sizeof(uint32_t))) {
43         *((double*) output) = wasm_f64x2_extract_lane(vfill, 0);
44         output += 2;
45       }
46       if XNN_LIKELY(c & (1 * sizeof(uint32_t))) {
47         *((float*) output) = wasm_f32x4_extract_lane(vfill, 0);
48         output += 1;
49       }
50     }
51     output = (void*) ((uintptr_t) output + output_increment);
52   } while (--rows != 0);
53 }
54