xref: /aosp_15_r20/external/XNNPACK/src/f32-gemm/gen/6x2-minmax-neonfma-lane-ld64.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/MRx2-neon-ld64.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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 <arm_neon.h>
13 
14 #include <xnnpack/common.h>
15 #include <xnnpack/gemm.h>
16 
17 
xnn_f32_gemm_minmax_ukernel_6x2__neonfma_lane_ld64(size_t mr,size_t nc,size_t kc,const float * restrict a,size_t a_stride,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_f32_gemm_minmax_ukernel_6x2__neonfma_lane_ld64(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     const float* restrict a,
23     size_t a_stride,
24     const float*restrict w,
25     float*restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(mr != 0);
31   assert(mr <= 6);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38 
39   const float* a0 = a;
40   float* c0 = c;
41   const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
42   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
43   if XNN_UNPREDICTABLE(mr < 2) {
44     a1 = a0;
45     c1 = c0;
46   }
47   const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
48   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 2) {
50     a2 = a1;
51     c2 = c1;
52   }
53   const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
54   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
55   if XNN_UNPREDICTABLE(mr < 4) {
56     a3 = a2;
57     c3 = c2;
58   }
59   const float* a4 = (const float*) ((uintptr_t) a3 + a_stride);
60   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
61   if XNN_UNPREDICTABLE(mr <= 4) {
62     a4 = a3;
63     c4 = c3;
64   }
65   const float* a5 = (const float*) ((uintptr_t) a4 + a_stride);
66   float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
67   if XNN_UNPREDICTABLE(mr != 6) {
68     a5 = a4;
69     c5 = c4;
70   }
71 
72   do {
73     float32x2_t vacc0x01 = vld1_f32(w); w += 2;
74     float32x2_t vacc1x01 = vacc0x01;
75     float32x2_t vacc2x01 = vacc0x01;
76     float32x2_t vacc3x01 = vacc0x01;
77     float32x2_t vacc4x01 = vacc0x01;
78     float32x2_t vacc5x01 = vacc0x01;
79 
80     size_t k = kc;
81     for (; k >= 2 * sizeof(float); k -= 2 * sizeof(float)) {
82       const float32x2_t va0 = vld1_f32(a0); a0 += 2;
83       const float32x2_t va1 = vld1_f32(a1); a1 += 2;
84       const float32x2_t va2 = vld1_f32(a2); a2 += 2;
85       const float32x2_t va3 = vld1_f32(a3); a3 += 2;
86       const float32x2_t va4 = vld1_f32(a4); a4 += 2;
87       const float32x2_t va5 = vld1_f32(a5); a5 += 2;
88 
89       const float32x2_t vb01c0 = vld1_f32(w); w += 2;
90 
91       #if XNN_ARCH_ARM64
92         vacc0x01 = vfma_lane_f32(vacc0x01, vb01c0, va0, 0);
93         vacc1x01 = vfma_lane_f32(vacc1x01, vb01c0, va1, 0);
94         vacc2x01 = vfma_lane_f32(vacc2x01, vb01c0, va2, 0);
95         vacc3x01 = vfma_lane_f32(vacc3x01, vb01c0, va3, 0);
96         vacc4x01 = vfma_lane_f32(vacc4x01, vb01c0, va4, 0);
97         vacc5x01 = vfma_lane_f32(vacc5x01, vb01c0, va5, 0);
98       #else
99         const float32x2_t va0c0 = vdup_lane_f32(va0, 0);
100         const float32x2_t va1c0 = vdup_lane_f32(va1, 0);
101         const float32x2_t va2c0 = vdup_lane_f32(va2, 0);
102         const float32x2_t va3c0 = vdup_lane_f32(va3, 0);
103         const float32x2_t va4c0 = vdup_lane_f32(va4, 0);
104         const float32x2_t va5c0 = vdup_lane_f32(va5, 0);
105         vacc0x01 = vfma_f32(vacc0x01, va0c0, vb01c0);
106         vacc1x01 = vfma_f32(vacc1x01, va1c0, vb01c0);
107         vacc2x01 = vfma_f32(vacc2x01, va2c0, vb01c0);
108         vacc3x01 = vfma_f32(vacc3x01, va3c0, vb01c0);
109         vacc4x01 = vfma_f32(vacc4x01, va4c0, vb01c0);
110         vacc5x01 = vfma_f32(vacc5x01, va5c0, vb01c0);
111       #endif
112       const float32x2_t vb01c1 = vld1_f32(w); w += 2;
113 
114       #if XNN_ARCH_ARM64
115         vacc0x01 = vfma_lane_f32(vacc0x01, vb01c1, va0, 1);
116         vacc1x01 = vfma_lane_f32(vacc1x01, vb01c1, va1, 1);
117         vacc2x01 = vfma_lane_f32(vacc2x01, vb01c1, va2, 1);
118         vacc3x01 = vfma_lane_f32(vacc3x01, vb01c1, va3, 1);
119         vacc4x01 = vfma_lane_f32(vacc4x01, vb01c1, va4, 1);
120         vacc5x01 = vfma_lane_f32(vacc5x01, vb01c1, va5, 1);
121       #else
122         const float32x2_t va0c1 = vdup_lane_f32(va0, 1);
123         const float32x2_t va1c1 = vdup_lane_f32(va1, 1);
124         const float32x2_t va2c1 = vdup_lane_f32(va2, 1);
125         const float32x2_t va3c1 = vdup_lane_f32(va3, 1);
126         const float32x2_t va4c1 = vdup_lane_f32(va4, 1);
127         const float32x2_t va5c1 = vdup_lane_f32(va5, 1);
128         vacc0x01 = vfma_f32(vacc0x01, va0c1, vb01c1);
129         vacc1x01 = vfma_f32(vacc1x01, va1c1, vb01c1);
130         vacc2x01 = vfma_f32(vacc2x01, va2c1, vb01c1);
131         vacc3x01 = vfma_f32(vacc3x01, va3c1, vb01c1);
132         vacc4x01 = vfma_f32(vacc4x01, va4c1, vb01c1);
133         vacc5x01 = vfma_f32(vacc5x01, va5c1, vb01c1);
134       #endif
135     }
136     if XNN_UNLIKELY(k != 0) {
137       const float32x2_t va0 = vld1_dup_f32(a0); a0 += 1;
138       const float32x2_t va1 = vld1_dup_f32(a1); a1 += 1;
139       const float32x2_t va2 = vld1_dup_f32(a2); a2 += 1;
140       const float32x2_t va3 = vld1_dup_f32(a3); a3 += 1;
141       const float32x2_t va4 = vld1_dup_f32(a4); a4 += 1;
142       const float32x2_t va5 = vld1_dup_f32(a5); a5 += 1;
143 
144       const float32x2_t vb01 = vld1_f32(w); w += 2;
145 
146       vacc0x01 = vfma_f32(vacc0x01, va0, vb01);
147       vacc1x01 = vfma_f32(vacc1x01, va1, vb01);
148       vacc2x01 = vfma_f32(vacc2x01, va2, vb01);
149       vacc3x01 = vfma_f32(vacc3x01, va3, vb01);
150       vacc4x01 = vfma_f32(vacc4x01, va4, vb01);
151       vacc5x01 = vfma_f32(vacc5x01, va5, vb01);
152     }
153 
154     const float32x2_t vmax = vld1_dup_f32(&params->scalar.max);
155     vacc0x01 = vmin_f32(vacc0x01, vmax);
156     vacc1x01 = vmin_f32(vacc1x01, vmax);
157     vacc2x01 = vmin_f32(vacc2x01, vmax);
158     vacc3x01 = vmin_f32(vacc3x01, vmax);
159     vacc4x01 = vmin_f32(vacc4x01, vmax);
160     vacc5x01 = vmin_f32(vacc5x01, vmax);
161 
162     const float32x2_t vmin = vld1_dup_f32(&params->scalar.min);
163     vacc0x01 = vmax_f32(vacc0x01, vmin);
164     vacc1x01 = vmax_f32(vacc1x01, vmin);
165     vacc2x01 = vmax_f32(vacc2x01, vmin);
166     vacc3x01 = vmax_f32(vacc3x01, vmin);
167     vacc4x01 = vmax_f32(vacc4x01, vmin);
168     vacc5x01 = vmax_f32(vacc5x01, vmin);
169 
170     if XNN_LIKELY(nc >= 2) {
171       vst1_f32(c0, vacc0x01);
172       c0 = (float*) ((uintptr_t) c0 + cn_stride);
173       vst1_f32(c1, vacc1x01);
174       c1 = (float*) ((uintptr_t) c1 + cn_stride);
175       vst1_f32(c2, vacc2x01);
176       c2 = (float*) ((uintptr_t) c2 + cn_stride);
177       vst1_f32(c3, vacc3x01);
178       c3 = (float*) ((uintptr_t) c3 + cn_stride);
179       vst1_f32(c4, vacc4x01);
180       c4 = (float*) ((uintptr_t) c4 + cn_stride);
181       vst1_f32(c5, vacc5x01);
182       c5 = (float*) ((uintptr_t) c5 + cn_stride);
183 
184       a0 = (const float*) ((uintptr_t) a0 - kc);
185       a1 = (const float*) ((uintptr_t) a1 - kc);
186       a2 = (const float*) ((uintptr_t) a2 - kc);
187       a3 = (const float*) ((uintptr_t) a3 - kc);
188       a4 = (const float*) ((uintptr_t) a4 - kc);
189       a5 = (const float*) ((uintptr_t) a5 - kc);
190 
191       nc -= 2;
192     } else {
193       assert(nc == 1);
194       vst1_lane_f32(c0, vacc0x01, 0);
195       vst1_lane_f32(c1, vacc1x01, 0);
196       vst1_lane_f32(c2, vacc2x01, 0);
197       vst1_lane_f32(c3, vacc3x01, 0);
198       vst1_lane_f32(c4, vacc4x01, 0);
199       vst1_lane_f32(c5, vacc5x01, 0);
200 
201       nc = 0;
202     }
203   } while (nc != 0);
204 }
205