1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-f32-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_qs8_f32_vcvt_ukernel__avx512skx_x64(size_t n,const int8_t * x,float * y,const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qs8_f32_vcvt_ukernel__avx512skx_x64(
20 size_t n,
21 const int8_t* x,
22 float* y,
23 const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(n != 0);
26 assert(n % sizeof(int8_t) == 0);
27 assert(x != NULL);
28 assert(y != NULL);
29
30 const __m512i vminus_zero_point = _mm512_load_si512(params->avx512.minus_zero_point);
31 const __m512 vscale = _mm512_load_ps(params->avx512.scale);
32 for (; n >= 64 * sizeof(int8_t); n -= 64 * sizeof(int8_t)) {
33 __m512i vx0123456789ABCDEF = _mm512_cvtepi8_epi32(_mm_loadu_si128((const __m128i*) x));
34 __m512i vxGHIJKLMNOPQRSTUV = _mm512_cvtepi8_epi32(_mm_loadu_si128((const __m128i*) (x + 16)));
35 __m512i vxWXYZ = _mm512_cvtepi8_epi32(_mm_loadu_si128((const __m128i*) (x + 32)));
36 __m512i vx = _mm512_cvtepi8_epi32(_mm_loadu_si128((const __m128i*) (x + 48)));
37 x += 64;
38
39 vx0123456789ABCDEF = _mm512_add_epi32(vx0123456789ABCDEF, vminus_zero_point);
40 vxGHIJKLMNOPQRSTUV = _mm512_add_epi32(vxGHIJKLMNOPQRSTUV, vminus_zero_point);
41 vxWXYZ = _mm512_add_epi32(vxWXYZ, vminus_zero_point);
42 vx = _mm512_add_epi32(vx, vminus_zero_point);
43
44 __m512 vy0123456789ABCDEF = _mm512_cvtepi32_ps(vx0123456789ABCDEF);
45 __m512 vyGHIJKLMNOPQRSTUV = _mm512_cvtepi32_ps(vxGHIJKLMNOPQRSTUV);
46 __m512 vyWXYZ = _mm512_cvtepi32_ps(vxWXYZ);
47 __m512 vy = _mm512_cvtepi32_ps(vx);
48
49 vy0123456789ABCDEF = _mm512_mul_ps(vy0123456789ABCDEF, vscale);
50 vyGHIJKLMNOPQRSTUV = _mm512_mul_ps(vyGHIJKLMNOPQRSTUV, vscale);
51 vyWXYZ = _mm512_mul_ps(vyWXYZ, vscale);
52 vy = _mm512_mul_ps(vy, vscale);
53
54 _mm512_storeu_ps(y, vy0123456789ABCDEF);
55 _mm512_storeu_ps(y + 16, vyGHIJKLMNOPQRSTUV);
56 _mm512_storeu_ps(y + 32, vyWXYZ);
57 _mm512_storeu_ps(y + 48, vy);
58 y += 64;
59 }
60 for (; n >= 16 * sizeof(int8_t); n -= 16 * sizeof(int8_t)) {
61 __m512i vx = _mm512_cvtepi8_epi32(_mm_loadu_si128((const __m128i*) x));
62 vx = _mm512_add_epi32(vx, vminus_zero_point);
63 x += 16;
64
65 __m512 vy = _mm512_cvtepi32_ps(vx);
66 vy = _mm512_mul_ps(vy, vscale);
67
68 _mm512_storeu_ps(y, vy);
69 y += 16;
70 }
71 if XNN_UNLIKELY(n != 0) {
72 assert(n >= 1 * sizeof(int8_t));
73 assert(n <= 15 * sizeof(int8_t));
74
75 // Prepare mask for valid elements (depends on n).
76 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
77
78 __m512i vx = _mm512_cvtepi8_epi32(_mm_maskz_loadu_epi8(vmask, x));
79 vx = _mm512_add_epi32(vx, vminus_zero_point);
80
81 __m512 vy = _mm512_cvtepi32_ps(vx);
82 vy = _mm512_mul_ps(vy, vscale);
83
84 _mm512_mask_storeu_ps(y, vmask, vy);
85 }
86 }
87