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_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_default_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_gemm_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_default_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 do {
47 float vacc00 = w[0];
48 float vacc01 = w[1];
49 float vacc02 = w[2];
50 float vacc03 = w[3];
51 w += 4;
52 float vacc10 = vacc00;
53 float vacc11 = vacc01;
54 float vacc12 = vacc02;
55 float vacc13 = vacc03;
56
57 size_t k = kc;
58 do {
59 const float va0 = *a0++;
60 const float va1 = *a1++;
61
62 const float vb0 = w[0];
63 const float vb1 = w[1];
64 const float vb2 = w[2];
65 const float vb3 = w[3];
66 w += 4;
67
68 vacc00 = math_muladd_f32(va0, vb0, vacc00);
69 vacc01 = math_muladd_f32(va0, vb1, vacc01);
70 vacc02 = math_muladd_f32(va0, vb2, vacc02);
71 vacc03 = math_muladd_f32(va0, vb3, vacc03);
72 vacc10 = math_muladd_f32(va1, vb0, vacc10);
73 vacc11 = math_muladd_f32(va1, vb1, vacc11);
74 vacc12 = math_muladd_f32(va1, vb2, vacc12);
75 vacc13 = math_muladd_f32(va1, vb3, vacc13);
76
77 k -= sizeof(float);
78 } while (k != 0);
79
80
81 if XNN_LIKELY(nc >= 4) {
82 c1[0] = vacc10;
83 c1[1] = vacc11;
84 c1[2] = vacc12;
85 c1[3] = vacc13;
86 c1 = (float*) ((uintptr_t) c1 + cn_stride);
87 c0[0] = vacc00;
88 c0[1] = vacc01;
89 c0[2] = vacc02;
90 c0[3] = vacc03;
91 c0 = (float*) ((uintptr_t) c0 + cn_stride);
92
93 a1 = (const void*) ((uintptr_t) a1 - kc);
94 a0 = (const void*) ((uintptr_t) a0 - kc);
95
96 nc -= 4;
97 } else {
98 if (nc & 2) {
99 c1[0] = vacc10;
100 c1[1] = vacc11;
101 vacc10 = vacc12;
102 c1 += 2;
103 c0[0] = vacc00;
104 c0[1] = vacc01;
105 vacc00 = vacc02;
106 c0 += 2;
107 }
108 if (nc & 1) {
109 c1[0] = vacc10;
110 c0[0] = vacc00;
111 }
112
113 nc = 0;
114 }
115 } while (nc != 0);
116 }
117