• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vsqrt/avx512f-nr1fma1adj.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/vunary.h>
17 
18 
xnn_f32_vsqrt_ukernel__avx512f_nr1fma1adj_x16(size_t n,const float * x,float * y,const union xnn_f32_sqrt_params params[restrict XNN_MIN_ELEMENTS (1)])19 void xnn_f32_vsqrt_ukernel__avx512f_nr1fma1adj_x16(
20     size_t n,
21     const float* x,
22     float* y,
23     const union xnn_f32_sqrt_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25   assert(n != 0);
26   assert(n % sizeof(float) == 0);
27 
28   const __m512 vhalf = _mm512_set1_ps(params->fma.half);
29   for (; n >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
30     const __m512 vx = _mm512_loadu_ps(x);
31     x += 16;
32 
33     const __m512 vrsqrtx = _mm512_rsqrt14_ps(vx);
34     __m512 vsqrtx = _mm512_mul_ps(vrsqrtx, vx);
35     __m512 vhalfrsqrtx = _mm512_mul_ps(vrsqrtx, vhalf);
36     const __m512 vresidual = _mm512_fnmadd_ps(vsqrtx, vhalfrsqrtx, vhalf);
37     vhalfrsqrtx = _mm512_fmadd_ps(vhalfrsqrtx, vresidual, vhalfrsqrtx);
38     vsqrtx = _mm512_fmadd_ps(vsqrtx, vresidual, vsqrtx);
39     const __m512 vadjustment = _mm512_fnmadd_ps(vsqrtx, vsqrtx, vx);
40     const __m512 vy = _mm512_fmadd_ps(vhalfrsqrtx, vadjustment, vsqrtx);
41 
42     _mm512_storeu_ps(y, vy);
43     y += 16;
44   }
45   if XNN_UNLIKELY(n != 0) {
46     assert(n >= 1 * sizeof(float));
47     assert(n <= 15 * sizeof(float));
48     // Prepare mask for valid 32-bit elements (depends on n).
49     n >>= 2 /* log2(sizeof(float)) */;
50     const __mmask16 vmask = _cvtu32_mask16((uint16_t) ((uint32_t) (UINT32_C(1) << n) - UINT32_C(1)));
51 
52     const __m512 vx = _mm512_maskz_loadu_ps(vmask, x);
53     const __m512 vrsqrtx = _mm512_rsqrt14_ps(vx);
54     __m512 vsqrtx = _mm512_mul_ps(vrsqrtx, vx);
55     __m512 vhalfrsqrtx = _mm512_mul_ps(vrsqrtx, vhalf);
56     const __m512 vresidual = _mm512_fnmadd_ps(vsqrtx, vhalfrsqrtx, vhalf);
57     vhalfrsqrtx = _mm512_fmadd_ps(vhalfrsqrtx, vresidual, vhalfrsqrtx);
58     vsqrtx = _mm512_fmadd_ps(vsqrtx, vresidual, vsqrtx);
59     const __m512 vadjustment = _mm512_fnmadd_ps(vsqrtx, vsqrtx, vx);
60     const __m512 vy = _mm512_fmadd_ps(vhalfrsqrtx, vadjustment, vsqrtx);
61 
62     _mm512_mask_storeu_ps(y, vmask, vy);
63   }
64 }
65