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