1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vsqrt/neonfma-nr2fma1adj.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 #include <math.h>
12
13 #include <arm_neon.h>
14
15 #include <xnnpack/common.h>
16 #include <xnnpack/vunary.h>
17
18
xnn_f32_vsqrt_ukernel__neonfma_nr2fma1adj_x4(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__neonfma_nr2fma1adj_x4(
20 size_t n,
21 const float* x,
22 float* y,
23 const union xnn_f32_sqrt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(n != 0);
26 assert(n % sizeof(float) == 0);
27
28 const float32x4_t vhalf = vmovq_n_f32(0.5f);
29 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
30 const float32x4_t vx = vld1q_f32(x); x += 4;
31 const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
32 float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
33 float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
34 float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
35 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
36 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
37 vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
38 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
39 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
40 const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
41 const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
42 vst1q_f32(y, vy); y += 4;
43 }
44 if XNN_UNLIKELY(n != 0) {
45 const float32x4_t vx = vld1q_f32(x);
46 const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
47 float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
48 float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
49 float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
50 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
51 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
52 vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
53 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
54 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
55 const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
56 const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
57
58 float32x2_t vy_lo = vget_low_f32(vy);
59 if (n & (2 * sizeof(float))) {
60 vst1_f32(y, vy_lo); y += 2;
61 vy_lo = vget_high_f32(vy);
62 }
63 if (n & (1 * sizeof(float))) {
64 vst1_lane_f32(y, vy_lo, 0);
65 }
66 }
67 }
68