• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_x4(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_x4(
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 >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
29     const float vx0 = x[0];
30     const float vx1 = x[1];
31     const float vx2 = x[2];
32     const float vx3 = x[3];
33     x += 4;
34 
35     const float vnegx0 = __builtin_wasm_min_f32(vx0, vzero);
36     const float vnegx1 = __builtin_wasm_min_f32(vx1, vzero);
37     const float vnegx2 = __builtin_wasm_min_f32(vx2, vzero);
38     const float vnegx3 = __builtin_wasm_min_f32(vx3, vzero);
39 
40     float vacc0 = vnegx0 * vslope;
41     const float vposx0 = __builtin_wasm_max_f32(vx0, vzero);
42     float vacc1 = vnegx1 * vslope;
43     const float vposx1 = __builtin_wasm_max_f32(vx1, vzero);
44     float vacc2 = vnegx2 * vslope;
45     const float vposx2 = __builtin_wasm_max_f32(vx2, vzero);
46     float vacc3 = vnegx3 * vslope;
47     const float vposx3 = __builtin_wasm_max_f32(vx3, vzero);
48 
49     vacc0 += vposx0;
50     vacc1 += vposx1;
51     vacc2 += vposx2;
52     vacc3 += vposx3;
53 
54     y[0] = vacc0;
55     y[1] = vacc1;
56     y[2] = vacc2;
57     y[3] = vacc3;
58     y += 4;
59   }
60   if XNN_UNLIKELY(n != 0) {
61     do {
62       const float vx = *x++;
63       const float vnegx = __builtin_wasm_min_f32(vx, vzero);
64       float vacc = vnegx * vslope;
65       const float vposx = __builtin_wasm_max_f32(vx, vzero);
66       vacc += vposx;
67       *y++ = vacc;
68       n -= sizeof(float);
69     } while (n != 0);
70   }
71 }
72