Debian Codegraph @

src/f32-velu/gen/f32-velu-sse41-rr2-p6-u4.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_u4(
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 >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
58 __m128 vx = _mm_loadu_ps(input);
59 input += 4;
60
61 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
62
63 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
64 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
65 vn = _mm_sub_ps(vn, vmagic_bias);
66
67 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
68 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
69
70 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
71 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
72 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
73 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
74 vp = _mm_mul_ps(vp, vt);
75
76 vt = _mm_mul_ps(vt, vs);
77 vs = _mm_sub_ps(vs, vone);
78 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
79 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
80
81 vx = _mm_mul_ps(vx, vbeta);
82 const __m128 vy = _mm_blendv_ps(vx, ve, vx);
83
84 _mm_storeu_ps(output, vy);
85 output += 4;
86 }
87 if XNN_UNLIKELY(batch != 0) {
88 __m128 vx = _mm_loadu_ps(input);
89
90 const __m128 vz = _mm_max_ps(vsat_cutoff, _mm_mul_ps(vx, vprescale));
91
92 __m128 vn = _mm_add_ps(_mm_mul_ps(vz, vlog2e), vmagic_bias);
93 __m128 vs = _mm_castsi128_ps(_mm_slli_epi32(_mm_castps_si128(vn), 23));
94 vn = _mm_sub_ps(vn, vmagic_bias);
95
96 __m128 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_hi), vz);
97 vt = _mm_add_ps(_mm_mul_ps(vn, vminus_ln2_lo), vt);
98
99 __m128 vp = _mm_add_ps(_mm_mul_ps(vc6, vt), vc5);
100 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc4);
101 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc3);
102 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vc2);
103 vp = _mm_mul_ps(vp, vt);
104
105 vt = _mm_mul_ps(vt, vs);
106 vs = _mm_sub_ps(vs, vone);
107 vp = _mm_add_ps(_mm_mul_ps(vp, vt), vt);
108 const __m128 ve = _mm_mul_ps(_mm_add_ps(vp, vs), valpha);
109
110 vx = _mm_mul_ps(vx, vbeta);
111 __m128 vy = _mm_blendv_ps(vx, ve, vx);
112
113 if (batch & (2 * sizeof(float))) {
114 _mm_storel_pi((__m64*) output, vy);
115 vy = _mm_movehl_ps(vy, vy);
116 output += 2;
117 }
118 if (batch & (1 * sizeof(float))) {
119 _mm_store_ss(output, vy);
120 }
121 }
122 }