1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vlrelu/wasm.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 <xnnpack/common.h>
13 #include <xnnpack/vunary.h>
14 
15 
xnn_f32_vlrelu_ukernel__wasm_x2(size_t n,const float * x,float * y,const union xnn_f32_lrelu_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_vlrelu_ukernel__wasm_x2(
17     size_t n,
18     const float* x,
19     float* y,
20     const union xnn_f32_lrelu_params params[restrict XNN_MIN_ELEMENTS(1)])
21 {
22   assert(n != 0);
23   assert(n % sizeof(float) == 0);
24 
25   const float vslope = params->scalar.slope;
26   const float vzero = 0.0f;
27 
28   for (; n >= 2 * sizeof(float); n -= 2 * sizeof(float)) {
29     const float vx0 = x[0];
30     const float vx1 = x[1];
31     x += 2;
32 
33     const float vnegx0 = __builtin_wasm_min_f32(vx0, vzero);
34     const float vnegx1 = __builtin_wasm_min_f32(vx1, vzero);
35 
36     float vacc0 = vnegx0 * vslope;
37     const float vposx0 = __builtin_wasm_max_f32(vx0, vzero);
38     float vacc1 = vnegx1 * vslope;
39     const float vposx1 = __builtin_wasm_max_f32(vx1, vzero);
40 
41     vacc0 += vposx0;
42     vacc1 += vposx1;
43 
44     y[0] = vacc0;
45     y[1] = vacc1;
46     y += 2;
47   }
48   if XNN_UNLIKELY(n != 0) {
49     const float vx = *x;
50     const float vnegx = __builtin_wasm_min_f32(vx, vzero);
51     float vacc = vnegx * vslope;
52     const float vposx = __builtin_wasm_max_f32(vx, vzero);
53     vacc += vposx;
54     *y = vacc;
55   }
56 }
57