• 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_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_relu_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_gemm_relu_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_relu_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 += va0 * vb0;
69       vacc01 += va0 * vb1;
70       vacc02 += va0 * vb2;
71       vacc03 += va0 * vb3;
72       vacc10 += va1 * vb0;
73       vacc11 += va1 * vb1;
74       vacc12 += va1 * vb2;
75       vacc13 += va1 * vb3;
76 
77       k -= sizeof(float);
78     } while (k != 0);
79 
80     vacc00 = math_max_f32(vacc00, 0.0f);
81     vacc01 = math_max_f32(vacc01, 0.0f);
82     vacc02 = math_max_f32(vacc02, 0.0f);
83     vacc03 = math_max_f32(vacc03, 0.0f);
84     vacc10 = math_max_f32(vacc10, 0.0f);
85     vacc11 = math_max_f32(vacc11, 0.0f);
86     vacc12 = math_max_f32(vacc12, 0.0f);
87     vacc13 = math_max_f32(vacc13, 0.0f);
88 
89     if XNN_LIKELY(nc >= 4) {
90       c1[0] = vacc10;
91       c1[1] = vacc11;
92       c1[2] = vacc12;
93       c1[3] = vacc13;
94       c1 = (float*) ((uintptr_t) c1 + cn_stride);
95       c0[0] = vacc00;
96       c0[1] = vacc01;
97       c0[2] = vacc02;
98       c0[3] = vacc03;
99       c0 = (float*) ((uintptr_t) c0 + cn_stride);
100 
101       a1 = (const void*) ((uintptr_t) a1 - kc);
102       a0 = (const void*) ((uintptr_t) a0 - kc);
103 
104       nc -= 4;
105     } else {
106       if (nc & 2) {
107         c1[0] = vacc10;
108         c1[1] = vacc11;
109         vacc10 = vacc12;
110         c1 += 2;
111         c0[0] = vacc00;
112         c0[1] = vacc01;
113         vacc00 = vacc02;
114         c0 += 2;
115       }
116       if (nc & 1) {
117         c1[0] = vacc10;
118         c0[0] = vacc00;
119       }
120 
121       nc = 0;
122     }
123   } while (nc != 0);
124 }
125