1 // Auto-generated file. Do not edit!
2 // Template: src/f32-hswish/wasmsimd.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/hswish.h>
16
17
xnn_f32_hswish_ukernel__wasmsimd_x8(size_t n,const float * x,float * y,const union xnn_f32_hswish_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_hswish_ukernel__wasmsimd_x8(
19 size_t n,
20 const float* x,
21 float* y,
22 const union xnn_f32_hswish_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 vsixth = wasm_v32x4_load_splat(¶ms->scalar.sixth);
28 const v128_t vthree = wasm_v32x4_load_splat(¶ms->scalar.three);
29 const v128_t vsix = wasm_v32x4_load_splat(¶ms->scalar.six);
30 const v128_t vzero = wasm_f32x4_splat(0.0f);
31
32 for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
33 v128_t vx0123 = wasm_v128_load(x);
34 v128_t vx4567 = wasm_v128_load(x + 4);
35 x += 8;
36
37 v128_t vacc0123 = wasm_f32x4_add(vx0123, vthree);
38 vx0123 = wasm_f32x4_mul(vx0123, vsixth);
39 v128_t vacc4567 = wasm_f32x4_add(vx4567, vthree);
40 vx4567 = wasm_f32x4_mul(vx4567, vsixth);
41
42 vacc0123 = wasm_i32x4_max(vacc0123, vzero);
43 vacc4567 = wasm_i32x4_max(vacc4567, vzero);
44
45 vacc0123 = wasm_i32x4_min(vacc0123, vsix);
46 vacc4567 = wasm_i32x4_min(vacc4567, vsix);
47
48 vacc0123 = wasm_f32x4_mul(vacc0123, vx0123);
49 vacc4567 = wasm_f32x4_mul(vacc4567, vx4567);
50
51 wasm_v128_store(y, vacc0123);
52 wasm_v128_store(y + 4, vacc4567);
53 y += 8;
54 }
55 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
56 v128_t vx = wasm_v128_load(x);
57 x += 4;
58
59 v128_t vacc = wasm_f32x4_add(vx, vthree);
60 vx = wasm_f32x4_mul(vx, vsixth);
61 vacc = wasm_i32x4_max(vacc, vzero);
62 vacc = wasm_i32x4_min(vacc, vsix);
63 vacc = wasm_f32x4_mul(vacc, vx);
64
65 wasm_v128_store(y, vacc);
66 y += 4;
67 }
68 if XNN_UNLIKELY(n != 0) {
69 v128_t vx = wasm_v128_load(x);
70
71 v128_t vacc = wasm_f32x4_add(vx, vthree);
72 vx = wasm_f32x4_mul(vx, vsixth);
73 vacc = wasm_i32x4_max(vacc, vzero);
74 vacc = wasm_i32x4_min(vacc, vsix);
75 vacc = wasm_f32x4_mul(vacc, vx);
76
77 if (n & (2 * sizeof(float))) {
78 *((double*) y) = wasm_f64x2_extract_lane(vacc, 0);
79 vacc = wasm_v32x4_shuffle(vacc, vacc, 2, 3, 2, 3);
80 y += 2;
81 }
82 if (n & (1 * sizeof(float))) {
83 *y = wasm_f32x4_extract_lane(vacc, 0);
84 }
85 }
86 }
87