• 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/hswish.h>
15 
16 
xnn_f32_hswish_ukernel__wasm_x2(size_t n,const float * x,float * y,const union xnn_f32_hswish_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_hswish_ukernel__wasm_x2(
18     size_t n,
19     const float* x,
20     float* y,
21     const union xnn_f32_hswish_params params[restrict XNN_MIN_ELEMENTS(1)])
22 {
23   assert(n != 0);
24   assert(n % sizeof(float) == 0);
25 
26   const float vsixth = params->scalar.sixth;
27   const float vthree = params->scalar.three;
28   const float vsix = params->scalar.six;
29   const float vzero = 0.0f;
30   assert(vthree == 3.0f);
31   assert(vsix == 6.0f);
32 
33   for (; n >= 2 * sizeof(float); n -= 2 * sizeof(float)) {
34     float vx0 = x[0];
35     float vx1 = x[1];
36     x += 2;
37 
38     float vacc0 = vx0 + vthree;
39     vx0 *= vsixth;
40     float vacc1 = vx1 + vthree;
41     vx1 *= vsixth;
42 
43     vacc0 = __builtin_wasm_max_f32(vacc0, vzero);
44     vacc1 = __builtin_wasm_max_f32(vacc1, vzero);
45 
46     vacc0 = __builtin_wasm_min_f32(vacc0, vsix);
47     vacc1 = __builtin_wasm_min_f32(vacc1, vsix);
48 
49     vacc0 *= vx0;
50     vacc1 *= vx1;
51 
52     y[0] = vacc0;
53     y[1] = vacc1;
54     y += 2;
55   }
56   if XNN_UNLIKELY(n != 0) {
57     float vx = *x;
58     float vacc = vx + vthree;
59     vx *= vsixth;
60     vacc = __builtin_wasm_max_f32(vacc, vzero);
61     vacc = __builtin_wasm_min_f32(vacc, vsix);
62     vacc *= vx;
63     *y = vacc;
64   }
65 }
66