• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <assert.h>
7 
8 #include <xnnpack/clamp.h>
9 #include <xnnpack/math.h>
10 
11 
xnn_f32_clamp_ukernel__wasm(size_t n,const float * x,float * y,const union xnn_f32_output_params params[restrict static1])12 void xnn_f32_clamp_ukernel__wasm(
13     size_t n,
14     const float* x,
15     float* y,
16     const union xnn_f32_output_params params[restrict static 1])
17 {
18   assert(n != 0);
19   assert(n % sizeof(float) == 0);
20 
21   const float vy_max = params->scalar.max;
22   const float vy_min = params->scalar.min;
23 
24   for (; n >= 2 * sizeof(float); n -= 2 * sizeof(float)) {
25     const float vx0 = x[0];
26     const float vx1 = x[1];
27     x += 2;
28 
29     float vy0 = __builtin_wasm_max_f32(vx0, vy_min);
30     float vy1 = __builtin_wasm_max_f32(vx1, vy_min);
31     vy0 = __builtin_wasm_min_f32(vy0, vy_max);
32     vy1 = __builtin_wasm_min_f32(vy1, vy_max);
33 
34     y[0] = vy0;
35     y[1] = vy1;
36     y += 2;
37   }
38   if (n != 0) {
39     const float vx = *x;
40     float vy = __builtin_wasm_max_f32(vx, vy_min);
41     vy = __builtin_wasm_min_f32(vy, vy_max);
42     *y = vy;
43   }
44 }
45