1 // Auto-generated file. Do not edit!
2 // Template: src/f32-ppmm/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/math.h>
13 #include <xnnpack/ppmm.h>
14
15
xnn_f32_ppmm_minmax_ukernel_3x3__scalar(size_t mr,size_t nc,size_t kc,const float * restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_ppmm_minmax_ukernel_3x3__scalar(
17 size_t mr,
18 size_t nc,
19 size_t kc,
20 const float*restrict a,
21 const float*restrict w,
22 float*restrict c,
23 size_t cm_stride,
24 size_t cn_stride,
25 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
26 {
27 assert(mr != 0);
28 assert(mr <= 3);
29 assert(nc != 0);
30 assert(kc != 0);
31 assert(kc % sizeof(float) == 0);
32
33 float* c0 = c;
34 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
35 if XNN_UNPREDICTABLE(mr < 2) {
36 c1 = c0;
37 }
38 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
39 if XNN_UNPREDICTABLE(mr <= 2) {
40 c2 = c1;
41 }
42
43 do {
44 float vacc0x0 = w[0];
45 float vacc0x1 = w[1];
46 float vacc0x2 = w[2];
47 float vacc1x0 = vacc0x0;
48 float vacc1x1 = vacc0x1;
49 float vacc1x2 = vacc0x2;
50 float vacc2x0 = vacc0x0;
51 float vacc2x1 = vacc0x1;
52 float vacc2x2 = vacc0x2;
53 w += 3;
54
55 size_t k = kc;
56 do {
57 const float va0 = a[0];
58 const float va1 = a[1];
59 const float va2 = a[2];
60 a += 3;
61
62 const float vb0 = w[0];
63 const float vb1 = w[1];
64 const float vb2 = w[2];
65 w += 3;
66
67 vacc0x0 += va0 * vb0;
68 vacc1x0 += va1 * vb0;
69 vacc2x0 += va2 * vb0;
70 vacc0x1 += va0 * vb1;
71 vacc1x1 += va1 * vb1;
72 vacc2x1 += va2 * vb1;
73 vacc0x2 += va0 * vb2;
74 vacc1x2 += va1 * vb2;
75 vacc2x2 += va2 * vb2;
76
77 k -= sizeof(float);
78 } while (k != 0);
79
80 const float vmax = params->scalar.max;
81 vacc0x0 = math_min_f32(vacc0x0, vmax);
82 vacc1x0 = math_min_f32(vacc1x0, vmax);
83 vacc2x0 = math_min_f32(vacc2x0, vmax);
84 vacc0x1 = math_min_f32(vacc0x1, vmax);
85 vacc1x1 = math_min_f32(vacc1x1, vmax);
86 vacc2x1 = math_min_f32(vacc2x1, vmax);
87 vacc0x2 = math_min_f32(vacc0x2, vmax);
88 vacc1x2 = math_min_f32(vacc1x2, vmax);
89 vacc2x2 = math_min_f32(vacc2x2, vmax);
90
91 const float vmin = params->scalar.min;
92 vacc0x0 = math_max_f32(vacc0x0, vmin);
93 vacc1x0 = math_max_f32(vacc1x0, vmin);
94 vacc2x0 = math_max_f32(vacc2x0, vmin);
95 vacc0x1 = math_max_f32(vacc0x1, vmin);
96 vacc1x1 = math_max_f32(vacc1x1, vmin);
97 vacc2x1 = math_max_f32(vacc2x1, vmin);
98 vacc0x2 = math_max_f32(vacc0x2, vmin);
99 vacc1x2 = math_max_f32(vacc1x2, vmin);
100 vacc2x2 = math_max_f32(vacc2x2, vmin);
101
102 if XNN_LIKELY(nc >= 3) {
103 c2[0] = vacc2x0;
104 c2[1] = vacc2x1;
105 c2[2] = vacc2x2;
106 c1[0] = vacc1x0;
107 c1[1] = vacc1x1;
108 c1[2] = vacc1x2;
109 c0[0] = vacc0x0;
110 c0[1] = vacc0x1;
111 c0[2] = vacc0x2;
112
113 a = (const float*) ((uintptr_t) a - kc * 3);
114
115 c2 = (float*) ((uintptr_t) c2 + cn_stride);
116 c1 = (float*) ((uintptr_t) c1 + cn_stride);
117 c0 = (float*) ((uintptr_t) c0 + cn_stride);
118
119 nc -= 3;
120 } else {
121 if (nc & 2) {
122 c2[0] = vacc2x0;
123 c2[1] = vacc2x1;
124 c1[0] = vacc1x0;
125 c1[1] = vacc1x1;
126 c0[0] = vacc0x0;
127 c0[1] = vacc0x1;
128
129 vacc2x0 = vacc2x2;
130 vacc1x0 = vacc1x2;
131 vacc0x0 = vacc0x2;
132
133 c2 += 2;
134 c1 += 2;
135 c0 += 2;
136 }
137 if (nc & 1) {
138 *c2 = vacc2x0;
139 *c1 = vacc1x0;
140 *c0 = vacc0x0;
141 }
142
143 nc = 0;
144 }
145 } while (nc != 0);
146 }
147