• 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_1x4__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_1x4__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 <= 1);
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 
40   do {
41     float vacc00 = w[0];
42     float vacc01 = w[1];
43     float vacc02 = w[2];
44     float vacc03 = w[3];
45     w += 4;
46 
47     size_t k = kc;
48     do {
49       const float va0 = *a0++;
50 
51       const float vb0 = w[0];
52       const float vb1 = w[1];
53       const float vb2 = w[2];
54       const float vb3 = w[3];
55       w += 4;
56 
57       vacc00 += va0 * vb0;
58       vacc01 += va0 * vb1;
59       vacc02 += va0 * vb2;
60       vacc03 += va0 * vb3;
61 
62       k -= sizeof(float);
63     } while (k != 0);
64 
65     vacc00 = math_max_f32(vacc00, 0.0f);
66     vacc01 = math_max_f32(vacc01, 0.0f);
67     vacc02 = math_max_f32(vacc02, 0.0f);
68     vacc03 = math_max_f32(vacc03, 0.0f);
69 
70     if XNN_LIKELY(nc >= 4) {
71       c0[0] = vacc00;
72       c0[1] = vacc01;
73       c0[2] = vacc02;
74       c0[3] = vacc03;
75       c0 = (float*) ((uintptr_t) c0 + cn_stride);
76 
77       a0 = (const void*) ((uintptr_t) a0 - kc);
78 
79       nc -= 4;
80     } else {
81       if (nc & 2) {
82         c0[0] = vacc00;
83         c0[1] = vacc01;
84         vacc00 = vacc02;
85         c0 += 2;
86       }
87       if (nc & 1) {
88         c0[0] = vacc00;
89       }
90 
91       nc = 0;
92     }
93   } while (nc != 0);
94 }
95