• 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_minmax_ukernel_1x4__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_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_igemm_minmax_ukernel_1x4__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_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(mr != 0);
31   assert(mr <= 1);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(ks != 0);
36   assert(ks % (1 * 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 
44   const float vmin = params->scalar.min;
45   const float vmax = params->scalar.max;
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 
53     size_t p = ks;
54     do {
55       const float* restrict a0 = a[0];
56       assert(a0 != NULL);
57       if XNN_UNPREDICTABLE(a0 != zero) {
58         a0 = (const float*) ((uintptr_t) a0 + a_offset);
59       }
60       a += 1;
61 
62       size_t k = kc;
63       do {
64         const float va0 = *a0++;
65 
66         const float vb0 = w[0];
67         const float vb1 = w[1];
68         const float vb2 = w[2];
69         const float vb3 = w[3];
70         w += 4;
71 
72         vacc00 += va0 * vb0;
73         vacc01 += va0 * vb1;
74         vacc02 += va0 * vb2;
75         vacc03 += va0 * vb3;
76 
77         k -= sizeof(float);
78       } while (k != 0);
79       p -= 1 * sizeof(void*);
80     } while (p != 0);
81 
82     vacc00 = math_max_f32(vacc00, vmin);
83     vacc01 = math_max_f32(vacc01, vmin);
84     vacc02 = math_max_f32(vacc02, vmin);
85     vacc03 = math_max_f32(vacc03, vmin);
86 
87     vacc00 = math_min_f32(vacc00, vmax);
88     vacc01 = math_min_f32(vacc01, vmax);
89     vacc02 = math_min_f32(vacc02, vmax);
90     vacc03 = math_min_f32(vacc03, vmax);
91 
92     if XNN_LIKELY(nc >= 4) {
93       c0[0] = vacc00;
94       c0[1] = vacc01;
95       c0[2] = vacc02;
96       c0[3] = vacc03;
97       c0 = (float*) ((uintptr_t) c0 + cn_stride);
98 
99       a = (const float**restrict) ((uintptr_t) a - ks);
100       nc -= 4;
101     } else {
102       if (nc & 2) {
103         c0[0] = vacc00;
104         c0[1] = vacc01;
105         vacc00 = vacc02;
106         c0 += 2;
107       }
108       if (nc & 1) {
109         c0[0] = vacc00;
110       }
111 
112       nc = 0;
113     }
114   } while (nc != 0);
115 }
116