1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vrnd/vrndu-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_vrndu_ukernel__sse2_x4(size_t n,const float * x,float * y,const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_vrndu_ukernel__sse2_x4(
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 const __m128 vone = _mm_load_ps(params->sse2.one);
30 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
31 const __m128 vx0123 = _mm_loadu_ps(x);
32 x += 4;
33
34 const __m128i vintx0123 = _mm_cvttps_epi32(vx0123);
35
36 const __m128 vrndmask0123 = _mm_castsi128_ps(_mm_or_si128(vmagic, _mm_cmpeq_epi32(vintx0123, vmagic)));
37
38 const __m128 vprerndx0123 = _mm_cvtepi32_ps(vintx0123);
39
40 const __m128 vrndx0123 = _mm_or_ps(_mm_and_ps(vx0123, vrndmask0123), _mm_andnot_ps(vrndmask0123, vprerndx0123));
41
42 const __m128 vadjmask0123 = _mm_or_ps(_mm_cmpge_ps(vrndx0123, vx0123), _mm_castsi128_ps(vmagic));
43
44 const __m128 vadjrndx0123 = _mm_add_ps(vrndx0123, vone);
45
46 const __m128 vy0123 = _mm_or_ps(_mm_and_ps(vrndx0123, vadjmask0123), _mm_andnot_ps(vadjmask0123, vadjrndx0123));
47
48 _mm_storeu_ps(y, vy0123);
49 y += 4;
50 }
51 if XNN_UNLIKELY(n != 0) {
52 const __m128 vx = _mm_loadu_ps(x);
53 const __m128i vintx = _mm_cvttps_epi32(vx);
54 const __m128 vrndmask = _mm_castsi128_ps(_mm_or_si128(vmagic, _mm_cmpeq_epi32(vintx, vmagic)));
55 const __m128 vprerndx = _mm_cvtepi32_ps(vintx);
56 const __m128 vrndx = _mm_or_ps(_mm_and_ps(vx, vrndmask), _mm_andnot_ps(vrndmask, vprerndx));
57 const __m128 vadjmask = _mm_or_ps(_mm_cmpge_ps(vrndx, vx), _mm_castsi128_ps(vmagic));
58 const __m128 vadjrndx = _mm_add_ps(vrndx, vone);
59 __m128 vy = _mm_or_ps(_mm_and_ps(vrndx, vadjmask), _mm_andnot_ps(vadjmask, vadjrndx));
60 if (n & (2 * sizeof(float))) {
61 _mm_storel_pi((__m64*) y, vy);
62 vy = _mm_movehl_ps(vy, vy);
63 y += 2;
64 }
65 if (n & (1 * sizeof(float))) {
66 _mm_store_ss(y, vy);
67 }
68 }
69 }
70