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_2x4__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_default_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_igemm_ukernel_2x4__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_default_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 2);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(kc % sizeof(float) == 0);
35 assert(ks != 0);
36 assert(ks % (2 * 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
48 do {
49 float vacc00 = w[0];
50 float vacc01 = w[1];
51 float vacc02 = w[2];
52 float vacc03 = w[3];
53 float vacc10 = vacc00;
54 float vacc11 = vacc01;
55 float vacc12 = vacc02;
56 float vacc13 = vacc03;
57 w += 4;
58
59 size_t p = ks;
60 do {
61 const float* restrict a0 = a[0];
62 assert(a0 != NULL);
63 if XNN_UNPREDICTABLE(a0 != zero) {
64 a0 = (const float*) ((uintptr_t) a0 + a_offset);
65 }
66 const float* restrict a1 = a[1];
67 assert(a1 != NULL);
68 if XNN_UNPREDICTABLE(a1 != zero) {
69 a1 = (const float*) ((uintptr_t) a1 + a_offset);
70 }
71 a += 2;
72
73 size_t k = kc;
74 do {
75 const float va0 = *a0++;
76 const float va1 = *a1++;
77
78 const float vb0 = w[0];
79 const float vb1 = w[1];
80 const float vb2 = w[2];
81 const float vb3 = w[3];
82 w += 4;
83
84 vacc00 += va0 * vb0;
85 vacc01 += va0 * vb1;
86 vacc02 += va0 * vb2;
87 vacc03 += va0 * vb3;
88 vacc10 += va1 * vb0;
89 vacc11 += va1 * vb1;
90 vacc12 += va1 * vb2;
91 vacc13 += va1 * vb3;
92
93 k -= sizeof(float);
94 } while (k != 0);
95 p -= 2 * sizeof(void*);
96 } while (p != 0);
97
98
99 if XNN_LIKELY(nc >= 4) {
100 c1[0] = vacc10;
101 c1[1] = vacc11;
102 c1[2] = vacc12;
103 c1[3] = vacc13;
104 c1 = (float*) ((uintptr_t) c1 + cn_stride);
105 c0[0] = vacc00;
106 c0[1] = vacc01;
107 c0[2] = vacc02;
108 c0[3] = vacc03;
109 c0 = (float*) ((uintptr_t) c0 + cn_stride);
110
111 a = (const float**restrict) ((uintptr_t) a - ks);
112 nc -= 4;
113 } else {
114 if (nc & 2) {
115 c1[0] = vacc10;
116 c1[1] = vacc11;
117 vacc10 = vacc12;
118 c1 += 2;
119 c0[0] = vacc00;
120 c0[1] = vacc01;
121 vacc00 = vacc02;
122 c0 += 2;
123 }
124 if (nc & 1) {
125 c1[0] = vacc10;
126 c0[0] = vacc00;
127 }
128
129 nc = 0;
130 }
131 } while (nc != 0);
132 }
133