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_4x2__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_4x2__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 vacc10 = vacc00;
60 float vacc11 = vacc01;
61 float vacc20 = vacc00;
62 float vacc21 = vacc01;
63 float vacc30 = vacc00;
64 float vacc31 = vacc01;
65 w += 2;
66
67 size_t p = ks;
68 do {
69 const float* restrict a0 = a[0];
70 assert(a0 != NULL);
71 if XNN_UNPREDICTABLE(a0 != zero) {
72 a0 = (const float*) ((uintptr_t) a0 + a_offset);
73 }
74 const float* restrict a1 = a[1];
75 assert(a1 != NULL);
76 if XNN_UNPREDICTABLE(a1 != zero) {
77 a1 = (const float*) ((uintptr_t) a1 + a_offset);
78 }
79 const float* restrict a2 = a[2];
80 assert(a2 != NULL);
81 if XNN_UNPREDICTABLE(a2 != zero) {
82 a2 = (const float*) ((uintptr_t) a2 + a_offset);
83 }
84 const float* restrict a3 = a[3];
85 assert(a3 != NULL);
86 if XNN_UNPREDICTABLE(a3 != zero) {
87 a3 = (const float*) ((uintptr_t) a3 + a_offset);
88 }
89 a += 4;
90
91 size_t k = kc;
92 do {
93 const float va0 = *a0++;
94 const float va1 = *a1++;
95 const float va2 = *a2++;
96 const float va3 = *a3++;
97
98 const float vb0 = w[0];
99 const float vb1 = w[1];
100 w += 2;
101
102 vacc00 += va0 * vb0;
103 vacc01 += va0 * vb1;
104 vacc10 += va1 * vb0;
105 vacc11 += va1 * vb1;
106 vacc20 += va2 * vb0;
107 vacc21 += va2 * vb1;
108 vacc30 += va3 * vb0;
109 vacc31 += va3 * vb1;
110
111 k -= sizeof(float);
112 } while (k != 0);
113 p -= 4 * sizeof(void*);
114 } while (p != 0);
115
116
117 if XNN_LIKELY(nc >= 2) {
118 c3[0] = vacc30;
119 c3[1] = vacc31;
120 c3 = (float*) ((uintptr_t) c3 + cn_stride);
121 c2[0] = vacc20;
122 c2[1] = vacc21;
123 c2 = (float*) ((uintptr_t) c2 + cn_stride);
124 c1[0] = vacc10;
125 c1[1] = vacc11;
126 c1 = (float*) ((uintptr_t) c1 + cn_stride);
127 c0[0] = vacc00;
128 c0[1] = vacc01;
129 c0 = (float*) ((uintptr_t) c0 + cn_stride);
130
131 a = (const float**restrict) ((uintptr_t) a - ks);
132 nc -= 2;
133 } else {
134 if (nc & 1) {
135 c3[0] = vacc30;
136 c2[0] = vacc20;
137 c1[0] = vacc10;
138 c0[0] = vacc00;
139 }
140
141 nc = 0;
142 }
143 } while (nc != 0);
144 }
145