1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vrnd/avx512f.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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/math.h>
17 #include <xnnpack/vunary.h>
18
19
xnn_f32_vrndne_ukernel__avx512f_x32(size_t n,const float * x,float * y,const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS (1)])20 void xnn_f32_vrndne_ukernel__avx512f_x32(
21 size_t n,
22 const float* x,
23 float* y,
24 const union xnn_f32_rnd_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
25 {
26 assert(n != 0);
27 assert(n % sizeof(float) == 0);
28
29 for (; n >= 32 * sizeof(float); n -= 32 * sizeof(float)) {
30 const __m512 vx0123456789ABCDEF = _mm512_loadu_ps(x);
31 const __m512 vxGHIJKLMNOPQRSTUV = _mm512_loadu_ps(x + 16);
32 x += 32;
33
34 const __m512 vy0123456789ABCDEF = _mm512_roundscale_ps(vx0123456789ABCDEF, _MM_FROUND_TO_NEAREST_INT);
35 const __m512 vyGHIJKLMNOPQRSTUV = _mm512_roundscale_ps(vxGHIJKLMNOPQRSTUV, _MM_FROUND_TO_NEAREST_INT);
36
37 _mm512_storeu_ps(y, vy0123456789ABCDEF);
38 _mm512_storeu_ps(y + 16, vyGHIJKLMNOPQRSTUV);
39 y += 32;
40 }
41 for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
42 const __m512 vx = _mm512_loadu_ps(x);
43 x += 16;
44
45 const __m512 vy = _mm512_roundscale_ps(vx, _MM_FROUND_TO_NEAREST_INT);
46
47 _mm512_storeu_ps(y, vy);
48 y += 16;
49 }
50 if XNN_UNLIKELY(n != 0) {
51 assert(n >= 1 * sizeof(float));
52 assert(n <= 15 * sizeof(float));
53 // Prepare mask for valid 32-bit elements (depends on n).
54 n >>= 2 /* log2(sizeof(float)) */;
55 const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
56
57 const __m512 vx = _mm512_maskz_loadu_ps(vmask, x);
58 const __m512 vy = _mm512_maskz_roundscale_ps(vmask, vx, _MM_FROUND_TO_NEAREST_INT);
59 _mm512_mask_storeu_ps(y, vmask, vy);
60 }
61 }
62