• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_qu8_f32_vcvt_ukernel__avx512skx_x32(size_t n,const uint8_t * x,float * y,const union xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_qu8_f32_vcvt_ukernel__avx512skx_x32(
20     size_t n,
21     const uint8_t* x,
22     float* y,
23     const union xnn_qu8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25   assert(n != 0);
26   assert(n % sizeof(uint8_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 >= 32 * sizeof(uint8_t); n -= 32 * sizeof(uint8_t)) {
33     __m512i vx0123456789ABCDEF = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) x));
34     __m512i vxGHIJKLMNOPQRSTUV = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) (x + 16)));
35     x += 32;
36 
37     vx0123456789ABCDEF = _mm512_add_epi32(vx0123456789ABCDEF, vminus_zero_point);
38     vxGHIJKLMNOPQRSTUV = _mm512_add_epi32(vxGHIJKLMNOPQRSTUV, vminus_zero_point);
39 
40     __m512 vy0123456789ABCDEF = _mm512_cvtepi32_ps(vx0123456789ABCDEF);
41     __m512 vyGHIJKLMNOPQRSTUV = _mm512_cvtepi32_ps(vxGHIJKLMNOPQRSTUV);
42 
43     vy0123456789ABCDEF = _mm512_mul_ps(vy0123456789ABCDEF, vscale);
44     vyGHIJKLMNOPQRSTUV = _mm512_mul_ps(vyGHIJKLMNOPQRSTUV, vscale);
45 
46     _mm512_storeu_ps(y, vy0123456789ABCDEF);
47     _mm512_storeu_ps(y + 16, vyGHIJKLMNOPQRSTUV);
48     y += 32;
49   }
50   for (; n >= 16 * sizeof(uint8_t); n -= 16 * sizeof(uint8_t)) {
51     __m512i vx = _mm512_cvtepu8_epi32(_mm_loadu_si128((const __m128i*) x));
52     vx = _mm512_add_epi32(vx, vminus_zero_point);
53     x += 16;
54 
55     __m512 vy = _mm512_cvtepi32_ps(vx);
56     vy = _mm512_mul_ps(vy, vscale);
57 
58     _mm512_storeu_ps(y, vy);
59     y += 16;
60   }
61   if XNN_UNLIKELY(n != 0) {
62     assert(n >= 1 * sizeof(uint8_t));
63     assert(n <= 15 * sizeof(uint8_t));
64 
65     // Prepare mask for valid elements (depends on n).
66     const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
67 
68     __m512i vx = _mm512_cvtepu8_epi32(_mm_maskz_loadu_epi8(vmask, x));
69     vx = _mm512_add_epi32(vx, vminus_zero_point);
70 
71     __m512 vy = _mm512_cvtepi32_ps(vx);
72     vy = _mm512_mul_ps(vy, vscale);
73 
74     _mm512_mask_storeu_ps(y, vmask, vy);
75   }
76 }
77