• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-gavgpool/unipass-scalar.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 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 #include <math.h>
12 
13 #include <xnnpack/gavgpool.h>
14 #include <xnnpack/math.h>
15 
16 
xnn_qu8_gavgpool_minmax_fp32_ukernel_7x__scalar_lrintf_c4(size_t rows,size_t channels,const uint8_t * input,size_t input_stride,const uint8_t * zero,uint8_t * output,const union xnn_qu8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qu8_gavgpool_minmax_fp32_ukernel_7x__scalar_lrintf_c4(
18     size_t rows,
19     size_t channels,
20     const uint8_t* input,
21     size_t input_stride,
22     const uint8_t* zero,
23     uint8_t* output,
24     const union xnn_qu8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26   assert(rows != 0);
27   assert(rows <= 7);
28   assert(channels != 0);
29 
30   const uint8_t* i0 = input;
31   const uint8_t* i1 = (const uint8_t*) ((uintptr_t) i0 + input_stride);
32   if XNN_UNPREDICTABLE(rows < 2) {
33     i1 = zero;
34   }
35   const uint8_t* i2 = (const uint8_t*) ((uintptr_t) i1 + input_stride);
36   if XNN_UNPREDICTABLE(rows <= 2) {
37     i2 = zero;
38   }
39   const uint8_t* i3 = (const uint8_t*) ((uintptr_t) i2 + input_stride);
40   if XNN_UNPREDICTABLE(rows < 4) {
41     i3 = zero;
42   }
43   const uint8_t* i4 = (const uint8_t*) ((uintptr_t) i3 + input_stride);
44   if XNN_UNPREDICTABLE(rows <= 4) {
45     i4 = zero;
46   }
47   const uint8_t* i5 = (const uint8_t*) ((uintptr_t) i4 + input_stride);
48   if XNN_UNPREDICTABLE(rows < 6) {
49     i5 = zero;
50   }
51   const uint8_t* i6 = (const uint8_t*) ((uintptr_t) i5 + input_stride);
52   if XNN_UNPREDICTABLE(rows <= 6) {
53     i6 = zero;
54   }
55 
56   const int32_t vinit_bias = params->fp32_scalar_lrintf.init_bias;
57   const float vscale = params->fp32_scalar_lrintf.scale;
58   const float voutput_min_less_zero_point = params->fp32_scalar_lrintf.output_min_less_zero_point;
59   const float voutput_max_less_zero_point = params->fp32_scalar_lrintf.output_max_less_zero_point;
60   const int32_t voutput_zero_point = params->fp32_scalar_lrintf.output_zero_point;
61   for (; channels >= 4; channels -= 4) {
62     const int32_t vi0x0 = (int32_t) i0[0];
63     const int32_t vi0x1 = (int32_t) i0[1];
64     const int32_t vi0x2 = (int32_t) i0[2];
65     const int32_t vi0x3 = (int32_t) i0[3];
66     i0 += 4;
67 
68     int32_t vacc0 = vi0x0 + vinit_bias;
69     const int32_t vi1x0 = (int32_t) i1[0];
70     int32_t vacc1 = vi0x1 + vinit_bias;
71     const int32_t vi1x1 = (int32_t) i1[1];
72     int32_t vacc2 = vi0x2 + vinit_bias;
73     const int32_t vi1x2 = (int32_t) i1[2];
74     int32_t vacc3 = vi0x3 + vinit_bias;
75     const int32_t vi1x3 = (int32_t) i1[3];
76     i1 += 4;
77 
78     vacc0 += vi1x0;
79     const int32_t vi2x0 = (int32_t) i2[0];
80     vacc1 += vi1x1;
81     const int32_t vi2x1 = (int32_t) i2[1];
82     vacc2 += vi1x2;
83     const int32_t vi2x2 = (int32_t) i2[2];
84     vacc3 += vi1x3;
85     const int32_t vi2x3 = (int32_t) i2[3];
86     i2 += 4;
87     vacc0 += vi2x0;
88     const int32_t vi3x0 = (int32_t) i3[0];
89     vacc1 += vi2x1;
90     const int32_t vi3x1 = (int32_t) i3[1];
91     vacc2 += vi2x2;
92     const int32_t vi3x2 = (int32_t) i3[2];
93     vacc3 += vi2x3;
94     const int32_t vi3x3 = (int32_t) i3[3];
95     i3 += 4;
96     vacc0 += vi3x0;
97     const int32_t vi4x0 = (int32_t) i4[0];
98     vacc1 += vi3x1;
99     const int32_t vi4x1 = (int32_t) i4[1];
100     vacc2 += vi3x2;
101     const int32_t vi4x2 = (int32_t) i4[2];
102     vacc3 += vi3x3;
103     const int32_t vi4x3 = (int32_t) i4[3];
104     i4 += 4;
105     vacc0 += vi4x0;
106     const int32_t vi5x0 = (int32_t) i5[0];
107     vacc1 += vi4x1;
108     const int32_t vi5x1 = (int32_t) i5[1];
109     vacc2 += vi4x2;
110     const int32_t vi5x2 = (int32_t) i5[2];
111     vacc3 += vi4x3;
112     const int32_t vi5x3 = (int32_t) i5[3];
113     i5 += 4;
114     vacc0 += vi5x0;
115     const int32_t vi6x0 = (int32_t) i6[0];
116     vacc1 += vi5x1;
117     const int32_t vi6x1 = (int32_t) i6[1];
118     vacc2 += vi5x2;
119     const int32_t vi6x2 = (int32_t) i6[2];
120     vacc3 += vi5x3;
121     const int32_t vi6x3 = (int32_t) i6[3];
122     i6 += 4;
123 
124     vacc0 += vi6x0;
125     vacc1 += vi6x1;
126     vacc2 += vi6x2;
127     vacc3 += vi6x3;
128 
129     float vfpacc0 = (float) vacc0 * vscale;
130     float vfpacc1 = (float) vacc1 * vscale;
131     float vfpacc2 = (float) vacc2 * vscale;
132     float vfpacc3 = (float) vacc3 * vscale;
133 
134     vfpacc0 = math_max_f32(vfpacc0, voutput_min_less_zero_point);
135     vfpacc1 = math_max_f32(vfpacc1, voutput_min_less_zero_point);
136     vfpacc2 = math_max_f32(vfpacc2, voutput_min_less_zero_point);
137     vfpacc3 = math_max_f32(vfpacc3, voutput_min_less_zero_point);
138 
139     vfpacc0 = math_min_f32(vfpacc0, voutput_max_less_zero_point);
140     vfpacc1 = math_min_f32(vfpacc1, voutput_max_less_zero_point);
141     vfpacc2 = math_min_f32(vfpacc2, voutput_max_less_zero_point);
142     vfpacc3 = math_min_f32(vfpacc3, voutput_max_less_zero_point);
143 
144     const int32_t vrndacc0 = (int32_t) lrintf(vfpacc0);
145     const int32_t vrndacc1 = (int32_t) lrintf(vfpacc1);
146     const int32_t vrndacc2 = (int32_t) lrintf(vfpacc2);
147     const int32_t vrndacc3 = (int32_t) lrintf(vfpacc3);
148 
149     int32_t vout0 = vrndacc0 + voutput_zero_point;
150     int32_t vout1 = vrndacc1 + voutput_zero_point;
151     int32_t vout2 = vrndacc2 + voutput_zero_point;
152     int32_t vout3 = vrndacc3 + voutput_zero_point;
153 
154     output[0] = (uint8_t) vout0;
155     output[1] = (uint8_t) vout1;
156     output[2] = (uint8_t) vout2;
157     output[3] = (uint8_t) vout3;
158     output += 4;
159   }
160   if XNN_UNLIKELY(channels != 0) {
161     do {
162       int32_t vacc = vinit_bias;
163       const int32_t vi0 = (int32_t) *i0++;
164       const int32_t vi1 = (int32_t) *i1++;
165 
166       vacc += vi0;
167       const int32_t vi2 = (int32_t) *i2++;
168       vacc += vi1;
169       const int32_t vi3 = (int32_t) *i3++;
170       vacc += vi2;
171       const int32_t vi4 = (int32_t) *i4++;
172       vacc += vi3;
173       const int32_t vi5 = (int32_t) *i5++;
174       vacc += vi4;
175       const int32_t vi6 = (int32_t) *i6++;
176 
177       vacc += vi5;
178       vacc += vi6;
179 
180       float vfpacc = (float) vacc * vscale;
181       vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
182       vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
183       const int32_t vrndacc = (int32_t) lrintf(vfpacc);
184       int32_t vout = vrndacc + voutput_zero_point;
185 
186       *output++ = (uint8_t) vout;
187     } while (--channels != 0);
188   }
189 }
190