• 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 
12 #include <xnnpack/gavgpool.h>
13 #include <xnnpack/math.h>
14 
15 
xnn_qs8_gavgpool_minmax_fp32_ukernel_7x__scalar_fmagic_c4(size_t rows,size_t channels,const int8_t * input,size_t input_stride,const int8_t * zero,int8_t * output,const union xnn_qs8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qs8_gavgpool_minmax_fp32_ukernel_7x__scalar_fmagic_c4(
17     size_t rows,
18     size_t channels,
19     const int8_t* input,
20     size_t input_stride,
21     const int8_t* zero,
22     int8_t* output,
23     const union xnn_qs8_avgpool_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
24 {
25   assert(rows != 0);
26   assert(rows <= 7);
27   assert(channels != 0);
28 
29   const int8_t* i0 = input;
30   const int8_t* i1 = (const int8_t*) ((uintptr_t) i0 + input_stride);
31   if XNN_UNPREDICTABLE(rows < 2) {
32     i1 = zero;
33   }
34   const int8_t* i2 = (const int8_t*) ((uintptr_t) i1 + input_stride);
35   if XNN_UNPREDICTABLE(rows <= 2) {
36     i2 = zero;
37   }
38   const int8_t* i3 = (const int8_t*) ((uintptr_t) i2 + input_stride);
39   if XNN_UNPREDICTABLE(rows < 4) {
40     i3 = zero;
41   }
42   const int8_t* i4 = (const int8_t*) ((uintptr_t) i3 + input_stride);
43   if XNN_UNPREDICTABLE(rows <= 4) {
44     i4 = zero;
45   }
46   const int8_t* i5 = (const int8_t*) ((uintptr_t) i4 + input_stride);
47   if XNN_UNPREDICTABLE(rows < 6) {
48     i5 = zero;
49   }
50   const int8_t* i6 = (const int8_t*) ((uintptr_t) i5 + input_stride);
51   if XNN_UNPREDICTABLE(rows <= 6) {
52     i6 = zero;
53   }
54 
55   const int32_t vinit_bias = params->fp32_scalar_fmagic.init_bias;
56   const float vscale = params->fp32_scalar_fmagic.scale;
57   const float voutput_min_less_zero_point = params->fp32_scalar_fmagic.output_min_less_zero_point;
58   const float voutput_max_less_zero_point = params->fp32_scalar_fmagic.output_max_less_zero_point;
59   const float vmagic_bias = params->fp32_scalar_fmagic.magic_bias;
60   const int32_t vmagic_bias_less_output_zero_point = params->fp32_scalar_fmagic.magic_bias_less_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     vfpacc0 += vmagic_bias;
145     vfpacc1 += vmagic_bias;
146     vfpacc2 += vmagic_bias;
147     vfpacc3 += vmagic_bias;
148 
149     int32_t vout0 = (int32_t) float_as_uint32(vfpacc0) - vmagic_bias_less_output_zero_point;
150     int32_t vout1 = (int32_t) float_as_uint32(vfpacc1) - vmagic_bias_less_output_zero_point;
151     int32_t vout2 = (int32_t) float_as_uint32(vfpacc2) - vmagic_bias_less_output_zero_point;
152     int32_t vout3 = (int32_t) float_as_uint32(vfpacc3) - vmagic_bias_less_output_zero_point;
153 
154     output[0] = (int8_t) vout0;
155     output[1] = (int8_t) vout1;
156     output[2] = (int8_t) vout2;
157     output[3] = (int8_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       vfpacc += vmagic_bias;
184       int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_zero_point;
185 
186       *output++ = (int8_t) vout;
187     } while (--channels != 0);
188   }
189 }
190