• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ukernel_4x8__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_output_params params[restrict static1])18 void xnn_f32_ppmm_ukernel_4x8__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_output_params params[restrict static 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       vacc0x0123 = vmlaq_lane_f32(vacc0x0123, vb0123, vget_low_f32(va0123), 0);
67       vacc1x0123 = vmlaq_lane_f32(vacc1x0123, vb0123, vget_low_f32(va0123), 1);
68       vacc2x0123 = vmlaq_lane_f32(vacc2x0123, vb0123, vget_high_f32(va0123), 0);
69       vacc3x0123 = vmlaq_lane_f32(vacc3x0123, vb0123, vget_high_f32(va0123), 1);
70       vacc0x4567 = vmlaq_lane_f32(vacc0x4567, vb4567, vget_low_f32(va0123), 0);
71       vacc1x4567 = vmlaq_lane_f32(vacc1x4567, vb4567, vget_low_f32(va0123), 1);
72       vacc2x4567 = vmlaq_lane_f32(vacc2x4567, vb4567, vget_high_f32(va0123), 0);
73       vacc3x4567 = vmlaq_lane_f32(vacc3x4567, vb4567, vget_high_f32(va0123), 1);
74 
75       k -= sizeof(float);
76     } while (k != 0);
77 
78     const float32x4_t vmax = vld1q_dup_f32(&params->scalar.max);
79     vacc0x0123 = vminq_f32(vacc0x0123, vmax);
80     vacc1x0123 = vminq_f32(vacc1x0123, vmax);
81     vacc2x0123 = vminq_f32(vacc2x0123, vmax);
82     vacc3x0123 = vminq_f32(vacc3x0123, vmax);
83     vacc0x4567 = vminq_f32(vacc0x4567, vmax);
84     vacc1x4567 = vminq_f32(vacc1x4567, vmax);
85     vacc2x4567 = vminq_f32(vacc2x4567, vmax);
86     vacc3x4567 = vminq_f32(vacc3x4567, vmax);
87 
88     const float32x4_t vmin = vld1q_dup_f32(&params->scalar.min);
89     vacc0x0123 = vmaxq_f32(vacc0x0123, vmin);
90     vacc1x0123 = vmaxq_f32(vacc1x0123, vmin);
91     vacc2x0123 = vmaxq_f32(vacc2x0123, vmin);
92     vacc3x0123 = vmaxq_f32(vacc3x0123, vmin);
93     vacc0x4567 = vmaxq_f32(vacc0x4567, vmin);
94     vacc1x4567 = vmaxq_f32(vacc1x4567, vmin);
95     vacc2x4567 = vmaxq_f32(vacc2x4567, vmin);
96     vacc3x4567 = vmaxq_f32(vacc3x4567, vmin);
97 
98     if XNN_LIKELY(nc >= 8) {
99       vst1q_f32(c3, vacc3x0123);
100       vst1q_f32(c3 + 4, vacc3x4567);
101       c3 = (float*) ((uintptr_t) c3 + cn_stride);
102       vst1q_f32(c2, vacc2x0123);
103       vst1q_f32(c2 + 4, vacc2x4567);
104       c2 = (float*) ((uintptr_t) c2 + cn_stride);
105       vst1q_f32(c1, vacc1x0123);
106       vst1q_f32(c1 + 4, vacc1x4567);
107       c1 = (float*) ((uintptr_t) c1 + cn_stride);
108       vst1q_f32(c0, vacc0x0123);
109       vst1q_f32(c0 + 4, vacc0x4567);
110       c0 = (float*) ((uintptr_t) c0 + cn_stride);
111 
112       a = (const float*) ((uintptr_t) a - kc * 4);
113 
114       nc -= 8;
115     } else {
116       if (nc & 4) {
117         vst1q_f32(c3, vacc3x0123); c3 += 4;
118         vst1q_f32(c2, vacc2x0123); c2 += 4;
119         vst1q_f32(c1, vacc1x0123); c1 += 4;
120         vst1q_f32(c0, vacc0x0123); c0 += 4;
121 
122         vacc3x0123 = vacc3x4567;
123         vacc2x0123 = vacc2x4567;
124         vacc1x0123 = vacc1x4567;
125         vacc0x0123 = vacc0x4567;
126       }
127       float32x2_t vacc3x01 = vget_low_f32(vacc3x0123);
128       float32x2_t vacc2x01 = vget_low_f32(vacc2x0123);
129       float32x2_t vacc1x01 = vget_low_f32(vacc1x0123);
130       float32x2_t vacc0x01 = vget_low_f32(vacc0x0123);
131       if (nc & 2) {
132         vst1_f32(c3, vacc3x01); c3 += 2;
133         vst1_f32(c2, vacc2x01); c2 += 2;
134         vst1_f32(c1, vacc1x01); c1 += 2;
135         vst1_f32(c0, vacc0x01); c0 += 2;
136 
137         vacc3x01 = vget_high_f32(vacc3x0123);
138         vacc2x01 = vget_high_f32(vacc2x0123);
139         vacc1x01 = vget_high_f32(vacc1x0123);
140         vacc0x01 = vget_high_f32(vacc0x0123);
141       }
142       if (nc & 1) {
143         vst1_lane_f32(c3, vacc3x01, 0);
144         vst1_lane_f32(c2, vacc2x01, 0);
145         vst1_lane_f32(c1, vacc1x01, 0);
146         vst1_lane_f32(c0, vacc0x01, 0);
147       }
148 
149       nc = 0;
150     }
151   } while (nc != 0);
152 }
153