xref: /aosp_15_r20/external/XNNPACK/src/f32-vsqrt/gen/neonfma-nr2fma1adj-x12.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1*4bdc9457SAndroid Build Coastguard Worker // Auto-generated file. Do not edit!
2*4bdc9457SAndroid Build Coastguard Worker //   Template: src/f32-vsqrt/neonfma-nr2fma1adj.c.in
3*4bdc9457SAndroid Build Coastguard Worker //   Generator: tools/xngen
4*4bdc9457SAndroid Build Coastguard Worker //
5*4bdc9457SAndroid Build Coastguard Worker // Copyright 2020 Google LLC
6*4bdc9457SAndroid Build Coastguard Worker //
7*4bdc9457SAndroid Build Coastguard Worker // This source code is licensed under the BSD-style license found in the
8*4bdc9457SAndroid Build Coastguard Worker // LICENSE file in the root directory of this source tree.
9*4bdc9457SAndroid Build Coastguard Worker 
10*4bdc9457SAndroid Build Coastguard Worker #include <assert.h>
11*4bdc9457SAndroid Build Coastguard Worker #include <math.h>
12*4bdc9457SAndroid Build Coastguard Worker 
13*4bdc9457SAndroid Build Coastguard Worker #include <arm_neon.h>
14*4bdc9457SAndroid Build Coastguard Worker 
15*4bdc9457SAndroid Build Coastguard Worker #include <xnnpack/common.h>
16*4bdc9457SAndroid Build Coastguard Worker #include <xnnpack/vunary.h>
17*4bdc9457SAndroid Build Coastguard Worker 
18*4bdc9457SAndroid Build Coastguard Worker 
xnn_f32_vsqrt_ukernel__neonfma_nr2fma1adj_x12(size_t n,const float * x,float * y,const union xnn_f32_sqrt_params params[restrict XNN_MIN_ELEMENTS (1)])19*4bdc9457SAndroid Build Coastguard Worker void xnn_f32_vsqrt_ukernel__neonfma_nr2fma1adj_x12(
20*4bdc9457SAndroid Build Coastguard Worker     size_t n,
21*4bdc9457SAndroid Build Coastguard Worker     const float* x,
22*4bdc9457SAndroid Build Coastguard Worker     float* y,
23*4bdc9457SAndroid Build Coastguard Worker     const union xnn_f32_sqrt_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24*4bdc9457SAndroid Build Coastguard Worker {
25*4bdc9457SAndroid Build Coastguard Worker   assert(n != 0);
26*4bdc9457SAndroid Build Coastguard Worker   assert(n % sizeof(float) == 0);
27*4bdc9457SAndroid Build Coastguard Worker 
28*4bdc9457SAndroid Build Coastguard Worker   const float32x4_t vhalf = vmovq_n_f32(0.5f);
29*4bdc9457SAndroid Build Coastguard Worker   for (; n >= 12 * sizeof(float); n -= 12 * sizeof(float)) {
30*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vx0123 = vld1q_f32(x); x += 4;
31*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vx4567 = vld1q_f32(x); x += 4;
32*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vx89AB = vld1q_f32(x); x += 4;
33*4bdc9457SAndroid Build Coastguard Worker 
34*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vrsqrtx0123 = vrsqrteq_f32(vx0123);
35*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vrsqrtx4567 = vrsqrteq_f32(vx4567);
36*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vrsqrtx89AB = vrsqrteq_f32(vx89AB);
37*4bdc9457SAndroid Build Coastguard Worker 
38*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vsqrtx0123 = vmulq_f32(vrsqrtx0123, vx0123);
39*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vhalfrsqrtx0123 = vmulq_f32(vrsqrtx0123, vhalf);
40*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vsqrtx4567 = vmulq_f32(vrsqrtx4567, vx4567);
41*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vhalfrsqrtx4567 = vmulq_f32(vrsqrtx4567, vhalf);
42*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vsqrtx89AB = vmulq_f32(vrsqrtx89AB, vx89AB);
43*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vhalfrsqrtx89AB = vmulq_f32(vrsqrtx89AB, vhalf);
44*4bdc9457SAndroid Build Coastguard Worker 
45*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vresidual0123 = vfmsq_f32(vhalf, vsqrtx0123, vhalfrsqrtx0123);
46*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vresidual4567 = vfmsq_f32(vhalf, vsqrtx4567, vhalfrsqrtx4567);
47*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vresidual89AB = vfmsq_f32(vhalf, vsqrtx89AB, vhalfrsqrtx89AB);
48*4bdc9457SAndroid Build Coastguard Worker 
49*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx0123 = vfmaq_f32(vhalfrsqrtx0123, vresidual0123, vhalfrsqrtx0123);
50*4bdc9457SAndroid Build Coastguard Worker     vsqrtx0123 = vfmaq_f32(vsqrtx0123, vresidual0123, vsqrtx0123);
51*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx4567 = vfmaq_f32(vhalfrsqrtx4567, vresidual4567, vhalfrsqrtx4567);
52*4bdc9457SAndroid Build Coastguard Worker     vsqrtx4567 = vfmaq_f32(vsqrtx4567, vresidual4567, vsqrtx4567);
53*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx89AB = vfmaq_f32(vhalfrsqrtx89AB, vresidual89AB, vhalfrsqrtx89AB);
54*4bdc9457SAndroid Build Coastguard Worker     vsqrtx89AB = vfmaq_f32(vsqrtx89AB, vresidual89AB, vsqrtx89AB);
55*4bdc9457SAndroid Build Coastguard Worker 
56*4bdc9457SAndroid Build Coastguard Worker     vresidual0123 = vfmsq_f32(vhalf, vsqrtx0123, vhalfrsqrtx0123);
57*4bdc9457SAndroid Build Coastguard Worker     vresidual4567 = vfmsq_f32(vhalf, vsqrtx4567, vhalfrsqrtx4567);
58*4bdc9457SAndroid Build Coastguard Worker     vresidual89AB = vfmsq_f32(vhalf, vsqrtx89AB, vhalfrsqrtx89AB);
59*4bdc9457SAndroid Build Coastguard Worker 
60*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx0123 = vfmaq_f32(vhalfrsqrtx0123, vresidual0123, vhalfrsqrtx0123);
61*4bdc9457SAndroid Build Coastguard Worker     vsqrtx0123 = vfmaq_f32(vsqrtx0123, vresidual0123, vsqrtx0123);
62*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx4567 = vfmaq_f32(vhalfrsqrtx4567, vresidual4567, vhalfrsqrtx4567);
63*4bdc9457SAndroid Build Coastguard Worker     vsqrtx4567 = vfmaq_f32(vsqrtx4567, vresidual4567, vsqrtx4567);
64*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx89AB = vfmaq_f32(vhalfrsqrtx89AB, vresidual89AB, vhalfrsqrtx89AB);
65*4bdc9457SAndroid Build Coastguard Worker     vsqrtx89AB = vfmaq_f32(vsqrtx89AB, vresidual89AB, vsqrtx89AB);
66*4bdc9457SAndroid Build Coastguard Worker 
67*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vadjustment0123 = vfmsq_f32(vx0123, vsqrtx0123, vsqrtx0123);
68*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vadjustment4567 = vfmsq_f32(vx4567, vsqrtx4567, vsqrtx4567);
69*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vadjustment89AB = vfmsq_f32(vx89AB, vsqrtx89AB, vsqrtx89AB);
70*4bdc9457SAndroid Build Coastguard Worker 
71*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vy0123 = vfmaq_f32(vsqrtx0123, vhalfrsqrtx0123, vadjustment0123);
72*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vy4567 = vfmaq_f32(vsqrtx4567, vhalfrsqrtx4567, vadjustment4567);
73*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vy89AB = vfmaq_f32(vsqrtx89AB, vhalfrsqrtx89AB, vadjustment89AB);
74*4bdc9457SAndroid Build Coastguard Worker 
75*4bdc9457SAndroid Build Coastguard Worker     vst1q_f32(y, vy0123); y += 4;
76*4bdc9457SAndroid Build Coastguard Worker     vst1q_f32(y, vy4567); y += 4;
77*4bdc9457SAndroid Build Coastguard Worker     vst1q_f32(y, vy89AB); y += 4;
78*4bdc9457SAndroid Build Coastguard Worker   }
79*4bdc9457SAndroid Build Coastguard Worker   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
80*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vx = vld1q_f32(x); x += 4;
81*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
82*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
83*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
84*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
85*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
86*4bdc9457SAndroid Build Coastguard Worker     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
87*4bdc9457SAndroid Build Coastguard Worker     vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
88*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
89*4bdc9457SAndroid Build Coastguard Worker     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
90*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
91*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
92*4bdc9457SAndroid Build Coastguard Worker     vst1q_f32(y, vy); y += 4;
93*4bdc9457SAndroid Build Coastguard Worker   }
94*4bdc9457SAndroid Build Coastguard Worker   if XNN_UNLIKELY(n != 0) {
95*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vx = vld1q_f32(x);
96*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
97*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
98*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
99*4bdc9457SAndroid Build Coastguard Worker     float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
100*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
101*4bdc9457SAndroid Build Coastguard Worker     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
102*4bdc9457SAndroid Build Coastguard Worker     vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
103*4bdc9457SAndroid Build Coastguard Worker     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
104*4bdc9457SAndroid Build Coastguard Worker     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
105*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
106*4bdc9457SAndroid Build Coastguard Worker     const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
107*4bdc9457SAndroid Build Coastguard Worker 
108*4bdc9457SAndroid Build Coastguard Worker     float32x2_t vy_lo = vget_low_f32(vy);
109*4bdc9457SAndroid Build Coastguard Worker     if (n & (2 * sizeof(float))) {
110*4bdc9457SAndroid Build Coastguard Worker       vst1_f32(y, vy_lo); y += 2;
111*4bdc9457SAndroid Build Coastguard Worker       vy_lo = vget_high_f32(vy);
112*4bdc9457SAndroid Build Coastguard Worker     }
113*4bdc9457SAndroid Build Coastguard Worker     if (n & (1 * sizeof(float))) {
114*4bdc9457SAndroid Build Coastguard Worker       vst1_lane_f32(y, vy_lo, 0);
115*4bdc9457SAndroid Build Coastguard Worker     }
116*4bdc9457SAndroid Build Coastguard Worker   }
117*4bdc9457SAndroid Build Coastguard Worker }
118