1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vmulcaddc/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/vmulcaddc.h>
14
15
xnn_f32_vmulcaddc_minmax_ukernel_c4__scalar_2x(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_vmulcaddc_minmax_ukernel_c4__scalar_2x(
17 size_t rows,
18 size_t channels,
19 const float*restrict input,
20 size_t input_stride,
21 const float*restrict weights,
22 float*restrict output,
23 size_t output_stride,
24 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26 assert(rows != 0);
27 assert(channels != 0);
28 assert(channels % sizeof(float) == 0);
29
30 const size_t input_increment = input_stride * 2 - channels;
31 const size_t output_increment = output_stride * 2 - channels;
32
33 const float* i0 = input;
34 float* o0 = output;
35 const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
36 float* o1 = (float*) ((uintptr_t) o0 + output_stride);
37 if XNN_UNPREDICTABLE(rows < 2) {
38 i1 = i0;
39 o1 = o0;
40 }
41
42 const float vmin = params->scalar.min;
43 const float vmax = params->scalar.max;
44 do {
45 const float* w = weights;
46 size_t c = channels;
47 for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
48 const float vscale0 = w[0];
49 const float vscale1 = w[1];
50 const float vscale2 = w[2];
51 const float vscale3 = w[3];
52
53 float vacc0x0 = i0[0];
54 float vacc0x1 = i0[1];
55 float vacc0x2 = i0[2];
56 float vacc0x3 = i0[3];
57 i0 += 4;
58 float vacc1x0 = i1[0];
59 float vacc1x1 = i1[1];
60 float vacc1x2 = i1[2];
61 float vacc1x3 = i1[3];
62 i1 += 4;
63
64 const float vbias0 = w[4];
65 const float vbias1 = w[5];
66 const float vbias2 = w[6];
67 const float vbias3 = w[7];
68
69 vacc0x0 = vacc0x0 * vscale0 + vbias0;
70 vacc0x1 = vacc0x1 * vscale1 + vbias1;
71 vacc0x2 = vacc0x2 * vscale2 + vbias2;
72 vacc0x3 = vacc0x3 * vscale3 + vbias3;
73 vacc1x0 = vacc1x0 * vscale0 + vbias0;
74 vacc1x1 = vacc1x1 * vscale1 + vbias1;
75 vacc1x2 = vacc1x2 * vscale2 + vbias2;
76 vacc1x3 = vacc1x3 * vscale3 + vbias3;
77
78 vacc0x0 = math_max_f32(vacc0x0, vmin);
79 vacc0x1 = math_max_f32(vacc0x1, vmin);
80 vacc0x2 = math_max_f32(vacc0x2, vmin);
81 vacc0x3 = math_max_f32(vacc0x3, vmin);
82 vacc1x0 = math_max_f32(vacc1x0, vmin);
83 vacc1x1 = math_max_f32(vacc1x1, vmin);
84 vacc1x2 = math_max_f32(vacc1x2, vmin);
85 vacc1x3 = math_max_f32(vacc1x3, vmin);
86
87 vacc0x0 = math_min_f32(vacc0x0, vmax);
88 vacc0x1 = math_min_f32(vacc0x1, vmax);
89 vacc0x2 = math_min_f32(vacc0x2, vmax);
90 vacc0x3 = math_min_f32(vacc0x3, vmax);
91 vacc1x0 = math_min_f32(vacc1x0, vmax);
92 vacc1x1 = math_min_f32(vacc1x1, vmax);
93 vacc1x2 = math_min_f32(vacc1x2, vmax);
94 vacc1x3 = math_min_f32(vacc1x3, vmax);
95
96 o0[0] = vacc0x0;
97 o0[1] = vacc0x1;
98 o0[2] = vacc0x2;
99 o0[3] = vacc0x3;
100 o0 += 4;
101 o1[0] = vacc1x0;
102 o1[1] = vacc1x1;
103 o1[2] = vacc1x2;
104 o1[3] = vacc1x3;
105 o1 += 4;
106
107 w += 8;
108 }
109 if XNN_UNLIKELY(c != 0) {
110 do {
111 const float vscale = *w++;
112
113 float vacc0 = *i0++;
114 float vacc1 = *i1++;
115
116 const float vbias = w[3];
117
118 vacc0 = vacc0 * vscale + vbias;
119 vacc1 = vacc1 * vscale + vbias;
120
121 vacc0 = math_max_f32(vacc0, vmin);
122 vacc1 = math_max_f32(vacc1, vmin);
123
124 vacc0 = math_min_f32(vacc0, vmax);
125 vacc1 = math_min_f32(vacc1, vmax);
126
127 *o0++ = vacc0;
128 *o1++ = vacc1;
129
130 c -= sizeof(float);
131 } while (c != 0);
132 }
133 i0 = (const float*) ((uintptr_t) i0 + input_increment);
134 o0 = (float*) ((uintptr_t) o0 + output_increment);
135 i1 = (const float*) ((uintptr_t) i1 + input_increment);
136 o1 = (float*) ((uintptr_t) o1 + output_increment);
137 if XNN_UNPREDICTABLE(rows < 4) {
138 i1 = i0;
139 o1 = o0;
140 }
141 rows = doz(rows, 2);
142 } while (rows != 0);
143 }
144