1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vrnd/vrndd-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_vrndd_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_vrndd_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_OOB_READS
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 vy0123 = _mm_sub_ps(vrndx0123, _mm_and_ps(_mm_cmpgt_ps(vrndx0123, vx0123), vone));
43
44 _mm_storeu_ps(y, vy0123);
45 y += 4;
46 }
47 if XNN_UNLIKELY(n != 0) {
48 const __m128 vx = _mm_loadu_ps(x);
49 const __m128i vintx = _mm_cvttps_epi32(vx);
50 const __m128 vrndmask = _mm_castsi128_ps(_mm_or_si128(vmagic, _mm_cmpeq_epi32(vintx, vmagic)));
51 const __m128 vprerndx = _mm_cvtepi32_ps(vintx);
52 const __m128 vrndx = _mm_or_ps(_mm_and_ps(vx, vrndmask), _mm_andnot_ps(vrndmask, vprerndx));
53 __m128 vy = _mm_sub_ps(vrndx, _mm_and_ps(_mm_cmpgt_ps(vrndx, vx), vone));
54 if (n & (2 * sizeof(float))) {
55 _mm_storel_pi((__m64*) y, vy);
56 vy = _mm_movehl_ps(vy, vy);
57 y += 2;
58 }
59 if (n & (1 * sizeof(float))) {
60 _mm_store_ss(y, vy);
61 }
62 }
63 }
64