1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vlrelu/wasmsimd-bitselect.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 <assert.h>
11 
12 #include <wasm_simd128.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/vunary.h>
16 
17 
xnn_f32_vlrelu_ukernel__wasmsimd_bitselect_x8(size_t n,const float * x,float * y,const union xnn_f32_lrelu_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_vlrelu_ukernel__wasmsimd_bitselect_x8(
19     size_t n,
20     const float* x,
21     float* y,
22     const union xnn_f32_lrelu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
23 {
24   assert(n != 0);
25   assert(n % sizeof(float) == 0);
26 
27   const v128_t vslope = wasm_v32x4_load_splat(&params->scalar.slope);
28   const v128_t vzero = wasm_f32x4_splat(0.0f);
29   for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
30     const v128_t vx0123 = wasm_v128_load(x);
31     const v128_t vx4567 = wasm_v128_load(x + 4);
32     x += 8;
33 
34     v128_t vacc0123 = wasm_f32x4_mul(vx0123, vslope);
35     const v128_t vmask0123 = wasm_i32x4_lt(vx0123, vzero);
36     v128_t vacc4567 = wasm_f32x4_mul(vx4567, vslope);
37     const v128_t vmask4567 = wasm_i32x4_lt(vx4567, vzero);
38 
39     vacc0123 = wasm_v128_bitselect(vacc0123, vx0123, vmask0123);
40     vacc4567 = wasm_v128_bitselect(vacc4567, vx4567, vmask4567);
41 
42     wasm_v128_store(y, vacc0123);
43     wasm_v128_store(y + 4, vacc4567);
44     y += 8;
45   }
46   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
47     const v128_t vx = wasm_v128_load(x);
48     x += 4;
49     v128_t vacc = wasm_f32x4_mul(vx, vslope);
50     const v128_t vmask = wasm_i32x4_lt(vx, vzero);
51     vacc = wasm_v128_bitselect(vacc, vx, vmask);
52     wasm_v128_store(y, vacc);
53     y += 4;
54   }
55   if XNN_UNLIKELY(n != 0) {
56     const v128_t vx = wasm_v128_load(x);
57     v128_t vacc = wasm_f32x4_mul(vx, vslope);
58     const v128_t vmask = wasm_i32x4_lt(vx, vzero);
59     vacc = wasm_v128_bitselect(vacc, vx, vmask);
60 
61     if (n & (2 * sizeof(float))) {
62       *((double*) y) = wasm_f64x2_extract_lane(vacc, 0);
63       vacc = wasm_v32x4_shuffle(vacc, vacc, 2, 3, 2, 3);
64       y += 2;
65     }
66     if (n & (1 * sizeof(float))) {
67       *y = wasm_f32x4_extract_lane(vacc, 0);
68     }
69   }
70 }
71