1 // Auto-generated file. Do not edit!
2 // Template: src/f32-igemm/scalar.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 <xnnpack/igemm.h>
13 #include <xnnpack/math.h>
14
15
xnn_f32_igemm_relu_ukernel_4x4__scalar(size_t mr,size_t nc,size_t kc,size_t ks,const float ** restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const float * zero,const union xnn_f32_relu_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_igemm_relu_ukernel_4x4__scalar(
17 size_t mr,
18 size_t nc,
19 size_t kc,
20 size_t ks,
21 const float**restrict a,
22 const float*restrict w,
23 float*restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 size_t a_offset,
27 const float* zero,
28 const union xnn_f32_relu_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 4);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(float) == 0);
35 assert(ks != 0);
36 assert(ks % (4 * sizeof(void*)) == 0);
37 assert(a_offset % sizeof(float) == 0);
38 assert(a != NULL);
39 assert(w != NULL);
40 assert(c != NULL);
41
42 float* c0 = c;
43 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44 if XNN_UNPREDICTABLE(mr < 2) {
45 c1 = c0;
46 }
47 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
48 if XNN_UNPREDICTABLE(mr <= 2) {
49 c2 = c1;
50 }
51 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
52 if XNN_UNPREDICTABLE(mr != 4) {
53 c3 = c2;
54 }
55
56 do {
57 float vacc00 = w[0];
58 float vacc01 = w[1];
59 float vacc02 = w[2];
60 float vacc03 = w[3];
61 float vacc10 = vacc00;
62 float vacc11 = vacc01;
63 float vacc12 = vacc02;
64 float vacc13 = vacc03;
65 float vacc20 = vacc00;
66 float vacc21 = vacc01;
67 float vacc22 = vacc02;
68 float vacc23 = vacc03;
69 float vacc30 = vacc00;
70 float vacc31 = vacc01;
71 float vacc32 = vacc02;
72 float vacc33 = vacc03;
73 w += 4;
74
75 size_t p = ks;
76 do {
77 const float* restrict a0 = a[0];
78 assert(a0 != NULL);
79 if XNN_UNPREDICTABLE(a0 != zero) {
80 a0 = (const float*) ((uintptr_t) a0 + a_offset);
81 }
82 const float* restrict a1 = a[1];
83 assert(a1 != NULL);
84 if XNN_UNPREDICTABLE(a1 != zero) {
85 a1 = (const float*) ((uintptr_t) a1 + a_offset);
86 }
87 const float* restrict a2 = a[2];
88 assert(a2 != NULL);
89 if XNN_UNPREDICTABLE(a2 != zero) {
90 a2 = (const float*) ((uintptr_t) a2 + a_offset);
91 }
92 const float* restrict a3 = a[3];
93 assert(a3 != NULL);
94 if XNN_UNPREDICTABLE(a3 != zero) {
95 a3 = (const float*) ((uintptr_t) a3 + a_offset);
96 }
97 a += 4;
98
99 size_t k = kc;
100 do {
101 const float va0 = *a0++;
102 const float va1 = *a1++;
103 const float va2 = *a2++;
104 const float va3 = *a3++;
105
106 const float vb0 = w[0];
107 const float vb1 = w[1];
108 const float vb2 = w[2];
109 const float vb3 = w[3];
110 w += 4;
111
112 vacc00 = math_muladd_f32(va0, vb0, vacc00);
113 vacc01 = math_muladd_f32(va0, vb1, vacc01);
114 vacc02 = math_muladd_f32(va0, vb2, vacc02);
115 vacc03 = math_muladd_f32(va0, vb3, vacc03);
116 vacc10 = math_muladd_f32(va1, vb0, vacc10);
117 vacc11 = math_muladd_f32(va1, vb1, vacc11);
118 vacc12 = math_muladd_f32(va1, vb2, vacc12);
119 vacc13 = math_muladd_f32(va1, vb3, vacc13);
120 vacc20 = math_muladd_f32(va2, vb0, vacc20);
121 vacc21 = math_muladd_f32(va2, vb1, vacc21);
122 vacc22 = math_muladd_f32(va2, vb2, vacc22);
123 vacc23 = math_muladd_f32(va2, vb3, vacc23);
124 vacc30 = math_muladd_f32(va3, vb0, vacc30);
125 vacc31 = math_muladd_f32(va3, vb1, vacc31);
126 vacc32 = math_muladd_f32(va3, vb2, vacc32);
127 vacc33 = math_muladd_f32(va3, vb3, vacc33);
128
129 k -= sizeof(float);
130 } while (k != 0);
131 p -= 4 * sizeof(void*);
132 } while (p != 0);
133
134 vacc00 = math_max_f32(vacc00, 0.0f);
135 vacc01 = math_max_f32(vacc01, 0.0f);
136 vacc02 = math_max_f32(vacc02, 0.0f);
137 vacc03 = math_max_f32(vacc03, 0.0f);
138 vacc10 = math_max_f32(vacc10, 0.0f);
139 vacc11 = math_max_f32(vacc11, 0.0f);
140 vacc12 = math_max_f32(vacc12, 0.0f);
141 vacc13 = math_max_f32(vacc13, 0.0f);
142 vacc20 = math_max_f32(vacc20, 0.0f);
143 vacc21 = math_max_f32(vacc21, 0.0f);
144 vacc22 = math_max_f32(vacc22, 0.0f);
145 vacc23 = math_max_f32(vacc23, 0.0f);
146 vacc30 = math_max_f32(vacc30, 0.0f);
147 vacc31 = math_max_f32(vacc31, 0.0f);
148 vacc32 = math_max_f32(vacc32, 0.0f);
149 vacc33 = math_max_f32(vacc33, 0.0f);
150
151 if XNN_LIKELY(nc >= 4) {
152 c3[0] = vacc30;
153 c3[1] = vacc31;
154 c3[2] = vacc32;
155 c3[3] = vacc33;
156 c3 = (float*) ((uintptr_t) c3 + cn_stride);
157 c2[0] = vacc20;
158 c2[1] = vacc21;
159 c2[2] = vacc22;
160 c2[3] = vacc23;
161 c2 = (float*) ((uintptr_t) c2 + cn_stride);
162 c1[0] = vacc10;
163 c1[1] = vacc11;
164 c1[2] = vacc12;
165 c1[3] = vacc13;
166 c1 = (float*) ((uintptr_t) c1 + cn_stride);
167 c0[0] = vacc00;
168 c0[1] = vacc01;
169 c0[2] = vacc02;
170 c0[3] = vacc03;
171 c0 = (float*) ((uintptr_t) c0 + cn_stride);
172
173 a = (const float**restrict) ((uintptr_t) a - ks);
174 nc -= 4;
175 } else {
176 if (nc & 2) {
177 c3[0] = vacc30;
178 c3[1] = vacc31;
179 vacc30 = vacc32;
180 c3 += 2;
181 c2[0] = vacc20;
182 c2[1] = vacc21;
183 vacc20 = vacc22;
184 c2 += 2;
185 c1[0] = vacc10;
186 c1[1] = vacc11;
187 vacc10 = vacc12;
188 c1 += 2;
189 c0[0] = vacc00;
190 c0[1] = vacc01;
191 vacc00 = vacc02;
192 c0 += 2;
193 }
194 if (nc & 1) {
195 c3[0] = vacc30;
196 c2[0] = vacc20;
197 c1[0] = vacc10;
198 c0[0] = vacc00;
199 }
200
201 nc = 0;
202 }
203 } while (nc != 0);
204 }
205