• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vrnd/vrndz-sse2.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 <emmintrin.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/math.h>
16 #include <xnnpack/vunary.h>
17 
18 
xnn_f32_vrndz_ukernel__sse2_x8(size_t n,const float * x,float * y,const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_vrndz_ukernel__sse2_x8(
20     size_t n,
21     const float* x,
22     float* y,
23     const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
24 {
25   assert(n != 0);
26   assert(n % sizeof(float) == 0);
27 
28   const __m128i vmagic = _mm_load_si128((const __m128i*) params->sse2.sign_mask);
29   for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
30     const __m128 vx0123 = _mm_loadu_ps(x);
31     const __m128 vx4567 = _mm_loadu_ps(x + 4);
32     x += 8;
33 
34     const __m128i vintx0123 = _mm_cvttps_epi32(vx0123);
35     const __m128i vintx4567 = _mm_cvttps_epi32(vx4567);
36 
37     const __m128 vrndmask0123 = _mm_castsi128_ps(_mm_or_si128(vmagic, _mm_cmpeq_epi32(vintx0123, vmagic)));
38     const __m128 vrndmask4567 = _mm_castsi128_ps(_mm_or_si128(vmagic, _mm_cmpeq_epi32(vintx4567, vmagic)));
39 
40     const __m128 vrndx0123 = _mm_cvtepi32_ps(vintx0123);
41     const __m128 vrndx4567 = _mm_cvtepi32_ps(vintx4567);
42 
43     const __m128 vy0123 = _mm_or_ps(_mm_and_ps(vx0123, vrndmask0123), _mm_andnot_ps(vrndmask0123, vrndx0123));
44     const __m128 vy4567 = _mm_or_ps(_mm_and_ps(vx4567, vrndmask4567), _mm_andnot_ps(vrndmask4567, vrndx4567));
45 
46     _mm_storeu_ps(y, vy0123);
47     _mm_storeu_ps(y + 4, vy4567);
48     y += 8;
49   }
50   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
51     const __m128 vx = _mm_loadu_ps(x);
52     x += 4;
53 
54     const __m128i vintx = _mm_cvttps_epi32(vx);
55     const __m128 vrndmask = _mm_castsi128_ps(_mm_or_si128(vmagic, _mm_cmpeq_epi32(vintx, vmagic)));
56     const __m128 vrndx = _mm_cvtepi32_ps(vintx);
57     const __m128 vy = _mm_or_ps(_mm_and_ps(vx, vrndmask), _mm_andnot_ps(vrndmask, vrndx));
58 
59     _mm_storeu_ps(y, vy);
60     y += 4;
61   }
62   if XNN_UNLIKELY(n != 0) {
63     const __m128 vx = _mm_loadu_ps(x);
64     const __m128i vintx = _mm_cvttps_epi32(vx);
65     const __m128 vrndmask = _mm_castsi128_ps(_mm_or_si128(vmagic, _mm_cmpeq_epi32(vintx, vmagic)));
66     const __m128 vrndx = _mm_cvtepi32_ps(vintx);
67     __m128 vy = _mm_or_ps(_mm_and_ps(vx, vrndmask), _mm_andnot_ps(vrndmask, vrndx));
68     if (n & (2 * sizeof(float))) {
69       _mm_storel_pi((__m64*) y, vy);
70       vy = _mm_movehl_ps(vy, vy);
71       y += 2;
72     }
73     if (n & (1 * sizeof(float))) {
74       _mm_store_ss(y, vy);
75     }
76   }
77 }
78