• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-hswish/scalar.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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/math.h>
14 #include <xnnpack/vbinary.h>
15 
16 
xnn_f32_hswish_ukernel__wasm_x4(size_t n,const float * x,float * y,const union xnn_f32_hswish_params params[restrict static1])17 void xnn_f32_hswish_ukernel__wasm_x4(
18     size_t n,
19     const float* x,
20     float* y,
21     const union xnn_f32_hswish_params params[restrict static 1])
22 {
23   assert(n != 0);
24   assert(n % sizeof(float) == 0);
25 
26   const float vsixth = params->scalar.sixth;
27   const float vhalf = params->scalar.half;
28   const float vone = params->scalar.one;
29   assert(vhalf == 0.5f);
30   assert(vone == 1.0f);
31 
32   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
33     const float vx0 = x[0];
34     const float vx1 = x[1];
35     const float vx2 = x[2];
36     const float vx3 = x[3];
37     x += 4;
38 
39     float vacc0 = vx0 * vsixth + vhalf;
40     float vacc1 = vx1 * vsixth + vhalf;
41     float vacc2 = vx2 * vsixth + vhalf;
42     float vacc3 = vx3 * vsixth + vhalf;
43 
44     vacc0 = __builtin_wasm_max_f32(vacc0, 0.0f);
45     vacc1 = __builtin_wasm_max_f32(vacc1, 0.0f);
46     vacc2 = __builtin_wasm_max_f32(vacc2, 0.0f);
47     vacc3 = __builtin_wasm_max_f32(vacc3, 0.0f);
48 
49     vacc0 = __builtin_wasm_min_f32(vacc0, vone);
50     vacc1 = __builtin_wasm_min_f32(vacc1, vone);
51     vacc2 = __builtin_wasm_min_f32(vacc2, vone);
52     vacc3 = __builtin_wasm_min_f32(vacc3, vone);
53 
54     vacc0 *= vx0;
55     vacc1 *= vx1;
56     vacc2 *= vx2;
57     vacc3 *= vx3;
58 
59     y[0] = vacc0;
60     y[1] = vacc1;
61     y[2] = vacc2;
62     y[3] = vacc3;
63     y += 4;
64   }
65   if XNN_UNLIKELY(n != 0) {
66     do {
67       const float vx = *x++;
68       float vacc = vx * vsixth + vhalf;
69       vacc = __builtin_wasm_max_f32(vacc, 0.0f);
70       vacc = __builtin_wasm_min_f32(vacc, vone);
71       vacc = vacc * vx;
72       *y++ = vacc;
73       n -= sizeof(float);
74     } while (n != 0);
75   }
76 }
77