• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-igemm/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/igemm.h>
13 #include <xnnpack/math.h>
14 
15 
xnn_f32_igemm_relu_ukernel_2x4__scalar(size_t mr,size_t nc,size_t kc,size_t ks,const float ** restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const float * zero,const union xnn_f32_relu_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_igemm_relu_ukernel_2x4__scalar(
17     size_t mr,
18     size_t nc,
19     size_t kc,
20     size_t ks,
21     const float**restrict a,
22     const float*restrict w,
23     float*restrict c,
24     size_t cm_stride,
25     size_t cn_stride,
26     size_t a_offset,
27     const float* zero,
28     const union xnn_f32_relu_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(mr != 0);
31   assert(mr <= 2);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(ks != 0);
36   assert(ks % (2 * sizeof(void*)) == 0);
37   assert(a_offset % sizeof(float) == 0);
38   assert(a != NULL);
39   assert(w != NULL);
40   assert(c != NULL);
41 
42   float* c0 = c;
43   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44   if XNN_UNPREDICTABLE(mr != 2) {
45     c1 = c0;
46   }
47 
48   do {
49     float vacc00 = w[0];
50     float vacc01 = w[1];
51     float vacc02 = w[2];
52     float vacc03 = w[3];
53     float vacc10 = vacc00;
54     float vacc11 = vacc01;
55     float vacc12 = vacc02;
56     float vacc13 = vacc03;
57     w += 4;
58 
59     size_t p = ks;
60     do {
61       const float* restrict a0 = a[0];
62       assert(a0 != NULL);
63       if XNN_UNPREDICTABLE(a0 != zero) {
64         a0 = (const float*) ((uintptr_t) a0 + a_offset);
65       }
66       const float* restrict a1 = a[1];
67       assert(a1 != NULL);
68       if XNN_UNPREDICTABLE(a1 != zero) {
69         a1 = (const float*) ((uintptr_t) a1 + a_offset);
70       }
71       a += 2;
72 
73       size_t k = kc;
74       do {
75         const float va0 = *a0++;
76         const float va1 = *a1++;
77 
78         const float vb0 = w[0];
79         const float vb1 = w[1];
80         const float vb2 = w[2];
81         const float vb3 = w[3];
82         w += 4;
83 
84         vacc00 += va0 * vb0;
85         vacc01 += va0 * vb1;
86         vacc02 += va0 * vb2;
87         vacc03 += va0 * vb3;
88         vacc10 += va1 * vb0;
89         vacc11 += va1 * vb1;
90         vacc12 += va1 * vb2;
91         vacc13 += va1 * vb3;
92 
93         k -= sizeof(float);
94       } while (k != 0);
95       p -= 2 * sizeof(void*);
96     } while (p != 0);
97 
98     vacc00 = math_max_f32(vacc00, 0.0f);
99     vacc01 = math_max_f32(vacc01, 0.0f);
100     vacc02 = math_max_f32(vacc02, 0.0f);
101     vacc03 = math_max_f32(vacc03, 0.0f);
102     vacc10 = math_max_f32(vacc10, 0.0f);
103     vacc11 = math_max_f32(vacc11, 0.0f);
104     vacc12 = math_max_f32(vacc12, 0.0f);
105     vacc13 = math_max_f32(vacc13, 0.0f);
106 
107     if XNN_LIKELY(nc >= 4) {
108       c1[0] = vacc10;
109       c1[1] = vacc11;
110       c1[2] = vacc12;
111       c1[3] = vacc13;
112       c1 = (float*) ((uintptr_t) c1 + cn_stride);
113       c0[0] = vacc00;
114       c0[1] = vacc01;
115       c0[2] = vacc02;
116       c0[3] = vacc03;
117       c0 = (float*) ((uintptr_t) c0 + cn_stride);
118 
119       a = (const float**restrict) ((uintptr_t) a - ks);
120       nc -= 4;
121     } else {
122       if (nc & 2) {
123         c1[0] = vacc10;
124         c1[1] = vacc11;
125         vacc10 = vacc12;
126         c1 += 2;
127         c0[0] = vacc00;
128         c0[1] = vacc01;
129         vacc00 = vacc02;
130         c0 += 2;
131       }
132       if (nc & 1) {
133         c1[0] = vacc10;
134         c0[0] = vacc00;
135       }
136 
137       nc = 0;
138     }
139   } while (nc != 0);
140 }
141