1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vsigmoid/avx512f-rr1-lut16-p3-perm-scalef.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 <immintrin.h>
13
14 #include <xnnpack/common.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16 #include <xnnpack/vunary.h>
17
18
xnn_f32_vsigmoid_ukernel__avx512f_rr1_lut16_p3_perm_scalef_div_x16(size_t n,const float * x,float * y,const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_vsigmoid_ukernel__avx512f_rr1_lut16_p3_perm_scalef_div_x16(
20 size_t n,
21 const float* x,
22 float* y,
23 const union xnn_f32_sigmoid_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25 assert(n % sizeof(float) == 0);
26
27 const __m512i vsign_mask = _mm512_set1_epi32((int) params->avx512_rr1_lut16_p3.sign_mask);
28 const __m512 vmagic_bias = _mm512_set1_ps(params->avx512_rr1_lut16_p3.magic_bias);
29 const __m512 vlog2e = _mm512_set1_ps(params->avx512_rr1_lut16_p3.log2e);
30 const __m512 vtable = _mm512_load_ps(params->avx512_rr1_lut16_p3.table);
31 const __m512 vminus_ln2 = _mm512_set1_ps(params->avx512_rr1_lut16_p3.minus_ln2);
32 const __m512 vc3 = _mm512_set1_ps(params->avx512_rr1_lut16_p3.c3);
33 const __m512 vc2 = _mm512_set1_ps(params->avx512_rr1_lut16_p3.c2);
34 const __m512 vone = _mm512_set1_ps(params->avx512_rr1_lut16_p3.one);
35
36 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
37 const __m512 vx = _mm512_loadu_ps(x);
38 x += 16;
39
40 const __m512 vz = _mm512_castsi512_ps(_mm512_or_epi32(_mm512_castps_si512(vx), vsign_mask));
41
42 __m512 vn = _mm512_fmadd_ps(vz, vlog2e, vmagic_bias);
43 const __m512 vl = _mm512_permutexvar_ps(_mm512_castps_si512(vn), vtable);
44 vn = _mm512_sub_ps(vn, vmagic_bias);
45
46 __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vz);
47
48 __m512 vp = _mm512_fmadd_ps(vt, vc3, vc2);
49 vp = _mm512_mul_ps(vp, vt);
50 vp = _mm512_fmadd_ps(vt, vp, vt);
51 vp = _mm512_fmadd_ps(vl, vp, vl);
52
53 const __m512 ve = _mm512_scalef_ps(vp, vn);
54 const __m512 vd = _mm512_add_ps(ve, vone);
55
56 __m512 vf = _mm512_div_ps(ve, vd);
57
58 vf = _mm512_mask_sub_ps(vf, _mm512_testn_epi32_mask(_mm512_castps_si512(vx), vsign_mask), vone, vf);
59
60 _mm512_storeu_ps(y, vf);
61 y += 16;
62 }
63 if XNN_UNLIKELY(n != 0) {
64 assert(n >= 1 * sizeof(float));
65 assert(n <= 15 * sizeof(float));
66
67 // Prepare mask for valid 32-bit elements (depends on n).
68 n >>= 2 /* log2(sizeof(float)) */;
69 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
70
71 const __m512 vx = _mm512_maskz_loadu_ps(vmask, x);
72 const __m512 vz = _mm512_castsi512_ps(_mm512_or_epi32(_mm512_castps_si512(vx), vsign_mask));
73
74 __m512 vn = _mm512_fmadd_ps(vz, vlog2e, vmagic_bias);
75 const __m512 vl = _mm512_permutexvar_ps(_mm512_castps_si512(vn), vtable);
76 vn = _mm512_sub_ps(vn, vmagic_bias);
77
78 __m512 vt = _mm512_fmadd_ps(vn, vminus_ln2, vz);
79
80 __m512 vp = _mm512_fmadd_ps(vt, vc3, vc2);
81 vp = _mm512_mul_ps(vp, vt);
82 vp = _mm512_fmadd_ps(vt, vp, vt);
83 vp = _mm512_fmadd_ps(vl, vp, vl);
84
85 const __m512 ve = _mm512_scalef_ps(vp, vn);
86 const __m512 vd = _mm512_add_ps(ve, vone);
87
88 __m512 vf = _mm512_div_ps(ve, vd);
89
90 vf = _mm512_mask_sub_ps(vf, _mm512_testn_epi32_mask(_mm512_castps_si512(vx), vsign_mask), vone, vf);
91
92 _mm512_mask_storeu_ps(y, vmask, vf);
93 }
94 }
95