• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
38   const float vmin = params->scalar.min;
39   const float vmax = params->scalar.max;
40   do {
41     if XNN_UNPREDICTABLE(rows < 2) {
42       i1 = i0;
43       o1 = o0;
44     }
45 
46     const float* w = weights;
47     size_t c = channels;
48     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
49       const float vscale0 = w[0];
50       const float vscale1 = w[1];
51       const float vscale2 = w[2];
52       const float vscale3 = w[3];
53 
54       float vacc0x0 = i0[0];
55       float vacc0x1 = i0[1];
56       float vacc0x2 = i0[2];
57       float vacc0x3 = i0[3];
58       i0 += 4;
59       float vacc1x0 = i1[0];
60       float vacc1x1 = i1[1];
61       float vacc1x2 = i1[2];
62       float vacc1x3 = i1[3];
63       i1 += 4;
64 
65       const float vbias0 = w[4];
66       const float vbias1 = w[5];
67       const float vbias2 = w[6];
68       const float vbias3 = w[7];
69 
70       vacc0x0 = vacc0x0 * vscale0 + vbias0;
71       vacc0x1 = vacc0x1 * vscale1 + vbias1;
72       vacc0x2 = vacc0x2 * vscale2 + vbias2;
73       vacc0x3 = vacc0x3 * vscale3 + vbias3;
74       vacc1x0 = vacc1x0 * vscale0 + vbias0;
75       vacc1x1 = vacc1x1 * vscale1 + vbias1;
76       vacc1x2 = vacc1x2 * vscale2 + vbias2;
77       vacc1x3 = vacc1x3 * vscale3 + vbias3;
78 
79       vacc0x0 = math_max_f32(vacc0x0, vmin);
80       vacc0x1 = math_max_f32(vacc0x1, vmin);
81       vacc0x2 = math_max_f32(vacc0x2, vmin);
82       vacc0x3 = math_max_f32(vacc0x3, vmin);
83       vacc1x0 = math_max_f32(vacc1x0, vmin);
84       vacc1x1 = math_max_f32(vacc1x1, vmin);
85       vacc1x2 = math_max_f32(vacc1x2, vmin);
86       vacc1x3 = math_max_f32(vacc1x3, vmin);
87 
88       vacc0x0 = math_min_f32(vacc0x0, vmax);
89       vacc0x1 = math_min_f32(vacc0x1, vmax);
90       vacc0x2 = math_min_f32(vacc0x2, vmax);
91       vacc0x3 = math_min_f32(vacc0x3, vmax);
92       vacc1x0 = math_min_f32(vacc1x0, vmax);
93       vacc1x1 = math_min_f32(vacc1x1, vmax);
94       vacc1x2 = math_min_f32(vacc1x2, vmax);
95       vacc1x3 = math_min_f32(vacc1x3, vmax);
96 
97       o0[0] = vacc0x0;
98       o0[1] = vacc0x1;
99       o0[2] = vacc0x2;
100       o0[3] = vacc0x3;
101       o0 += 4;
102       o1[0] = vacc1x0;
103       o1[1] = vacc1x1;
104       o1[2] = vacc1x2;
105       o1[3] = vacc1x3;
106       o1 += 4;
107 
108       w += 8;
109     }
110     if XNN_UNLIKELY(c != 0) {
111       do {
112         const float vscale = *w++;
113 
114         float vacc0 = *i0++;
115         float vacc1 = *i1++;
116 
117         const float vbias = w[3];
118 
119         vacc0 = vacc0 * vscale + vbias;
120         vacc1 = vacc1 * vscale + vbias;
121 
122         vacc0 = math_max_f32(vacc0, vmin);
123         vacc1 = math_max_f32(vacc1, vmin);
124 
125         vacc0 = math_min_f32(vacc0, vmax);
126         vacc1 = math_min_f32(vacc1, vmax);
127 
128         *o0++ = vacc0;
129         *o1++ = vacc1;
130 
131         c -= sizeof(float);
132       } while (c != 0);
133     }
134     i0 = (const float*) ((uintptr_t) i0 + input_increment);
135     o0 = (float*) ((uintptr_t) o0 + output_increment);
136     i1 = (const float*) ((uintptr_t) i1 + input_increment);
137     o1 = (float*) ((uintptr_t) o1 + output_increment);
138     rows = doz(rows, 2);
139   } while (rows != 0);
140 }
141