• 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 <psimd.h>
9 
10 #include <xnnpack/clamp.h>
11 
12 
xnn_f32_clamp_ukernel__psimd(size_t n,const float * x,float * y,const union xnn_f32_output_params params[restrict static1])13 void xnn_f32_clamp_ukernel__psimd(
14     size_t n,
15     const float* x,
16     float* y,
17     const union xnn_f32_output_params params[restrict static 1])
18 {
19   assert(n != 0);
20   assert(n % sizeof(float) == 0);
21 
22   const psimd_f32 voutput_max = psimd_load_splat_f32(&params->scalar.max);
23   const psimd_f32 voutput_min = psimd_load_splat_f32(&params->scalar.min);
24 
25   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
26     const psimd_f32 vx = psimd_load_f32(x);
27     x += 4;
28 
29     const psimd_f32 vy = psimd_min_f32(psimd_max_f32(vx, voutput_min), voutput_max);
30 
31     psimd_store_f32(y, vy);
32     y += 4;
33   }
34   if (n != 0) {
35     const psimd_f32 vx = psimd_load_f32(x);
36 
37     psimd_f32 vy = psimd_min_f32(psimd_max_f32(vx, voutput_min), voutput_max);
38 
39     if (n & 2 * sizeof(float)) {
40       psimd_store2_f32(y, vy);
41       vy = psimd_concat_hi_f32(vy, vy);
42       y += 2;
43     }
44     if (n & 1 * sizeof(float)) {
45       psimd_store1_f32(y, vy);
46     }
47   }
48 }
49