xref: /aosp_15_r20/external/XNNPACK/src/f32-ppmm/gen/8x8-minmax-neon.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-ppmm/neon.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/ppmm.h>
16 
17 
xnn_f32_ppmm_minmax_ukernel_8x8__neon(size_t mr,size_t nc,size_t kc,const float * restrict a,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_ppmm_minmax_ukernel_8x8__neon(
19   size_t mr,
20   size_t nc,
21   size_t kc,
22   const float*restrict a,
23   const float*restrict w,
24   float*restrict c,
25   size_t cm_stride,
26   size_t cn_stride,
27   const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29   assert(mr != 0);
30   assert(mr <= 8);
31   assert(nc != 0);
32   assert(kc != 0);
33   assert(kc % sizeof(float) == 0);
34 
35   float* c0 = c;
36   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
37   if XNN_UNPREDICTABLE(mr < 2) {
38     c1 = c0;
39   }
40   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
41   if XNN_UNPREDICTABLE(mr <= 2) {
42     c2 = c1;
43   }
44   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
45   if XNN_UNPREDICTABLE(mr < 4) {
46     c3 = c2;
47   }
48   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 4) {
50     c4 = c3;
51   }
52   float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
53   if XNN_UNPREDICTABLE(mr < 6) {
54     c5 = c4;
55   }
56   float* c6 = (float*) ((uintptr_t) c5 + cm_stride);
57   if XNN_UNPREDICTABLE(mr <= 6) {
58     c6 = c5;
59   }
60   float* c7 = (float*) ((uintptr_t) c6 + cm_stride);
61   if XNN_UNPREDICTABLE(mr != 8) {
62     c7 = c6;
63   }
64 
65   do {
66     float32x4_t vacc0x0123 = vld1q_f32(w); w += 4;
67     float32x4_t vacc0x4567 = vld1q_f32(w); w += 4;
68     float32x4_t vacc1x0123 = vacc0x0123;
69     float32x4_t vacc1x4567 = vacc0x4567;
70     float32x4_t vacc2x0123 = vacc0x0123;
71     float32x4_t vacc2x4567 = vacc0x4567;
72     float32x4_t vacc3x0123 = vacc0x0123;
73     float32x4_t vacc3x4567 = vacc0x4567;
74     float32x4_t vacc4x0123 = vacc0x0123;
75     float32x4_t vacc4x4567 = vacc0x4567;
76     float32x4_t vacc5x0123 = vacc0x0123;
77     float32x4_t vacc5x4567 = vacc0x4567;
78     float32x4_t vacc6x0123 = vacc0x0123;
79     float32x4_t vacc6x4567 = vacc0x4567;
80     float32x4_t vacc7x0123 = vacc0x0123;
81     float32x4_t vacc7x4567 = vacc0x4567;
82 
83     size_t k = kc;
84     do {
85       const float32x4_t va0123 = vld1q_f32(a); a += 4;
86       const float32x4_t va4567 = vld1q_f32(a); a += 4;
87 
88       const float32x4_t vb0123 = vld1q_f32(w); w += 4;
89       const float32x4_t vb4567 = vld1q_f32(w); w += 4;
90 
91       vacc0x0123 = vmlaq_lane_f32(vacc0x0123, vb0123, vget_low_f32(va0123), 0);
92       vacc1x0123 = vmlaq_lane_f32(vacc1x0123, vb0123, vget_low_f32(va0123), 1);
93       vacc2x0123 = vmlaq_lane_f32(vacc2x0123, vb0123, vget_high_f32(va0123), 0);
94       vacc3x0123 = vmlaq_lane_f32(vacc3x0123, vb0123, vget_high_f32(va0123), 1);
95       vacc4x0123 = vmlaq_lane_f32(vacc4x0123, vb0123, vget_low_f32(va4567), 0);
96       vacc5x0123 = vmlaq_lane_f32(vacc5x0123, vb0123, vget_low_f32(va4567), 1);
97       vacc6x0123 = vmlaq_lane_f32(vacc6x0123, vb0123, vget_high_f32(va4567), 0);
98       vacc7x0123 = vmlaq_lane_f32(vacc7x0123, vb0123, vget_high_f32(va4567), 1);
99       vacc0x4567 = vmlaq_lane_f32(vacc0x4567, vb4567, vget_low_f32(va0123), 0);
100       vacc1x4567 = vmlaq_lane_f32(vacc1x4567, vb4567, vget_low_f32(va0123), 1);
101       vacc2x4567 = vmlaq_lane_f32(vacc2x4567, vb4567, vget_high_f32(va0123), 0);
102       vacc3x4567 = vmlaq_lane_f32(vacc3x4567, vb4567, vget_high_f32(va0123), 1);
103       vacc4x4567 = vmlaq_lane_f32(vacc4x4567, vb4567, vget_low_f32(va4567), 0);
104       vacc5x4567 = vmlaq_lane_f32(vacc5x4567, vb4567, vget_low_f32(va4567), 1);
105       vacc6x4567 = vmlaq_lane_f32(vacc6x4567, vb4567, vget_high_f32(va4567), 0);
106       vacc7x4567 = vmlaq_lane_f32(vacc7x4567, vb4567, vget_high_f32(va4567), 1);
107 
108       k -= sizeof(float);
109     } while (k != 0);
110 
111     const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
112     vacc0x0123 = vminq_f32(vacc0x0123, vmax);
113     vacc1x0123 = vminq_f32(vacc1x0123, vmax);
114     vacc2x0123 = vminq_f32(vacc2x0123, vmax);
115     vacc3x0123 = vminq_f32(vacc3x0123, vmax);
116     vacc4x0123 = vminq_f32(vacc4x0123, vmax);
117     vacc5x0123 = vminq_f32(vacc5x0123, vmax);
118     vacc6x0123 = vminq_f32(vacc6x0123, vmax);
119     vacc7x0123 = vminq_f32(vacc7x0123, vmax);
120     vacc0x4567 = vminq_f32(vacc0x4567, vmax);
121     vacc1x4567 = vminq_f32(vacc1x4567, vmax);
122     vacc2x4567 = vminq_f32(vacc2x4567, vmax);
123     vacc3x4567 = vminq_f32(vacc3x4567, vmax);
124     vacc4x4567 = vminq_f32(vacc4x4567, vmax);
125     vacc5x4567 = vminq_f32(vacc5x4567, vmax);
126     vacc6x4567 = vminq_f32(vacc6x4567, vmax);
127     vacc7x4567 = vminq_f32(vacc7x4567, vmax);
128 
129     const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
130     vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
131     vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
132     vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
133     vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
134     vacc4x0123 = vmaxq_f32(vacc4x0123, vmin);
135     vacc5x0123 = vmaxq_f32(vacc5x0123, vmin);
136     vacc6x0123 = vmaxq_f32(vacc6x0123, vmin);
137     vacc7x0123 = vmaxq_f32(vacc7x0123, vmin);
138     vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
139     vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
140     vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
141     vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
142     vacc4x4567 = vmaxq_f32(vacc4x4567, vmin);
143     vacc5x4567 = vmaxq_f32(vacc5x4567, vmin);
144     vacc6x4567 = vmaxq_f32(vacc6x4567, vmin);
145     vacc7x4567 = vmaxq_f32(vacc7x4567, vmin);
146 
147     if XNN_LIKELY(nc >= 8) {
148       vst1q_f32(c7, vacc7x0123);
149       vst1q_f32(c7 + 4, vacc7x4567);
150       c7 = (float*) ((uintptr_t) c7 + cn_stride);
151       vst1q_f32(c6, vacc6x0123);
152       vst1q_f32(c6 + 4, vacc6x4567);
153       c6 = (float*) ((uintptr_t) c6 + cn_stride);
154       vst1q_f32(c5, vacc5x0123);
155       vst1q_f32(c5 + 4, vacc5x4567);
156       c5 = (float*) ((uintptr_t) c5 + cn_stride);
157       vst1q_f32(c4, vacc4x0123);
158       vst1q_f32(c4 + 4, vacc4x4567);
159       c4 = (float*) ((uintptr_t) c4 + cn_stride);
160       vst1q_f32(c3, vacc3x0123);
161       vst1q_f32(c3 + 4, vacc3x4567);
162       c3 = (float*) ((uintptr_t) c3 + cn_stride);
163       vst1q_f32(c2, vacc2x0123);
164       vst1q_f32(c2 + 4, vacc2x4567);
165       c2 = (float*) ((uintptr_t) c2 + cn_stride);
166       vst1q_f32(c1, vacc1x0123);
167       vst1q_f32(c1 + 4, vacc1x4567);
168       c1 = (float*) ((uintptr_t) c1 + cn_stride);
169       vst1q_f32(c0, vacc0x0123);
170       vst1q_f32(c0 + 4, vacc0x4567);
171       c0 = (float*) ((uintptr_t) c0 + cn_stride);
172 
173       a = (const float*) ((uintptr_t) a - kc * 8);
174 
175       nc -= 8;
176     } else {
177       if (nc & 4) {
178         vst1q_f32(c7, vacc7x0123); c7 += 4;
179         vst1q_f32(c6, vacc6x0123); c6 += 4;
180         vst1q_f32(c5, vacc5x0123); c5 += 4;
181         vst1q_f32(c4, vacc4x0123); c4 += 4;
182         vst1q_f32(c3, vacc3x0123); c3 += 4;
183         vst1q_f32(c2, vacc2x0123); c2 += 4;
184         vst1q_f32(c1, vacc1x0123); c1 += 4;
185         vst1q_f32(c0, vacc0x0123); c0 += 4;
186 
187         vacc7x0123 = vacc7x4567;
188         vacc6x0123 = vacc6x4567;
189         vacc5x0123 = vacc5x4567;
190         vacc4x0123 = vacc4x4567;
191         vacc3x0123 = vacc3x4567;
192         vacc2x0123 = vacc2x4567;
193         vacc1x0123 = vacc1x4567;
194         vacc0x0123 = vacc0x4567;
195       }
196       float32x2_t vacc7x01 = vget_low_f32(vacc7x0123);
197       float32x2_t vacc6x01 = vget_low_f32(vacc6x0123);
198       float32x2_t vacc5x01 = vget_low_f32(vacc5x0123);
199       float32x2_t vacc4x01 = vget_low_f32(vacc4x0123);
200       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
201       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
202       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
203       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
204       if (nc & 2) {
205         vst1_f32(c7, vacc7x01); c7 += 2;
206         vst1_f32(c6, vacc6x01); c6 += 2;
207         vst1_f32(c5, vacc5x01); c5 += 2;
208         vst1_f32(c4, vacc4x01); c4 += 2;
209         vst1_f32(c3, vacc3x01); c3 += 2;
210         vst1_f32(c2, vacc2x01); c2 += 2;
211         vst1_f32(c1, vacc1x01); c1 += 2;
212         vst1_f32(c0, vacc0x01); c0 += 2;
213 
214         vacc7x01 = vget_high_f32(vacc7x0123);
215         vacc6x01 = vget_high_f32(vacc6x0123);
216         vacc5x01 = vget_high_f32(vacc5x0123);
217         vacc4x01 = vget_high_f32(vacc4x0123);
218         vacc3x01 = vget_high_f32(vacc3x0123);
219         vacc2x01 = vget_high_f32(vacc2x0123);
220         vacc1x01 = vget_high_f32(vacc1x0123);
221         vacc0x01 = vget_high_f32(vacc0x0123);
222       }
223       if (nc & 1) {
224         vst1_lane_f32(c7, vacc7x01, 0);
225         vst1_lane_f32(c6, vacc6x01, 0);
226         vst1_lane_f32(c5, vacc5x01, 0);
227         vst1_lane_f32(c4, vacc4x01, 0);
228         vst1_lane_f32(c3, vacc3x01, 0);
229         vst1_lane_f32(c2, vacc2x01, 0);
230         vst1_lane_f32(c1, vacc1x01, 0);
231         vst1_lane_f32(c0, vacc0x01, 0);
232       }
233 
234       nc = 0;
235     }
236   } while (nc != 0);
237 }
238