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_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__neonfma_nr2fma1adj_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)]) 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 >= 16 * sizeof(float); n -= 16 * sizeof(float)) {
30 const float32x4_t vx0123 = vld1q_f32(x); x += 4;
31 const float32x4_t vx4567 = vld1q_f32(x); x += 4;
32 const float32x4_t vx89AB = vld1q_f32(x); x += 4;
33 const float32x4_t vxCDEF = vld1q_f32(x); x += 4;
34
35 const float32x4_t vrsqrtx0123 = vrsqrteq_f32(vx0123);
36 const float32x4_t vrsqrtx4567 = vrsqrteq_f32(vx4567);
37 const float32x4_t vrsqrtx89AB = vrsqrteq_f32(vx89AB);
38 const float32x4_t vrsqrtxCDEF = vrsqrteq_f32(vxCDEF);
39
40 float32x4_t vsqrtx0123 = vmulq_f32(vrsqrtx0123, vx0123);
41 float32x4_t vhalfrsqrtx0123 = vmulq_f32(vrsqrtx0123, vhalf);
42 float32x4_t vsqrtx4567 = vmulq_f32(vrsqrtx4567, vx4567);
43 float32x4_t vhalfrsqrtx4567 = vmulq_f32(vrsqrtx4567, vhalf);
44 float32x4_t vsqrtx89AB = vmulq_f32(vrsqrtx89AB, vx89AB);
45 float32x4_t vhalfrsqrtx89AB = vmulq_f32(vrsqrtx89AB, vhalf);
46 float32x4_t vsqrtxCDEF = vmulq_f32(vrsqrtxCDEF, vxCDEF);
47 float32x4_t vhalfrsqrtxCDEF = vmulq_f32(vrsqrtxCDEF, vhalf);
48
49 float32x4_t vresidual0123 = vfmsq_f32(vhalf, vsqrtx0123, vhalfrsqrtx0123);
50 float32x4_t vresidual4567 = vfmsq_f32(vhalf, vsqrtx4567, vhalfrsqrtx4567);
51 float32x4_t vresidual89AB = vfmsq_f32(vhalf, vsqrtx89AB, vhalfrsqrtx89AB);
52 float32x4_t vresidualCDEF = vfmsq_f32(vhalf, vsqrtxCDEF, vhalfrsqrtxCDEF);
53
54 vhalfrsqrtx0123 = vfmaq_f32(vhalfrsqrtx0123, vresidual0123, vhalfrsqrtx0123);
55 vsqrtx0123 = vfmaq_f32(vsqrtx0123, vresidual0123, vsqrtx0123);
56 vhalfrsqrtx4567 = vfmaq_f32(vhalfrsqrtx4567, vresidual4567, vhalfrsqrtx4567);
57 vsqrtx4567 = vfmaq_f32(vsqrtx4567, vresidual4567, vsqrtx4567);
58 vhalfrsqrtx89AB = vfmaq_f32(vhalfrsqrtx89AB, vresidual89AB, vhalfrsqrtx89AB);
59 vsqrtx89AB = vfmaq_f32(vsqrtx89AB, vresidual89AB, vsqrtx89AB);
60 vhalfrsqrtxCDEF = vfmaq_f32(vhalfrsqrtxCDEF, vresidualCDEF, vhalfrsqrtxCDEF);
61 vsqrtxCDEF = vfmaq_f32(vsqrtxCDEF, vresidualCDEF, vsqrtxCDEF);
62
63 vresidual0123 = vfmsq_f32(vhalf, vsqrtx0123, vhalfrsqrtx0123);
64 vresidual4567 = vfmsq_f32(vhalf, vsqrtx4567, vhalfrsqrtx4567);
65 vresidual89AB = vfmsq_f32(vhalf, vsqrtx89AB, vhalfrsqrtx89AB);
66 vresidualCDEF = vfmsq_f32(vhalf, vsqrtxCDEF, vhalfrsqrtxCDEF);
67
68 vhalfrsqrtx0123 = vfmaq_f32(vhalfrsqrtx0123, vresidual0123, vhalfrsqrtx0123);
69 vsqrtx0123 = vfmaq_f32(vsqrtx0123, vresidual0123, vsqrtx0123);
70 vhalfrsqrtx4567 = vfmaq_f32(vhalfrsqrtx4567, vresidual4567, vhalfrsqrtx4567);
71 vsqrtx4567 = vfmaq_f32(vsqrtx4567, vresidual4567, vsqrtx4567);
72 vhalfrsqrtx89AB = vfmaq_f32(vhalfrsqrtx89AB, vresidual89AB, vhalfrsqrtx89AB);
73 vsqrtx89AB = vfmaq_f32(vsqrtx89AB, vresidual89AB, vsqrtx89AB);
74 vhalfrsqrtxCDEF = vfmaq_f32(vhalfrsqrtxCDEF, vresidualCDEF, vhalfrsqrtxCDEF);
75 vsqrtxCDEF = vfmaq_f32(vsqrtxCDEF, vresidualCDEF, vsqrtxCDEF);
76
77 const float32x4_t vadjustment0123 = vfmsq_f32(vx0123, vsqrtx0123, vsqrtx0123);
78 const float32x4_t vadjustment4567 = vfmsq_f32(vx4567, vsqrtx4567, vsqrtx4567);
79 const float32x4_t vadjustment89AB = vfmsq_f32(vx89AB, vsqrtx89AB, vsqrtx89AB);
80 const float32x4_t vadjustmentCDEF = vfmsq_f32(vxCDEF, vsqrtxCDEF, vsqrtxCDEF);
81
82 const float32x4_t vy0123 = vfmaq_f32(vsqrtx0123, vhalfrsqrtx0123, vadjustment0123);
83 const float32x4_t vy4567 = vfmaq_f32(vsqrtx4567, vhalfrsqrtx4567, vadjustment4567);
84 const float32x4_t vy89AB = vfmaq_f32(vsqrtx89AB, vhalfrsqrtx89AB, vadjustment89AB);
85 const float32x4_t vyCDEF = vfmaq_f32(vsqrtxCDEF, vhalfrsqrtxCDEF, vadjustmentCDEF);
86
87 vst1q_f32(y, vy0123); y += 4;
88 vst1q_f32(y, vy4567); y += 4;
89 vst1q_f32(y, vy89AB); y += 4;
90 vst1q_f32(y, vyCDEF); y += 4;
91 }
92 for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
93 const float32x4_t vx = vld1q_f32(x); x += 4;
94 const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
95 float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
96 float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
97 float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
98 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
99 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
100 vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
101 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
102 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
103 const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
104 const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
105 vst1q_f32(y, vy); y += 4;
106 }
107 if XNN_UNLIKELY(n != 0) {
108 const float32x4_t vx = vld1q_f32(x);
109 const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
110 float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
111 float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
112 float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
113 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
114 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
115 vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
116 vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
117 vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
118 const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
119 const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
120
121 float32x2_t vy_lo = vget_low_f32(vy);
122 if (n & (2 * sizeof(float))) {
123 vst1_f32(y, vy_lo); y += 2;
124 vy_lo = vget_high_f32(vy);
125 }
126 if (n & (1 * sizeof(float))) {
127 vst1_lane_f32(y, vy_lo, 0);
128 }
129 }
130 }
131