• 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_qu8_gavgpool_minmax_fp32_ukernel_7x__scalar_fmagic_c2(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)])16 void xnn_qu8_gavgpool_minmax_fp32_ukernel_7x__scalar_fmagic_c2(
17     size_t rows,
18     size_t channels,
19     const uint8_t* input,
20     size_t input_stride,
21     const uint8_t* zero,
22     uint8_t* output,
23     const union xnn_qu8_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 uint8_t* i0 = input;
30   const uint8_t* i1 = (const uint8_t*) ((uintptr_t) i0 + input_stride);
31   if XNN_UNPREDICTABLE(rows < 2) {
32     i1 = zero;
33   }
34   const uint8_t* i2 = (const uint8_t*) ((uintptr_t) i1 + input_stride);
35   if XNN_UNPREDICTABLE(rows <= 2) {
36     i2 = zero;
37   }
38   const uint8_t* i3 = (const uint8_t*) ((uintptr_t) i2 + input_stride);
39   if XNN_UNPREDICTABLE(rows < 4) {
40     i3 = zero;
41   }
42   const uint8_t* i4 = (const uint8_t*) ((uintptr_t) i3 + input_stride);
43   if XNN_UNPREDICTABLE(rows <= 4) {
44     i4 = zero;
45   }
46   const uint8_t* i5 = (const uint8_t*) ((uintptr_t) i4 + input_stride);
47   if XNN_UNPREDICTABLE(rows < 6) {
48     i5 = zero;
49   }
50   const uint8_t* i6 = (const uint8_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 >= 2; channels -= 2) {
62     const int32_t vi0x0 = (int32_t) i0[0];
63     const int32_t vi0x1 = (int32_t) i0[1];
64     i0 += 2;
65 
66     int32_t vacc0 = vi0x0 + vinit_bias;
67     const int32_t vi1x0 = (int32_t) i1[0];
68     int32_t vacc1 = vi0x1 + vinit_bias;
69     const int32_t vi1x1 = (int32_t) i1[1];
70     i1 += 2;
71 
72     vacc0 += vi1x0;
73     const int32_t vi2x0 = (int32_t) i2[0];
74     vacc1 += vi1x1;
75     const int32_t vi2x1 = (int32_t) i2[1];
76     i2 += 2;
77     vacc0 += vi2x0;
78     const int32_t vi3x0 = (int32_t) i3[0];
79     vacc1 += vi2x1;
80     const int32_t vi3x1 = (int32_t) i3[1];
81     i3 += 2;
82     vacc0 += vi3x0;
83     const int32_t vi4x0 = (int32_t) i4[0];
84     vacc1 += vi3x1;
85     const int32_t vi4x1 = (int32_t) i4[1];
86     i4 += 2;
87     vacc0 += vi4x0;
88     const int32_t vi5x0 = (int32_t) i5[0];
89     vacc1 += vi4x1;
90     const int32_t vi5x1 = (int32_t) i5[1];
91     i5 += 2;
92     vacc0 += vi5x0;
93     const int32_t vi6x0 = (int32_t) i6[0];
94     vacc1 += vi5x1;
95     const int32_t vi6x1 = (int32_t) i6[1];
96     i6 += 2;
97 
98     vacc0 += vi6x0;
99     vacc1 += vi6x1;
100 
101     float vfpacc0 = (float) vacc0 * vscale;
102     float vfpacc1 = (float) vacc1 * vscale;
103 
104     vfpacc0 = math_max_f32(vfpacc0, voutput_min_less_zero_point);
105     vfpacc1 = math_max_f32(vfpacc1, voutput_min_less_zero_point);
106 
107     vfpacc0 = math_min_f32(vfpacc0, voutput_max_less_zero_point);
108     vfpacc1 = math_min_f32(vfpacc1, voutput_max_less_zero_point);
109 
110     vfpacc0 += vmagic_bias;
111     vfpacc1 += vmagic_bias;
112 
113     int32_t vout0 = (int32_t) float_as_uint32(vfpacc0) - vmagic_bias_less_output_zero_point;
114     int32_t vout1 = (int32_t) float_as_uint32(vfpacc1) - vmagic_bias_less_output_zero_point;
115 
116     output[0] = (uint8_t) vout0;
117     output[1] = (uint8_t) vout1;
118     output += 2;
119   }
120   if XNN_UNLIKELY(channels != 0) {
121     int32_t vacc = vinit_bias;
122     const int32_t vi0 = (int32_t) *i0;
123     const int32_t vi1 = (int32_t) *i1;
124 
125     vacc += vi0;
126     const int32_t vi2 = (int32_t) *i2;
127     vacc += vi1;
128     const int32_t vi3 = (int32_t) *i3;
129     vacc += vi2;
130     const int32_t vi4 = (int32_t) *i4;
131     vacc += vi3;
132     const int32_t vi5 = (int32_t) *i5;
133     vacc += vi4;
134     const int32_t vi6 = (int32_t) *i6;
135 
136     vacc += vi5;
137     vacc += vi6;
138 
139     float vfpacc = (float) vacc * vscale;
140     vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
141     vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
142     vfpacc += vmagic_bias;
143     int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_zero_point;
144 
145     *output = (uint8_t) vout;
146   }
147 }
148