1 // Auto-generated file. Do not edit!
2 // Template: src/f32-velu/sse-rr2-p6.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/vunary.h>
15 #include <xnnpack/common.h>
16
17
xnn_f32_velu_ukernel__sse2_rr2_p6_x4(size_t n,const float * x,float * y,const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_velu_ukernel__sse2_rr2_p6_x4(
19 size_t n,
20 const float* x,
21 float* y,
22 const union xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
23 {
24 assert(n != 0);
25 assert(n % sizeof(float) == 0);
26 assert(x != NULL);
27 assert(y != NULL);
28
29 const __m128 vprescale = _mm_load_ps(params->sse.prescale);
30 const __m128 valpha = _mm_load_ps(params->sse.alpha);
31 const __m128 vbeta = _mm_load_ps(params->sse.beta);
32
33 const __m128 vsat_cutoff = _mm_set1_ps(-0x1.154246p+4f);
34 const __m128 vmagic_bias = _mm_set1_ps(0x1.8000FEp23f);
35 const __m128 vlog2e = _mm_set1_ps(0x1.715476p+0f);
36 const __m128 vminus_ln2_hi = _mm_set1_ps(-0x1.62E440p-1f);
37 const __m128 vminus_ln2_lo = _mm_set1_ps(0x1.0105C6p-21f);
38 const __m128 vc6 = _mm_set1_ps(0x1.6b7338p-10f);
39 const __m128 vc5 = _mm_set1_ps(0x1.12278Ep-7f);
40 const __m128 vc4 = _mm_set1_ps(0x1.555716p-5f);
41 const __m128 vc3 = _mm_set1_ps(0x1.5554B0p-3f);
42 const __m128 vc2 = _mm_set1_ps(0x1.FFFFFEp-2f);
43 const __m128 vone = _mm_set1_ps(1.0f);
44
45 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
46 __m128 vx = _mm_loadu_ps(x);
47 x += 4;
48
49 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
50
51 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
52 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
53 vn = _mm_sub_ps(vn, vmagic_bias);
54
55 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
56 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
57
58 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
59 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
60 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
61 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
62 vp = _mm_mul_ps(vp, vt);
63
64 vt = _mm_mul_ps(vt, vs);
65 vs = _mm_sub_ps(vs, vone);
66 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
67 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
68
69 const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
70 vx = _mm_mul_ps(vx, vbeta);
71 const __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
72
73 _mm_storeu_ps(y, vy);
74 y += 4;
75 }
76 if XNN_UNLIKELY(n != 0) {
77 __m128 vx = _mm_loadu_ps(x);
78
79 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
80
81 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
82 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
83 vn = _mm_sub_ps(vn, vmagic_bias);
84
85 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
86 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
87
88 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
89 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
90 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
91 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
92 vp = _mm_mul_ps(vp, vt);
93
94 vt = _mm_mul_ps(vt, vs);
95 vs = _mm_sub_ps(vs, vone);
96 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
97 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
98
99 const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
100 vx = _mm_mul_ps(vx, vbeta);
101 __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
102
103 if (n & (2 * sizeof(float))) {
104 _mm_storel_pi((__m64*) y, vy);
105 vy = _mm_movehl_ps(vy, vy);
106 y += 2;
107 }
108 if (n & (1 * sizeof(float))) {
109 _mm_store_ss(y, vy);
110 }
111 }
112 }
113