• 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_4x2__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_4x2__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 <= 4);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(ks != 0);
36   assert(ks % (4 * 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   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
48   if XNN_UNPREDICTABLE(mr <= 2) {
49     c2 = c1;
50   }
51   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
52   if XNN_UNPREDICTABLE(mr != 4) {
53     c3 = c2;
54   }
55 
56   const float vmin = params->scalar.min;
57   const float vmax = params->scalar.max;
58   do {
59     float vacc00 = w[0];
60     float vacc01 = w[1];
61     float vacc10 = vacc00;
62     float vacc11 = vacc01;
63     float vacc20 = vacc00;
64     float vacc21 = vacc01;
65     float vacc30 = vacc00;
66     float vacc31 = vacc01;
67     w += 2;
68 
69     size_t p = ks;
70     do {
71       const float* restrict a0 = a[0];
72       assert(a0 != NULL);
73       if XNN_UNPREDICTABLE(a0 != zero) {
74         a0 = (const float*) ((uintptr_t) a0 + a_offset);
75       }
76       const float* restrict a1 = a[1];
77       assert(a1 != NULL);
78       if XNN_UNPREDICTABLE(a1 != zero) {
79         a1 = (const float*) ((uintptr_t) a1 + a_offset);
80       }
81       const float* restrict a2 = a[2];
82       assert(a2 != NULL);
83       if XNN_UNPREDICTABLE(a2 != zero) {
84         a2 = (const float*) ((uintptr_t) a2 + a_offset);
85       }
86       const float* restrict a3 = a[3];
87       assert(a3 != NULL);
88       if XNN_UNPREDICTABLE(a3 != zero) {
89         a3 = (const float*) ((uintptr_t) a3 + a_offset);
90       }
91       a += 4;
92 
93       size_t k = kc;
94       do {
95         const float va0 = *a0++;
96         const float va1 = *a1++;
97         const float va2 = *a2++;
98         const float va3 = *a3++;
99 
100         const float vb0 = w[0];
101         const float vb1 = w[1];
102         w += 2;
103 
104         vacc00 += va0 * vb0;
105         vacc01 += va0 * vb1;
106         vacc10 += va1 * vb0;
107         vacc11 += va1 * vb1;
108         vacc20 += va2 * vb0;
109         vacc21 += va2 * vb1;
110         vacc30 += va3 * vb0;
111         vacc31 += va3 * vb1;
112 
113         k -= sizeof(float);
114       } while (k != 0);
115       p -= 4 * sizeof(void*);
116     } while (p != 0);
117 
118     vacc00 = math_max_f32(vacc00, vmin);
119     vacc01 = math_max_f32(vacc01, vmin);
120     vacc10 = math_max_f32(vacc10, vmin);
121     vacc11 = math_max_f32(vacc11, vmin);
122     vacc20 = math_max_f32(vacc20, vmin);
123     vacc21 = math_max_f32(vacc21, vmin);
124     vacc30 = math_max_f32(vacc30, vmin);
125     vacc31 = math_max_f32(vacc31, vmin);
126 
127     vacc00 = math_min_f32(vacc00, vmax);
128     vacc01 = math_min_f32(vacc01, vmax);
129     vacc10 = math_min_f32(vacc10, vmax);
130     vacc11 = math_min_f32(vacc11, vmax);
131     vacc20 = math_min_f32(vacc20, vmax);
132     vacc21 = math_min_f32(vacc21, vmax);
133     vacc30 = math_min_f32(vacc30, vmax);
134     vacc31 = math_min_f32(vacc31, vmax);
135 
136     if XNN_LIKELY(nc >= 2) {
137       c3[0] = vacc30;
138       c3[1] = vacc31;
139       c3 = (float*) ((uintptr_t) c3 + cn_stride);
140       c2[0] = vacc20;
141       c2[1] = vacc21;
142       c2 = (float*) ((uintptr_t) c2 + cn_stride);
143       c1[0] = vacc10;
144       c1[1] = vacc11;
145       c1 = (float*) ((uintptr_t) c1 + cn_stride);
146       c0[0] = vacc00;
147       c0[1] = vacc01;
148       c0 = (float*) ((uintptr_t) c0 + cn_stride);
149 
150       a = (const float**restrict) ((uintptr_t) a - ks);
151       nc -= 2;
152     } else {
153       if (nc & 1) {
154         c3[0] = vacc30;
155         c2[0] = vacc20;
156         c1[0] = vacc10;
157         c0[0] = vacc00;
158       }
159 
160       nc = 0;
161     }
162   } while (nc != 0);
163 }
164