blob: ff84229603069525d9b77a68db06e8eca8e4bc10 [file] [log] [blame]
XNNPACK Teamb455b122019-09-27 18:10:33 -07001// 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
Marat Dukhanc72fa1e2019-11-27 11:54:03 -080014#include <xnnpack/common.h>
XNNPACK Teamb455b122019-09-27 18:10:33 -070015#include <xnnpack/ppmm.h>
16
17
18void 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,
Marat Dukhaneb09a6b2020-04-08 17:34:32 -070027 const union xnn_f32_minmax_params params[restrict static 1])
XNNPACK Teamb455b122019-09-27 18:10:33 -070028{
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
Frank Barchardfcfdc0e2019-10-21 15:58:42 -070078 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);
XNNPACK Teamb455b122019-09-27 18:10:33 -070087
Frank Barchardfcfdc0e2019-10-21 15:58:42 -070088 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);
XNNPACK Teamb455b122019-09-27 18:10:33 -070097
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}