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_4x8__neonfma(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_4x8__neonfma(
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 <= 4);
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 
49   do {
50     float32x4_t vacc0x0123 = vld1q_f32(w); w += 4;
51     float32x4_t vacc0x4567 = vld1q_f32(w); w += 4;
52     float32x4_t vacc1x0123 = vacc0x0123;
53     float32x4_t vacc1x4567 = vacc0x4567;
54     float32x4_t vacc2x0123 = vacc0x0123;
55     float32x4_t vacc2x4567 = vacc0x4567;
56     float32x4_t vacc3x0123 = vacc0x0123;
57     float32x4_t vacc3x4567 = vacc0x4567;
58 
59     size_t k = kc;
60     do {
61       const float32x4_t va0123 = vld1q_f32(a); a += 4;
62 
63       const float32x4_t vb0123 = vld1q_f32(w); w += 4;
64       const float32x4_t vb4567 = vld1q_f32(w); w += 4;
65 
66       #if XNN_ARCH_ARM64
67         vacc0x0123 = vfmaq_laneq_f32(vacc0x0123, vb0123, va0123, 0);
68         vacc1x0123 = vfmaq_laneq_f32(vacc1x0123, vb0123, va0123, 1);
69         vacc2x0123 = vfmaq_laneq_f32(vacc2x0123, vb0123, va0123, 2);
70         vacc3x0123 = vfmaq_laneq_f32(vacc3x0123, vb0123, va0123, 3);
71         vacc0x4567 = vfmaq_laneq_f32(vacc0x4567, vb4567, va0123, 0);
72         vacc1x4567 = vfmaq_laneq_f32(vacc1x4567, vb4567, va0123, 1);
73         vacc2x4567 = vfmaq_laneq_f32(vacc2x4567, vb4567, va0123, 2);
74         vacc3x4567 = vfmaq_laneq_f32(vacc3x4567, vb4567, va0123, 3);
75       #else
76         const float32x4_t va0000 = vdupq_lane_f32(vget_low_f32(va0123), 0);
77         const float32x4_t va1111 = vdupq_lane_f32(vget_low_f32(va0123), 1);
78         const float32x4_t va2222 = vdupq_lane_f32(vget_high_f32(va0123), 0);
79         const float32x4_t va3333 = vdupq_lane_f32(vget_high_f32(va0123), 1);
80 
81         vacc0x0123 = vfmaq_f32(vacc0x0123, va0000, vb0123);
82         vacc1x0123 = vfmaq_f32(vacc1x0123, va1111, vb0123);
83         vacc2x0123 = vfmaq_f32(vacc2x0123, va2222, vb0123);
84         vacc3x0123 = vfmaq_f32(vacc3x0123, va3333, vb0123);
85         vacc0x4567 = vfmaq_f32(vacc0x4567, va0000, vb4567);
86         vacc1x4567 = vfmaq_f32(vacc1x4567, va1111, vb4567);
87         vacc2x4567 = vfmaq_f32(vacc2x4567, va2222, vb4567);
88         vacc3x4567 = vfmaq_f32(vacc3x4567, va3333, vb4567);
89       #endif
90 
91       k -= sizeof(float);
92     } while (k != 0);
93 
94     const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
95     vacc0x0123 = vminq_f32(vacc0x0123, vmax);
96     vacc1x0123 = vminq_f32(vacc1x0123, vmax);
97     vacc2x0123 = vminq_f32(vacc2x0123, vmax);
98     vacc3x0123 = vminq_f32(vacc3x0123, vmax);
99     vacc0x4567 = vminq_f32(vacc0x4567, vmax);
100     vacc1x4567 = vminq_f32(vacc1x4567, vmax);
101     vacc2x4567 = vminq_f32(vacc2x4567, vmax);
102     vacc3x4567 = vminq_f32(vacc3x4567, vmax);
103 
104     const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
105     vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
106     vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
107     vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
108     vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
109     vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
110     vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
111     vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
112     vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
113 
114     if XNN_LIKELY(nc >= 8) {
115       vst1q_f32(c3, vacc3x0123);
116       vst1q_f32(c3 + 4, vacc3x4567);
117       c3 = (float*) ((uintptr_t) c3 + cn_stride);
118       vst1q_f32(c2, vacc2x0123);
119       vst1q_f32(c2 + 4, vacc2x4567);
120       c2 = (float*) ((uintptr_t) c2 + cn_stride);
121       vst1q_f32(c1, vacc1x0123);
122       vst1q_f32(c1 + 4, vacc1x4567);
123       c1 = (float*) ((uintptr_t) c1 + cn_stride);
124       vst1q_f32(c0, vacc0x0123);
125       vst1q_f32(c0 + 4, vacc0x4567);
126       c0 = (float*) ((uintptr_t) c0 + cn_stride);
127 
128       a = (const float*) ((uintptr_t) a - kc * 4);
129 
130       nc -= 8;
131     } else {
132       if (nc & 4) {
133         vst1q_f32(c3, vacc3x0123); c3 += 4;
134         vst1q_f32(c2, vacc2x0123); c2 += 4;
135         vst1q_f32(c1, vacc1x0123); c1 += 4;
136         vst1q_f32(c0, vacc0x0123); c0 += 4;
137 
138         vacc3x0123 = vacc3x4567;
139         vacc2x0123 = vacc2x4567;
140         vacc1x0123 = vacc1x4567;
141         vacc0x0123 = vacc0x4567;
142       }
143       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
144       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
145       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
146       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
147       if (nc & 2) {
148         vst1_f32(c3, vacc3x01); c3 += 2;
149         vst1_f32(c2, vacc2x01); c2 += 2;
150         vst1_f32(c1, vacc1x01); c1 += 2;
151         vst1_f32(c0, vacc0x01); c0 += 2;
152 
153         vacc3x01 = vget_high_f32(vacc3x0123);
154         vacc2x01 = vget_high_f32(vacc2x0123);
155         vacc1x01 = vget_high_f32(vacc1x0123);
156         vacc0x01 = vget_high_f32(vacc0x0123);
157       }
158       if (nc & 1) {
159         vst1_lane_f32(c3, vacc3x01, 0);
160         vst1_lane_f32(c2, vacc2x01, 0);
161         vst1_lane_f32(c1, vacc1x01, 0);
162         vst1_lane_f32(c0, vacc0x01, 0);
163       }
164 
165       nc = 0;
166     }
167   } while (nc != 0);
168 }
169