1 // Auto-generated file. Do not edit!
2 // Template: src/f32-f16-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_f16_vcvt_ukernel__avx512skx_x16(size_t n,const float * input,void * output,const union xnn_f32_f16_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_f16_vcvt_ukernel__avx512skx_x16(
20 size_t n,
21 const float* input,
22 void* output,
23 const union xnn_f32_f16_cvt_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25 assert(n != 0);
26 assert(n % sizeof(float) == 0);
27 assert(input != NULL);
28 assert(output != NULL);
29
30 uint16_t* o = (uint16_t*) output;
31 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
32 const __m512 vf = _mm512_loadu_ps(input);
33 input += 16;
34
35 _mm256_storeu_si256((__m256i*) o, _mm512_cvtps_ph(vf, _MM_FROUND_NO_EXC));
36 o += 16;
37 }
38 if XNN_UNLIKELY(n != 0) {
39 assert(n >= 1 * sizeof(float));
40 assert(n <= 15 * sizeof(float));
41
42 // Prepare mask for valid elements (depends on n).
43 n >>= 2 /* log2(sizeof(float)) */;
44 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
45
46 const __m512 vf = _mm512_maskz_loadu_ps(vmask, input);
47 const __m256i vh = _mm512_cvtps_ph(vf, _MM_FROUND_NO_EXC);
48 _mm256_mask_storeu_epi16(o, vmask, vh);
49 }
50 }
51