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