• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ukernel_4x4__wasm(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_default_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_igemm_ukernel_4x4__wasm(
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_default_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 += va0 * vb0;
113         vacc01 += va0 * vb1;
114         vacc02 += va0 * vb2;
115         vacc03 += va0 * vb3;
116         vacc10 += va1 * vb0;
117         vacc11 += va1 * vb1;
118         vacc12 += va1 * vb2;
119         vacc13 += va1 * vb3;
120         vacc20 += va2 * vb0;
121         vacc21 += va2 * vb1;
122         vacc22 += va2 * vb2;
123         vacc23 += va2 * vb3;
124         vacc30 += va3 * vb0;
125         vacc31 += va3 * vb1;
126         vacc32 += va3 * vb2;
127         vacc33 += va3 * vb3;
128 
129         k -= sizeof(float);
130       } while (k != 0);
131       p -= 4 * sizeof(void*);
132     } while (p != 0);
133 
134 
135     if XNN_LIKELY(nc >= 4) {
136       c3[0] = vacc30;
137       c3[1] = vacc31;
138       c3[2] = vacc32;
139       c3[3] = vacc33;
140       c3 = (float*) ((uintptr_t) c3 + cn_stride);
141       c2[0] = vacc20;
142       c2[1] = vacc21;
143       c2[2] = vacc22;
144       c2[3] = vacc23;
145       c2 = (float*) ((uintptr_t) c2 + cn_stride);
146       c1[0] = vacc10;
147       c1[1] = vacc11;
148       c1[2] = vacc12;
149       c1[3] = vacc13;
150       c1 = (float*) ((uintptr_t) c1 + cn_stride);
151       c0[0] = vacc00;
152       c0[1] = vacc01;
153       c0[2] = vacc02;
154       c0[3] = vacc03;
155       c0 = (float*) ((uintptr_t) c0 + cn_stride);
156 
157       a = (const float**restrict) ((uintptr_t) a - ks);
158       nc -= 4;
159     } else {
160       if (nc & 2) {
161         c3[0] = vacc30;
162         c3[1] = vacc31;
163         vacc30 = vacc32;
164         c3 += 2;
165         c2[0] = vacc20;
166         c2[1] = vacc21;
167         vacc20 = vacc22;
168         c2 += 2;
169         c1[0] = vacc10;
170         c1[1] = vacc11;
171         vacc10 = vacc12;
172         c1 += 2;
173         c0[0] = vacc00;
174         c0[1] = vacc01;
175         vacc00 = vacc02;
176         c0 += 2;
177       }
178       if (nc & 1) {
179         c3[0] = vacc30;
180         c2[0] = vacc20;
181         c1[0] = vacc10;
182         c0[0] = vacc00;
183       }
184 
185       nc = 0;
186     }
187   } while (nc != 0);
188 }
189