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_OOB_READS
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->sse2_rr2_p6.prescale);
30 const __m128 valpha = _mm_load_ps(params->sse2_rr2_p6.alpha);
31 const __m128 vbeta = _mm_load_ps(params->sse2_rr2_p6.beta);
32 const __m128 vsat_cutoff = _mm_load_ps(params->sse2_rr2_p6.sat_cutoff);
33 const __m128 vmagic_bias = _mm_load_ps(params->sse2_rr2_p6.magic_bias);
34 const __m128 vlog2e = _mm_load_ps(params->sse2_rr2_p6.log2e);
35 const __m128 vminus_ln2_hi = _mm_load_ps(params->sse2_rr2_p6.minus_ln2_hi);
36 const __m128 vminus_ln2_lo = _mm_load_ps(params->sse2_rr2_p6.minus_ln2_lo);
37 const __m128 vc6 = _mm_load_ps(params->sse2_rr2_p6.c6);
38 const __m128 vc5 = _mm_load_ps(params->sse2_rr2_p6.c5);
39 const __m128 vc4 = _mm_load_ps(params->sse2_rr2_p6.c4);
40 const __m128 vc3 = _mm_load_ps(params->sse2_rr2_p6.c3);
41 const __m128 vc2 = _mm_load_ps(params->sse2_rr2_p6.c2);
42 const __m128 vone = _mm_load_ps(params->sse2_rr2_p6.one);
43
44 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
45 __m128 vx = _mm_loadu_ps(x);
46 x += 4;
47
48 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
49
50 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
51 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
52 vn = _mm_sub_ps(vn, vmagic_bias);
53
54 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
55 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
56
57 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
58 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
59 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
60 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
61 vp = _mm_mul_ps(vp, vt);
62
63 vt = _mm_mul_ps(vt, vs);
64 vs = _mm_sub_ps(vs, vone);
65 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
66 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
67
68 const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
69 vx = _mm_mul_ps(vx, vbeta);
70 const __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
71
72 _mm_storeu_ps(y, vy);
73 y += 4;
74 }
75 if XNN_UNLIKELY(n != 0) {
76 __m128 vx = _mm_loadu_ps(x);
77
78 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
79
80 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
81 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
82 vn = _mm_sub_ps(vn, vmagic_bias);
83
84 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
85 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
86
87 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
88 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
89 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
90 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
91 vp = _mm_mul_ps(vp, vt);
92
93 vt = _mm_mul_ps(vt, vs);
94 vs = _mm_sub_ps(vs, vone);
95 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
96 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
97
98 const __m128 vm = _mm_castsi128_ps(_mm_cmpgt_epi32(_mm_setzero_si128(), _mm_castps_si128(vx)));
99 vx = _mm_mul_ps(vx, vbeta);
100 __m128 vy = _mm_or_ps(_mm_and_ps(ve, vm), _mm_andnot_ps(vm, vx));
101
102 if (n & (2 * sizeof(float))) {
103 _mm_storel_pi((__m64*) y, vy);
104 vy = _mm_movehl_ps(vy, vy);
105 y += 2;
106 }
107 if (n & (1 * sizeof(float))) {
108 _mm_store_ss(y, vy);
109 }
110 }
111 }
112