1 // Auto-generated file. Do not edit!
2 // Template: src/f32-clamp/scalar.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/clamp.h>
13 #include <xnnpack/common.h>
14 #include <xnnpack/math.h>
15
16
xnn_f32_clamp_ukernel__wasm_x2(size_t n,const float * x,float * y,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_clamp_ukernel__wasm_x2(
18 size_t n,
19 const float* x,
20 float* y,
21 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
22 {
23 assert(n != 0);
24 assert(n % sizeof(float) == 0);
25 assert(x != NULL);
26 assert(y != NULL);
27
28 const float vy_min = params->scalar.min;
29 const float vy_max = params->scalar.max;
30
31 for (; n >= 2 * sizeof(float); n -= 2 * sizeof(float)) {
32 float vacc0 = x[0];
33 float vacc1 = x[1];
34 x += 2;
35
36 vacc0 = __builtin_wasm_max_f32(vacc0, vy_min);
37 vacc1 = __builtin_wasm_max_f32(vacc1, vy_min);
38
39 vacc0 = __builtin_wasm_min_f32(vacc0, vy_max);
40 vacc1 = __builtin_wasm_min_f32(vacc1, vy_max);
41
42 y[0] = vacc0;
43 y[1] = vacc1;
44 y += 2;
45 }
46 if XNN_UNLIKELY(n != 0) {
47 float vacc = *x;
48 vacc = __builtin_wasm_max_f32(vacc, vy_min);
49 vacc = __builtin_wasm_min_f32(vacc, vy_max);
50 *y = vacc;
51 }
52 }
53