Debian Codegraph @

src/f16-velu/gen/f16-velu-avx2-rr1-p3-u8.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/f16-velu/avx2-rr1-p3.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2022 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
19 void xnn_f16_velu_ukernel__avx2_rr1_p3_u8(
20 size_t batch,
21 const xnn_float16* input,
22 xnn_float16* output,
23 const struct xnn_f16_elu_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(uint16_t) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 const __m256 vsat_cutoff = _mm256_set1_ps(-0x1.0A4000p+3f);
31 const __m256 vmagic_bias = _mm256_set1_ps(0x1.8000FEp23f);
32 const __m256 vlog2e = _mm256_set1_ps(0x1.715476p+0f);
33 const __m256 vminus_ln2 = _mm256_set1_ps(-0x1.62E430p-1f);
34 const __m256 vc3 = _mm256_set1_ps(0x1.5554DCp-3f);
35 const __m256 vc2 = _mm256_set1_ps(0x1.01EBB2p-1f);
36 const __m256 vc1 = _mm256_set1_ps(0x1.0002F2p+0f);
37
38 XNN_FORCE_REALIZATION(vsat_cutoff);
39 XNN_FORCE_REALIZATION(vmagic_bias);
40 XNN_FORCE_REALIZATION(vlog2e);
41 XNN_FORCE_REALIZATION(vminus_ln2);
42 XNN_FORCE_REALIZATION(vc3);
43 XNN_FORCE_REALIZATION(vc2);
44 XNN_FORCE_REALIZATION(vc1);
45
46 const __m256 vprescale = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.prescale));
47 const __m256 valpha = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.alpha));
48 const __m256 vbeta = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.beta));
49
50 const uint16_t* i = (const uint16_t*) input;
51 uint16_t* o = (uint16_t*) output;
52 for (; batch >= 8 * sizeof(uint16_t); batch -= 8 * sizeof(uint16_t)) {
53 __m256 vx = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
54 i += 8;
55
56 const __m256 vz = _mm256_max_ps(vsat_cutoff, _mm256_mul_ps(vx, vprescale));
57
58 __m256 vn = _mm256_fmadd_ps(vz, vlog2e, vmagic_bias);
59 __m256 vs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(vn), 23));
60 vn = _mm256_sub_ps(vn, vmagic_bias);
61 __m256 vt = _mm256_fmadd_ps(vn, vminus_ln2, vz);
62
63 __m256 vp = _mm256_fmadd_ps(vc3, vt, vc2);
64 vp = _mm256_fmadd_ps(vp, vt, vc1);
65 vt = _mm256_mul_ps(vt, valpha);
66 vt = _mm256_mul_ps(vt, vs);
67 vs = _mm256_fmsub_ps(vs, valpha, valpha);
68 const __m256 ve = _mm256_fmadd_ps(vp, vt, vs);
69 vx = _mm256_mul_ps(vx, vbeta);
70 const __m256 vy = _mm256_blendv_ps(vx, ve, vx);
71
72 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vy, _MM_FROUND_TO_NEAREST_INT));
73 o += 8;
74 }
75 if XNN_UNLIKELY(batch != 0) {
76 assert(batch >= 1 * sizeof(uint16_t));
77 assert(batch <= 7 * sizeof(uint16_t));
78 __m256 vx = _mm256_cvtph_ps(_mm_loadu_si128((const __m128i*) i));
79
80 const __m256 vz = _mm256_max_ps(vsat_cutoff, _mm256_mul_ps(vx, vprescale));
81
82 __m256 vn = _mm256_fmadd_ps(vz, vlog2e, vmagic_bias);
83 __m256 vs = _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_castps_si256(vn), 23));
84 vn = _mm256_sub_ps(vn, vmagic_bias);
85 __m256 vt = _mm256_fmadd_ps(vn, vminus_ln2, vz);
86
87 __m256 vp = _mm256_fmadd_ps(vc3, vt, vc2);
88 vp = _mm256_fmadd_ps(vp, vt, vc1);
89 vt = _mm256_mul_ps(vt, valpha);
90 vt = _mm256_mul_ps(vt, vs);
91 vs = _mm256_fmsub_ps(vs, valpha, valpha);
92 const __m256 ve = _mm256_fmadd_ps(vp, vt, vs);
93 vx = _mm256_mul_ps(vx, vbeta);
94 const __m256 vy = _mm256_blendv_ps(vx, ve, vx);
95
96 __m128i vh = _mm256_cvtps_ph(vy, _MM_FROUND_TO_NEAREST_INT);
97 if (batch & (4 * sizeof(uint16_t))) {
98 _mm_storel_epi64((__m128i*) o, vh);
99 vh = _mm_unpackhi_epi64(vh, vh);
100 o += 4;
101 }
102 if (batch & (2 * sizeof(uint16_t))) {
103 _mm_storeu_si32(o, vh);
104 vh = _mm_srli_epi64(vh, 32);
105 o += 2;
106 }
107 if (batch & (1 * sizeof(uint16_t))) {
108 *o = (uint16_t) _mm_extract_epi16(vh, 0);
109 }
110 }
111 }