Debian Codegraph @

src/f32-velu/gen/f32-velu-sse41-rr2-p6-u8.c

raw symbols SCIP
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 <smmintrin.h>
13
14 #include "xnnpack/vunary.h"
15 #include "xnnpack/common.h"
16
17
18 void xnn_f32_velu_ukernel__sse41_rr2_p6_u8(
19 size_t batch,
20 const float* input,
21 float* output,
22 const struct xnn_f32_elu_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(float) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const __m128 vsat_cutoff = _mm_set1_ps(-0x1.154246p+4f);
30 const __m128 vmagic_bias = _mm_set1_ps(0x1.8000FEp23f);
31 const __m128 vlog2e = _mm_set1_ps(0x1.715476p+0f);
32 const __m128 vminus_ln2_hi = _mm_set1_ps(-0x1.62E440p-1f);
33 const __m128 vminus_ln2_lo = _mm_set1_ps(0x1.0105C6p-21f);
34 const __m128 vc6 = _mm_set1_ps(0x1.6b7338p-10f);
35 const __m128 vc5 = _mm_set1_ps(0x1.12278Ep-7f);
36 const __m128 vc4 = _mm_set1_ps(0x1.555716p-5f);
37 const __m128 vc3 = _mm_set1_ps(0x1.5554B0p-3f);
38 const __m128 vc2 = _mm_set1_ps(0x1.FFFFFEp-2f);
39 const __m128 vone = _mm_set1_ps(1.0f);
40
41 XNN_FORCE_REALIZATION(vsat_cutoff);
42 XNN_FORCE_REALIZATION(vmagic_bias);
43 XNN_FORCE_REALIZATION(vlog2e);
44 XNN_FORCE_REALIZATION(vminus_ln2_hi);
45 XNN_FORCE_REALIZATION(vminus_ln2_lo);
46 XNN_FORCE_REALIZATION(vc6);
47 XNN_FORCE_REALIZATION(vc5);
48 XNN_FORCE_REALIZATION(vc4);
49 XNN_FORCE_REALIZATION(vc3);
50 XNN_FORCE_REALIZATION(vc2);
51 XNN_FORCE_REALIZATION(vone);
52
53 const __m128 vprescale = _mm_set1_ps(params->scalar.prescale);
54 const __m128 valpha = _mm_set1_ps(params->scalar.alpha);
55 const __m128 vbeta = _mm_set1_ps(params->scalar.beta);
56
57 for (; batch >= 8 * sizeof(float); batch -= 8 * sizeof(float)) {
58 __m128 vx0123 = _mm_loadu_ps(input);
59 __m128 vx4567 = _mm_loadu_ps(input + 4);
60 input += 8;
61
62 const __m128 vz0123 = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx0123, vprescale));
63 const __m128 vz4567 = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx4567, vprescale));
64
65 __m128 vn0123 = _mm_add_ps(_mm_mul_ps(vz0123, vlog2e), vmagic_bias);
66 __m128 vn4567 = _mm_add_ps(_mm_mul_ps(vz4567, vlog2e), vmagic_bias);
67
68 __m128 vs0123 = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn0123), 23));
69 __m128 vs4567 = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn4567), 23));
70
71 vn0123 = _mm_sub_ps(vn0123, vmagic_bias);
72 vn4567 = _mm_sub_ps(vn4567, vmagic_bias);
73
74 __m128 vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_hi), vz0123);
75 __m128 vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_hi), vz4567);
76
77 vt0123 = _mm_add_ps(_mm_mul_ps(vn0123, vminus_ln2_lo), vt0123);
78 vt4567 = _mm_add_ps(_mm_mul_ps(vn4567, vminus_ln2_lo), vt4567);
79
80 __m128 vp0123 = _mm_add_ps(_mm_mul_ps(vc6, vt0123), vc5);
81 __m128 vp4567 = _mm_add_ps(_mm_mul_ps(vc6, vt4567), vc5);
82
83 vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vc4);
84 vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vc4);
85
86 vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vc3);
87 vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vc3);
88
89 vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vc2);
90 vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vc2);
91
92 vp0123 = _mm_mul_ps(vp0123, vt0123);
93 vp4567 = _mm_mul_ps(vp4567, vt4567);
94
95 vt0123 = _mm_mul_ps(vt0123, vs0123);
96 vs0123 = _mm_sub_ps(vs0123, vone);
97 vt4567 = _mm_mul_ps(vt4567, vs4567);
98 vs4567 = _mm_sub_ps(vs4567, vone);
99
100 vp0123 = _mm_add_ps(_mm_mul_ps(vp0123, vt0123), vt0123);
101 vp4567 = _mm_add_ps(_mm_mul_ps(vp4567, vt4567), vt4567);
102
103 const __m128 ve0123 = _mm_mul_ps(_mm_add_ps(vp0123, vs0123), valpha);
104 const __m128 ve4567 = _mm_mul_ps(_mm_add_ps(vp4567, vs4567), valpha);
105
106 vx0123 = _mm_mul_ps(vx0123, vbeta);
107 vx4567 = _mm_mul_ps(vx4567, vbeta);
108
109 const __m128 vy0123 = _mm_blendv_ps(vx0123, ve0123, vx0123);
110 const __m128 vy4567 = _mm_blendv_ps(vx4567, ve4567, vx4567);
111
112 _mm_storeu_ps(output, vy0123);
113 _mm_storeu_ps(output + 4, vy4567);
114 output += 8;
115 }
116 for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
117 __m128 vx = _mm_loadu_ps(input);
118 input += 4;
119
120 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
121
122 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
123 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
124 vn = _mm_sub_ps(vn, vmagic_bias);
125
126 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
127 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
128
129 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
130 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
131 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
132 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
133 vp = _mm_mul_ps(vp, vt);
134
135 vt = _mm_mul_ps(vt, vs);
136 vs = _mm_sub_ps(vs, vone);
137 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
138 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
139
140 vx = _mm_mul_ps(vx, vbeta);
141 const __m128 vy = _mm_blendv_ps(vx, ve, vx);
142
143 _mm_storeu_ps(output, vy);
144 output += 4;
145 }
146 if XNN_UNLIKELY(batch != 0) {
147 __m128 vx = _mm_loadu_ps(input);
148
149 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
150
151 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
152 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
153 vn = _mm_sub_ps(vn, vmagic_bias);
154
155 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
156 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
157
158 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
159 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
160 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
161 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
162 vp = _mm_mul_ps(vp, vt);
163
164 vt = _mm_mul_ps(vt, vs);
165 vs = _mm_sub_ps(vs, vone);
166 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
167 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
168
169 vx = _mm_mul_ps(vx, vbeta);
170 __m128 vy = _mm_blendv_ps(vx, ve, vx);
171
172 if (batch & (2 * sizeof(float))) {
173 _mm_storel_pi((__m64*) output, vy);
174 vy = _mm_movehl_ps(vy, vy);
175 output += 2;
176 }
177 if (batch & (1 * sizeof(float))) {
178 _mm_store_ss(output, vy);
179 }
180 }
181 }