• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
xnn_f32_velu_ukernel__sse41_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__sse41_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     vx = _mm_mul_ps(vx, vbeta);
70     const __m128 vy = _mm_blendv_ps(vx, ve, 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     vx = _mm_mul_ps(vx, vbeta);
99     __m128 vy = _mm_blendv_ps(vx, ve, vx);
100 
101     if (n & (2 * sizeof(float))) {
102       _mm_storel_pi((__m64*) y, vy);
103       vy = _mm_movehl_ps(vy, vy);
104       y += 2;
105     }
106     if (n & (1 * sizeof(float))) {
107       _mm_store_ss(y, vy);
108     }
109   }
110 }
111