• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_x8(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_x8(
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 >= 8 * sizeof(float); n -= 8 * sizeof(float)) {
30     const float32x4_t vx0123 = vld1q_f32(x); x += 4;
31     const float32x4_t vx4567 = vld1q_f32(x); x += 4;
32 
33     const float32x4_t vrsqrtx0123 = vrsqrteq_f32(vx0123);
34     const float32x4_t vrsqrtx4567 = vrsqrteq_f32(vx4567);
35 
36     float32x4_t vsqrtx0123 = vmulq_f32(vrsqrtx0123, vx0123);
37     float32x4_t vhalfrsqrtx0123 = vmulq_f32(vrsqrtx0123, vhalf);
38     float32x4_t vsqrtx4567 = vmulq_f32(vrsqrtx4567, vx4567);
39     float32x4_t vhalfrsqrtx4567 = vmulq_f32(vrsqrtx4567, vhalf);
40 
41     float32x4_t vresidual0123 = vfmsq_f32(vhalf, vsqrtx0123, vhalfrsqrtx0123);
42     float32x4_t vresidual4567 = vfmsq_f32(vhalf, vsqrtx4567, vhalfrsqrtx4567);
43 
44     vhalfrsqrtx0123 = vfmaq_f32(vhalfrsqrtx0123, vresidual0123, vhalfrsqrtx0123);
45     vsqrtx0123 = vfmaq_f32(vsqrtx0123, vresidual0123, vsqrtx0123);
46     vhalfrsqrtx4567 = vfmaq_f32(vhalfrsqrtx4567, vresidual4567, vhalfrsqrtx4567);
47     vsqrtx4567 = vfmaq_f32(vsqrtx4567, vresidual4567, vsqrtx4567);
48 
49     vresidual0123 = vfmsq_f32(vhalf, vsqrtx0123, vhalfrsqrtx0123);
50     vresidual4567 = vfmsq_f32(vhalf, vsqrtx4567, vhalfrsqrtx4567);
51 
52     vhalfrsqrtx0123 = vfmaq_f32(vhalfrsqrtx0123, vresidual0123, vhalfrsqrtx0123);
53     vsqrtx0123 = vfmaq_f32(vsqrtx0123, vresidual0123, vsqrtx0123);
54     vhalfrsqrtx4567 = vfmaq_f32(vhalfrsqrtx4567, vresidual4567, vhalfrsqrtx4567);
55     vsqrtx4567 = vfmaq_f32(vsqrtx4567, vresidual4567, vsqrtx4567);
56 
57     const float32x4_t vadjustment0123 = vfmsq_f32(vx0123, vsqrtx0123, vsqrtx0123);
58     const float32x4_t vadjustment4567 = vfmsq_f32(vx4567, vsqrtx4567, vsqrtx4567);
59 
60     const float32x4_t vy0123 = vfmaq_f32(vsqrtx0123, vhalfrsqrtx0123, vadjustment0123);
61     const float32x4_t vy4567 = vfmaq_f32(vsqrtx4567, vhalfrsqrtx4567, vadjustment4567);
62 
63     vst1q_f32(y, vy0123); y += 4;
64     vst1q_f32(y, vy4567); y += 4;
65   }
66   for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) {
67     const float32x4_t vx = vld1q_f32(x); x += 4;
68     const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
69     float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
70     float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
71     float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
72     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
73     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
74     vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
75     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
76     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
77     const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
78     const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
79     vst1q_f32(y, vy); y += 4;
80   }
81   if XNN_UNLIKELY(n != 0) {
82     const float32x4_t vx = vld1q_f32(x);
83     const float32x4_t vrsqrtx = vrsqrteq_f32(vx);
84     float32x4_t vsqrtx = vmulq_f32(vrsqrtx, vx);
85     float32x4_t vhalfrsqrtx = vmulq_f32(vrsqrtx, vhalf);
86     float32x4_t vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
87     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
88     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
89     vresidual = vfmsq_f32(vhalf, vsqrtx, vhalfrsqrtx);
90     vhalfrsqrtx = vfmaq_f32(vhalfrsqrtx, vresidual, vhalfrsqrtx);
91     vsqrtx = vfmaq_f32(vsqrtx, vresidual, vsqrtx);
92     const float32x4_t vadjustment = vfmsq_f32(vx, vsqrtx, vsqrtx);
93     const float32x4_t vy = vfmaq_f32(vsqrtx, vhalfrsqrtx, vadjustment);
94 
95     float32x2_t vy_lo = vget_low_f32(vy);
96     if (n & (2 * sizeof(float))) {
97       vst1_f32(y, vy_lo); y += 2;
98       vy_lo = vget_high_f32(vy);
99     }
100     if (n & (1 * sizeof(float))) {
101       vst1_lane_f32(y, vy_lo, 0);
102     }
103   }
104 }
105