• 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 <emmintrin.h>
9 
10 #include <xnnpack/clamp.h>
11 
12 
xnn_f32_clamp_ukernel__sse(size_t n,const float * x,float * y,const union xnn_f32_output_params params[restrict static1])13 void xnn_f32_clamp_ukernel__sse(
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 __m128 voutput_max = _mm_load_ps(params->sse.max);
23   const __m128 voutput_min = _mm_load_ps(params->sse.min);
24 
25   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
26     const __m128 vx = _mm_loadu_ps(x);
27     x += 4;
28 
29     const __m128 vy = _mm_min_ps(_mm_max_ps(vx, voutput_min), voutput_max);
30 
31     _mm_storeu_ps(y, vy);
32     y += 4;
33   }
34   if (n != 0) {
35     const __m128 vx = _mm_loadu_ps(x);
36 
37     __m128 vy = _mm_min_ps(_mm_max_ps(vx, voutput_min), voutput_max);
38 
39     if (n & 2 * sizeof(float)) {
40       _mm_storel_pi((__m64*) y, vy);
41       vy = _mm_movehl_ps(vy, vy);
42       y += 2;
43     }
44     if (n & 1 * sizeof(float)) {
45       _mm_store_ss(y, vy);
46     }
47   }
48 }
49