Debian Codegraph @

src/qs8-f16-vcvt/gen/qs8-f16-vcvt-avx2-u64.c

raw symbols SCIP
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-f16-vcvt/avx2.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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/vcvt.h"
17
18
19 void xnn_qs8_f16_vcvt_ukernel__avx2_u64(
20 size_t batch,
21 const int8_t* input,
22 xnn_float16* output,
23 const struct xnn_qs8_f16_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(int8_t) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 uint16_t* o = (uint16_t*) output;
31 const __m256i vzero_point = _mm256_set1_epi32(params->scalar.zero_point);
32 const __m256 vscale = _mm256_cvtph_ps(_mm_set1_epi16(*(const uint16_t*) &params->scalar.scale));
33 XNN_FORCE_REALIZATION(vzero_point);
34 XNN_FORCE_REALIZATION(vscale);
35 for (; batch >= 64 * sizeof(int8_t); batch -= 64 * sizeof(int8_t)) {
36 __m256i vx01234567 = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) input));
37 __m256i vx89ABCDEF = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) (input + 8)));
38 __m256i vxGHIJKLMN = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) (input + 16)));
39 __m256i vxOPQRSTUV = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) (input + 24)));
40 __m256i vxWXYZabcd = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) (input + 32)));
41 __m256i vxefghijkl = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) (input + 40)));
42 __m256i vxmnopqrst = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) (input + 48)));
43 __m256i vxuvwxyz01 = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) (input + 56)));
44 input += 64;
45
46 vx01234567 = _mm256_sub_epi32(vx01234567, vzero_point);
47 vx89ABCDEF = _mm256_sub_epi32(vx89ABCDEF, vzero_point);
48 vxGHIJKLMN = _mm256_sub_epi32(vxGHIJKLMN, vzero_point);
49 vxOPQRSTUV = _mm256_sub_epi32(vxOPQRSTUV, vzero_point);
50 vxWXYZabcd = _mm256_sub_epi32(vxWXYZabcd, vzero_point);
51 vxefghijkl = _mm256_sub_epi32(vxefghijkl, vzero_point);
52 vxmnopqrst = _mm256_sub_epi32(vxmnopqrst, vzero_point);
53 vxuvwxyz01 = _mm256_sub_epi32(vxuvwxyz01, vzero_point);
54
55 __m256 vy01234567 = _mm256_cvtepi32_ps(vx01234567);
56 __m256 vy89ABCDEF = _mm256_cvtepi32_ps(vx89ABCDEF);
57 __m256 vyGHIJKLMN = _mm256_cvtepi32_ps(vxGHIJKLMN);
58 __m256 vyOPQRSTUV = _mm256_cvtepi32_ps(vxOPQRSTUV);
59 __m256 vyWXYZabcd = _mm256_cvtepi32_ps(vxWXYZabcd);
60 __m256 vyefghijkl = _mm256_cvtepi32_ps(vxefghijkl);
61 __m256 vymnopqrst = _mm256_cvtepi32_ps(vxmnopqrst);
62 __m256 vyuvwxyz01 = _mm256_cvtepi32_ps(vxuvwxyz01);
63
64 vy01234567 = _mm256_mul_ps(vy01234567, vscale);
65 vy89ABCDEF = _mm256_mul_ps(vy89ABCDEF, vscale);
66 vyGHIJKLMN = _mm256_mul_ps(vyGHIJKLMN, vscale);
67 vyOPQRSTUV = _mm256_mul_ps(vyOPQRSTUV, vscale);
68 vyWXYZabcd = _mm256_mul_ps(vyWXYZabcd, vscale);
69 vyefghijkl = _mm256_mul_ps(vyefghijkl, vscale);
70 vymnopqrst = _mm256_mul_ps(vymnopqrst, vscale);
71 vyuvwxyz01 = _mm256_mul_ps(vyuvwxyz01, vscale);
72
73 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vy01234567, _MM_FROUND_TO_NEAREST_INT));
74 _mm_storeu_si128((__m128i*) (o + 8) , _mm256_cvtps_ph(vy89ABCDEF, _MM_FROUND_TO_NEAREST_INT));
75 _mm_storeu_si128((__m128i*) (o + 16) , _mm256_cvtps_ph(vyGHIJKLMN, _MM_FROUND_TO_NEAREST_INT));
76 _mm_storeu_si128((__m128i*) (o + 24) , _mm256_cvtps_ph(vyOPQRSTUV, _MM_FROUND_TO_NEAREST_INT));
77 _mm_storeu_si128((__m128i*) (o + 32) , _mm256_cvtps_ph(vyWXYZabcd, _MM_FROUND_TO_NEAREST_INT));
78 _mm_storeu_si128((__m128i*) (o + 40) , _mm256_cvtps_ph(vyefghijkl, _MM_FROUND_TO_NEAREST_INT));
79 _mm_storeu_si128((__m128i*) (o + 48) , _mm256_cvtps_ph(vymnopqrst, _MM_FROUND_TO_NEAREST_INT));
80 _mm_storeu_si128((__m128i*) (o + 56) , _mm256_cvtps_ph(vyuvwxyz01, _MM_FROUND_TO_NEAREST_INT));
81 o += 64;
82 }
83 for (; batch >= 8 * sizeof(int8_t); batch -= 8 * sizeof(int8_t)) {
84 __m256i vx = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) input));
85 vx = _mm256_sub_epi32(vx, vzero_point);
86 input += 8;
87
88 __m256 vy = _mm256_cvtepi32_ps(vx);
89 vy = _mm256_mul_ps(vy, vscale);
90
91 _mm_storeu_si128((__m128i*) o, _mm256_cvtps_ph(vy, _MM_FROUND_TO_NEAREST_INT));
92 o += 8;
93 }
94 if XNN_UNLIKELY(batch != 0) {
95 assert(batch >= 1 * sizeof(int8_t));
96 assert(batch <= 7 * sizeof(int8_t));
97
98 __m256i vx = _mm256_cvtepi8_epi32(_mm_loadl_epi64((const __m128i*) input));
99 vx = _mm256_sub_epi32(vx, vzero_point);
100
101 __m256 vy = _mm256_cvtepi32_ps(vx);
102 vy = _mm256_mul_ps(vy, vscale);
103
104 __m128i vhy = _mm256_cvtps_ph(vy, _MM_FROUND_TO_NEAREST_INT);
105 if (batch & (4 * sizeof(int8_t))) {
106 _mm_storel_epi64((__m128i*) o, vhy);
107 vhy = _mm_unpackhi_epi64(vhy, vhy);
108 o += 4;
109 }
110 if (batch & (2 * sizeof(int8_t))) {
111 _mm_storeu_si32((__m64*) o, vhy);
112 vhy = _mm_srli_epi64(vhy, 32);
113 o += 2;
114 }
115 if (batch & (1 * sizeof(int8_t))) {
116 *o = (uint16_t) _mm_extract_epi16(vhy, 0);
117 }
118 }
119 }
120