1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vlrelu/wasmsimd-minmax.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_minmax_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_minmax_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(¶ms->scalar.slope);
28 const v128_t vzero = wasm_f32x4_splat(0.0f);
29 for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
30 v128_t vx0123 = wasm_v128_load(x);
31 v128_t vx4567 = wasm_v128_load(x + 4);
32 x += 8;
33
34 v128_t vacc0123 = wasm_i32x4_max(vx0123, vzero);
35 vx0123 = wasm_i32x4_min(vx0123, vzero);
36 v128_t vacc4567 = wasm_i32x4_max(vx4567, vzero);
37 vx4567 = wasm_i32x4_min(vx4567, vzero);
38
39 vacc0123 = wasm_f32x4_add(vacc0123, wasm_f32x4_mul(vx0123, vslope));
40 vacc4567 = wasm_f32x4_add(vacc4567, wasm_f32x4_mul(vx4567, vslope));
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 v128_t vx = wasm_v128_load(x);
48 x += 4;
49 v128_t vacc = wasm_i32x4_max(vx, vzero);
50 vx = wasm_i32x4_min(vx, vzero);
51 vacc = wasm_f32x4_add(vacc, wasm_f32x4_mul(vx, vslope));
52 wasm_v128_store(y, vacc);
53 y += 4;
54 }
55 if XNN_UNLIKELY(n != 0) {
56 v128_t vx = wasm_v128_load(x);
57 v128_t vacc = wasm_i32x4_max(vx, vzero);
58 vx = wasm_i32x4_min(vx, vzero);
59 vacc = wasm_f32x4_add(vacc, wasm_f32x4_mul(vx, vslope));
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