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_4x2__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_4x2__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 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 vacc00 = math_max_f32(vacc00, 0.0f);
117 vacc01 = math_max_f32(vacc01, 0.0f);
118 vacc10 = math_max_f32(vacc10, 0.0f);
119 vacc11 = math_max_f32(vacc11, 0.0f);
120 vacc20 = math_max_f32(vacc20, 0.0f);
121 vacc21 = math_max_f32(vacc21, 0.0f);
122 vacc30 = math_max_f32(vacc30, 0.0f);
123 vacc31 = math_max_f32(vacc31, 0.0f);
124
125 if XNN_LIKELY(nc >= 2) {
126 c3[0] = vacc30;
127 c3[1] = vacc31;
128 c3 = (float*) ((uintptr_t) c3 + cn_stride);
129 c2[0] = vacc20;
130 c2[1] = vacc21;
131 c2 = (float*) ((uintptr_t) c2 + cn_stride);
132 c1[0] = vacc10;
133 c1[1] = vacc11;
134 c1 = (float*) ((uintptr_t) c1 + cn_stride);
135 c0[0] = vacc00;
136 c0[1] = vacc01;
137 c0 = (float*) ((uintptr_t) c0 + cn_stride);
138
139 a = (const float**restrict) ((uintptr_t) a - ks);
140 nc -= 2;
141 } else {
142 if (nc & 1) {
143 c3[0] = vacc30;
144 c2[0] = vacc20;
145 c1[0] = vacc10;
146 c0[0] = vacc00;
147 }
148
149 nc = 0;
150 }
151 } while (nc != 0);
152 }
153