• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_relu_ukernel_4x2__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_relu_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_gemm_relu_ukernel_4x2__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_relu_params params[restrict XNN_MIN_ELEMENTS(1)])
27 {
28   assert(mr != 0);
29   assert(mr <= 4);
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   const float* a2 = (const float*) ((uintptr_t) a1 + a_stride);
46   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
47   if XNN_UNPREDICTABLE(mr <= 2) {
48     a2 = a1;
49     c2 = c1;
50   }
51   const float* a3 = (const float*) ((uintptr_t) a2 + a_stride);
52   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
53   if XNN_UNPREDICTABLE(mr != 4) {
54     a3 = a2;
55     c3 = c2;
56   }
57 
58   do {
59     float vacc00 = w[0];
60     float vacc01 = w[1];
61     w += 2;
62     float vacc10 = vacc00;
63     float vacc11 = vacc01;
64     float vacc20 = vacc00;
65     float vacc21 = vacc01;
66     float vacc30 = vacc00;
67     float vacc31 = vacc01;
68 
69     size_t k = kc;
70     do {
71       const float va0 = *a0++;
72       const float va1 = *a1++;
73       const float va2 = *a2++;
74       const float va3 = *a3++;
75 
76       const float vb0 = w[0];
77       const float vb1 = w[1];
78       w += 2;
79 
80       vacc00 += va0 * vb0;
81       vacc01 += va0 * vb1;
82       vacc10 += va1 * vb0;
83       vacc11 += va1 * vb1;
84       vacc20 += va2 * vb0;
85       vacc21 += va2 * vb1;
86       vacc30 += va3 * vb0;
87       vacc31 += va3 * vb1;
88 
89       k -= sizeof(float);
90     } while (k != 0);
91 
92     vacc00 = math_max_f32(vacc00, 0.0f);
93     vacc01 = math_max_f32(vacc01, 0.0f);
94     vacc10 = math_max_f32(vacc10, 0.0f);
95     vacc11 = math_max_f32(vacc11, 0.0f);
96     vacc20 = math_max_f32(vacc20, 0.0f);
97     vacc21 = math_max_f32(vacc21, 0.0f);
98     vacc30 = math_max_f32(vacc30, 0.0f);
99     vacc31 = math_max_f32(vacc31, 0.0f);
100 
101     if XNN_LIKELY(nc >= 2) {
102       c3[0] = vacc30;
103       c3[1] = vacc31;
104       c3 = (float*) ((uintptr_t) c3 + cn_stride);
105       c2[0] = vacc20;
106       c2[1] = vacc21;
107       c2 = (float*) ((uintptr_t) c2 + cn_stride);
108       c1[0] = vacc10;
109       c1[1] = vacc11;
110       c1 = (float*) ((uintptr_t) c1 + cn_stride);
111       c0[0] = vacc00;
112       c0[1] = vacc01;
113       c0 = (float*) ((uintptr_t) c0 + cn_stride);
114 
115       a3 = (const void*) ((uintptr_t) a3 - kc);
116       a2 = (const void*) ((uintptr_t) a2 - kc);
117       a1 = (const void*) ((uintptr_t) a1 - kc);
118       a0 = (const void*) ((uintptr_t) a0 - kc);
119 
120       nc -= 2;
121     } else {
122       if (nc & 1) {
123         c3[0] = vacc30;
124         c2[0] = vacc20;
125         c1[0] = vacc10;
126         c0[0] = vacc00;
127       }
128 
129       nc = 0;
130     }
131   } while (nc != 0);
132 }
133