• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-clamp/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/clamp.h>
15 #include <xnnpack/common.h>
16 #include <xnnpack/intrinsics-polyfill.h>
17 
18 
xnn_f32_clamp_ukernel__avx512f_x32(size_t n,const float * x,float * y,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_clamp_ukernel__avx512f_x32(
20     size_t n,
21     const float* x,
22     float* y,
23     const union xnn_f32_minmax_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 vy_min = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.min));
31   const __m512 vy_max = _mm512_broadcast_f32x4(_mm_load_ps(params->sse.max));
32 
33   for (; n >= 32 * sizeof(float); n -= 32 * sizeof(float)) {
34     __m512 vacc0123456789ABCDEF = _mm512_loadu_ps(x);
35     __m512 vaccGHIJKLMNOPQRSTUV = _mm512_loadu_ps(x + 16);
36     x += 32;
37 
38     vacc0123456789ABCDEF = _mm512_max_ps(vacc0123456789ABCDEF, vy_min);
39     vaccGHIJKLMNOPQRSTUV = _mm512_max_ps(vaccGHIJKLMNOPQRSTUV, vy_min);
40 
41     vacc0123456789ABCDEF = _mm512_min_ps(vacc0123456789ABCDEF, vy_max);
42     vaccGHIJKLMNOPQRSTUV = _mm512_min_ps(vaccGHIJKLMNOPQRSTUV, vy_max);
43 
44     _mm512_storeu_ps(y, vacc0123456789ABCDEF);
45     _mm512_storeu_ps(y + 16, vaccGHIJKLMNOPQRSTUV);
46     y += 32;
47   }
48   for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
49     __m512 vacc = _mm512_loadu_ps(x);
50     x += 16;
51 
52     vacc = _mm512_max_ps(vacc, vy_min);
53     vacc = _mm512_min_ps(vacc, vy_max);
54 
55     _mm512_storeu_ps(y, vacc);
56     y += 16;
57   }
58   if XNN_UNLIKELY(n != 0) {
59     assert(n >= 1 * sizeof(float));
60     assert(n <= 15 * sizeof(float));
61     // Prepare mask for valid 32-bit elements (depends on n).
62     n >>= 2 /* log2(sizeof(float)) */;
63     const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
64 
65     __m512 vacc = _mm512_maskz_loadu_ps(vmask, x);
66     vacc = _mm512_max_ps(vacc, vy_min);
67     vacc = _mm512_min_ps(vacc, vy_max);
68     _mm512_mask_storeu_ps(y, vmask, vacc);
69   }
70 }
71