1 // Auto-generated file. Do not edit!
2 // Template: src/f32-qs8-vcvt/avx512skx.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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
xnn_f32_qs8_vcvt_ukernel__avx512skx_x96(size_t n,const float * x,int8_t * y,const union xnn_f32_qs8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_qs8_vcvt_ukernel__avx512skx_x96(
20 size_t n,
21 const float* x,
22 int8_t* y,
23 const union xnn_f32_qs8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25 assert(n != 0);
26 assert(n % sizeof(float) == 0);
27 assert(x != NULL);
28 assert(y != NULL);
29
30 const __m512 vscale = _mm512_load_ps(params->avx2.scale);
31 const __m512 voutput_max_less_zero_point = _mm512_load_ps(params->avx512.output_max_less_zero_point);
32 const __m512i voutput_zero_point = _mm512_load_si512(params->avx512.output_zero_point);
33 const __m512i vshuffle512_mask = _mm512_load_si512(params->avx512.shuffle512_mask);
34 const __m256i vshuffle256_mask = _mm256_load_si256((const __m256i*) params->avx512.shuffle256_mask);
35 const __m512i voutput_min = _mm512_load_si512(params->avx512.output_min);
36 for (; n >= 96 * sizeof(float); n -= 96 * sizeof(float)) {
37 __m512 vx0123 = _mm512_loadu_ps(x);
38 __m512 vx4567 = _mm512_loadu_ps(x + 16);
39 __m512 vx89AB = _mm512_loadu_ps(x + 32);
40 __m512 vxCDEF = _mm512_loadu_ps(x + 48);
41 __m512 vxGHIJ = _mm512_loadu_ps(x + 64);
42 __m512 vxKLMN = _mm512_loadu_ps(x + 80);
43 x += 96;
44
45 vx0123 = _mm512_mul_ps(vx0123, vscale);
46 vx4567 = _mm512_mul_ps(vx4567, vscale);
47 vx89AB = _mm512_mul_ps(vx89AB, vscale);
48 vxCDEF = _mm512_mul_ps(vxCDEF, vscale);
49 vxGHIJ = _mm512_mul_ps(vxGHIJ, vscale);
50 vxKLMN = _mm512_mul_ps(vxKLMN, vscale);
51
52 vx0123 = _mm512_min_ps(vx0123, voutput_max_less_zero_point);
53 vx4567 = _mm512_min_ps(vx4567, voutput_max_less_zero_point);
54 vx89AB = _mm512_min_ps(vx89AB, voutput_max_less_zero_point);
55 vxCDEF = _mm512_min_ps(vxCDEF, voutput_max_less_zero_point);
56 vxGHIJ = _mm512_min_ps(vxGHIJ, voutput_max_less_zero_point);
57 vxKLMN = _mm512_min_ps(vxKLMN, voutput_max_less_zero_point);
58
59 const __m512i vacc0123 = _mm512_cvtps_epi32(vx0123);
60 const __m512i vacc4567 = _mm512_cvtps_epi32(vx4567);
61 const __m512i vacc89AB = _mm512_cvtps_epi32(vx89AB);
62 const __m512i vaccCDEF = _mm512_cvtps_epi32(vxCDEF);
63 const __m512i vaccGHIJ = _mm512_cvtps_epi32(vxGHIJ);
64 const __m512i vaccKLMN = _mm512_cvtps_epi32(vxKLMN);
65
66 __m512i vacc04152637 = _mm512_packs_epi32(vacc0123, vacc4567);
67 __m512i vacc8C9DAEBF = _mm512_packs_epi32(vacc89AB, vaccCDEF);
68 __m512i vaccGKHLIMJN = _mm512_packs_epi32(vaccGHIJ, vaccKLMN);
69
70 vacc04152637 = _mm512_adds_epi16(vacc04152637, voutput_zero_point);
71 vacc8C9DAEBF = _mm512_adds_epi16(vacc8C9DAEBF, voutput_zero_point);
72 vaccGKHLIMJN = _mm512_adds_epi16(vaccGKHLIMJN, voutput_zero_point);
73
74 __m512i vy048C159D26AE37BF = _mm512_packs_epi16(vacc04152637, vacc8C9DAEBF);
75 __m256i vyGKIMHLJN = _mm256_packs_epi16(_mm512_castsi512_si256(vaccGKHLIMJN), _mm512_extracti32x8_epi32(vaccGKHLIMJN, 1));
76
77 vy048C159D26AE37BF = _mm512_max_epi8(vy048C159D26AE37BF, voutput_min);
78 vyGKIMHLJN = _mm256_max_epi8(vyGKIMHLJN, _mm512_castsi512_si256(voutput_min));
79
80 const __m512i vy0123456789ABCDEF = _mm512_permutexvar_epi32(vshuffle512_mask, vy048C159D26AE37BF);
81 const __m256i vyGHIJKLMN = _mm256_permutevar8x32_epi32(vyGKIMHLJN, vshuffle256_mask);
82
83 _mm512_storeu_si512(y, vy0123456789ABCDEF);
84 _mm256_storeu_si256((__m256i*) (y + 64), vyGHIJKLMN);
85 y += 96;
86 }
87 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
88 __m512 vx0123 = _mm512_loadu_ps(x);
89 vx0123 = _mm512_mul_ps(vx0123, vscale);
90 vx0123 = _mm512_min_ps(vx0123, voutput_max_less_zero_point);
91 x += 16;
92
93 const __m512i vacc0123 = _mm512_cvtps_epi32(vx0123);
94
95 __m256i vacc0213 = _mm256_packs_epi32(_mm512_castsi512_si256(vacc0123), _mm512_extracti32x8_epi32(vacc0123, 1));
96 vacc0213 = _mm256_adds_epi16(vacc0213, _mm512_castsi512_si256(voutput_zero_point));
97 const __m128i vy0213 = _mm_packs_epi16(_mm256_castsi256_si128(vacc0213), _mm256_extracti128_si256(vacc0213, 1));
98 __m128i vy0123 = _mm_shuffle_epi32(vy0213, _MM_SHUFFLE(3, 1, 2, 0));
99 vy0123 = _mm_max_epi8(vy0123, _mm512_castsi512_si128(voutput_min));
100
101 _mm_storeu_si128((__m128i*) y, vy0123);
102 y += 16;
103 }
104 if XNN_UNLIKELY(n != 0) {
105 assert(n >= 1 * sizeof(float));
106 assert(n <= 15 * sizeof(float));
107
108 // Prepare mask for valid elements (depends on n).
109 n >>= 2 /* log2(sizeof(float)) */;
110 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
111
112 __m512 vx0123 = _mm512_maskz_loadu_ps(vmask, x);
113 vx0123 = _mm512_mul_ps(vx0123, vscale);
114 vx0123 = _mm512_min_ps(vx0123, voutput_max_less_zero_point);
115
116 const __m512i vacc0123 = _mm512_cvtps_epi32(vx0123);
117
118 __m256i vacc0213 = _mm256_packs_epi32(_mm512_castsi512_si256(vacc0123), _mm512_extracti32x8_epi32(vacc0123, 1));
119 vacc0213 = _mm256_adds_epi16(vacc0213, _mm512_castsi512_si256(voutput_zero_point));
120 const __m128i vy0213 = _mm_packs_epi16(_mm256_castsi256_si128(vacc0213), _mm256_extracti128_si256(vacc0213, 1));
121 __m128i vy0123 = _mm_shuffle_epi32(vy0213, _MM_SHUFFLE(3, 1, 2, 0));
122 vy0123 = _mm_max_epi8(vy0123, _mm512_castsi512_si128(voutput_min));
123
124 _mm_mask_storeu_epi8(y, vmask, vy0123);
125 }
126 }
127