Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-6f6m7l1c1s1r-minmax-fp32-scalar-imagic.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/multipass-scalar.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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 <stddef.h>
12 #include <stdint.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/dwconv.h"
16 #include "xnnpack/math.h"
17 #include "xnnpack/microparams.h"
18 #include "xnnpack/unaligned.h"
19
20
21 void xnn_qs8_dwconv_minmax_fp32_ukernel_6f6m7l1c1s1r__scalar_imagic(
22 size_t channels,
23 size_t output_width,
24 const int8_t** input,
25 const void* weights,
26 int8_t* output,
27 intptr_t input_stride,
28 size_t output_increment,
29 size_t input_offset,
30 const int8_t* zero,
31 size_t kernel_size,
32 int32_t* buffer,
33 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
34 {
35 assert(channels != 0);
36 assert(output_width != 0);
37 assert(kernel_size > 6);
38
39 const float vscale = params->fp32_scalar.scale;
40 const float vmagic_bias = 12582912.0f;
41 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
42 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
43 const int32_t vmagic_min = (int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point);
44 const int32_t vmagic_max = (int32_t) float_as_uint32(12582912.0f + output_max_less_zero_point);
45 const int32_t vmagic_bias_less_zero_point = INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point;
46 do {
47 const void* w = weights;
48
49 // First pass to process 6 inputs.
50 {
51 int32_t* b = buffer;
52 const int8_t* i0 = input[0];
53 assert(i0 != NULL);
54 if XNN_UNPREDICTABLE(i0 != zero) {
55 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
56 }
57 const int8_t* i1 = input[1];
58 assert(i1 != NULL);
59 if XNN_UNPREDICTABLE(i1 != zero) {
60 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
61 }
62 const int8_t* i2 = input[2];
63 assert(i2 != NULL);
64 if XNN_UNPREDICTABLE(i2 != zero) {
65 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
66 }
67 const int8_t* i3 = input[3];
68 assert(i3 != NULL);
69 if XNN_UNPREDICTABLE(i3 != zero) {
70 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
71 }
72 const int8_t* i4 = input[4];
73 assert(i4 != NULL);
74 if XNN_UNPREDICTABLE(i4 != zero) {
75 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
76 }
77 const int8_t* i5 = input[5];
78 assert(i5 != NULL);
79 if XNN_UNPREDICTABLE(i5 != zero) {
80 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
81 }
82 input += 6;
83
84 size_t c = channels;
85 do {
86 int32_t vacc = unaligned_load_s32(w);
87 const int32_t vi0 = (int32_t) *i0++;
88 const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
89 vacc += vi0 * vk0;
90 const int32_t vi1 = (int32_t) *i1++;
91 const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
92 vacc += vi1 * vk1;
93 const int32_t vi2 = (int32_t) *i2++;
94 const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
95 vacc += vi2 * vk2;
96 const int32_t vi3 = (int32_t) *i3++;
97 const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
98 vacc += vi3 * vk3;
99 const int32_t vi4 = (int32_t) *i4++;
100 const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
101 vacc += vi4 * vk4;
102 const int32_t vi5 = (int32_t) *i5++;
103 const int32_t vk5 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[5];
104 vacc += vi5 * vk5;
105
106 w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 6 * sizeof(int8_t));
107 *b++ = vacc;
108 } while (--c != 0);
109 }
110
111 // Middle pass to process 6 inputs in each iteration.
112 for (size_t ks = kernel_size - 6; ks > 7; ks -= 6) {
113 int32_t* b = buffer;
114 const int8_t* i0 = input[0];
115 assert(i0 != NULL);
116 if XNN_UNPREDICTABLE(i0 != zero) {
117 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
118 }
119 const int8_t* i1 = input[1];
120 assert(i1 != NULL);
121 if XNN_UNPREDICTABLE(i1 != zero) {
122 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
123 }
124 const int8_t* i2 = input[2];
125 assert(i2 != NULL);
126 if XNN_UNPREDICTABLE(i2 != zero) {
127 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
128 }
129 const int8_t* i3 = input[3];
130 assert(i3 != NULL);
131 if XNN_UNPREDICTABLE(i3 != zero) {
132 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
133 }
134 const int8_t* i4 = input[4];
135 assert(i4 != NULL);
136 if XNN_UNPREDICTABLE(i4 != zero) {
137 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
138 }
139 const int8_t* i5 = input[5];
140 assert(i5 != NULL);
141 if XNN_UNPREDICTABLE(i5 != zero) {
142 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
143 }
144 input += 6;
145
146 size_t c = channels;
147 do {
148 int32_t vacc = *b;
149 const int32_t vi0 = (int32_t) *i0++;
150 const int32_t vk0 = ((const int8_t*) w)[0];
151 vacc += vi0 * vk0;
152 const int32_t vi1 = (int32_t) *i1++;
153 const int32_t vk1 = ((const int8_t*) w)[1];
154 vacc += vi1 * vk1;
155 const int32_t vi2 = (int32_t) *i2++;
156 const int32_t vk2 = ((const int8_t*) w)[2];
157 vacc += vi2 * vk2;
158 const int32_t vi3 = (int32_t) *i3++;
159 const int32_t vk3 = ((const int8_t*) w)[3];
160 vacc += vi3 * vk3;
161 const int32_t vi4 = (int32_t) *i4++;
162 const int32_t vk4 = ((const int8_t*) w)[4];
163 vacc += vi4 * vk4;
164 const int32_t vi5 = (int32_t) *i5++;
165 const int32_t vk5 = ((const int8_t*) w)[5];
166 vacc += vi5 * vk5;
167
168 w = (const void*) ((uintptr_t) w + 6 * sizeof(int8_t));
169 *b++ = vacc;
170 } while (--c != 0);
171 }
172
173 // Last pass to process up to 7 inputs.
174 {
175 const int32_t* b = buffer;
176 const int8_t* i0 = input[0];
177 assert(i0 != NULL);
178 if XNN_UNPREDICTABLE(i0 != zero) {
179 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
180 }
181 const int8_t* i1 = input[1];
182 assert(i1 != NULL);
183 if XNN_UNPREDICTABLE(i1 != zero) {
184 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
185 }
186 const int8_t* i2 = input[2];
187 assert(i2 != NULL);
188 if XNN_UNPREDICTABLE(i2 != zero) {
189 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
190 }
191 const int8_t* i3 = input[3];
192 assert(i3 != NULL);
193 if XNN_UNPREDICTABLE(i3 != zero) {
194 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
195 }
196 const int8_t* i4 = input[4];
197 assert(i4 != NULL);
198 if XNN_UNPREDICTABLE(i4 != zero) {
199 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
200 }
201 const int8_t* i5 = input[5];
202 assert(i5 != NULL);
203 if XNN_UNPREDICTABLE(i5 != zero) {
204 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
205 }
206 const int8_t* i6 = input[6];
207 assert(i6 != NULL);
208 if XNN_UNPREDICTABLE(i6 != zero) {
209 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
210 }
211
212 size_t c = channels;
213 do {
214 int32_t vacc = unaligned_load_s32(b++);
215 const int32_t vi0 = (int32_t) *i0++;
216 const int32_t vk0 = ((const int8_t*) w)[0];
217 vacc += vi0 * vk0;
218 const int32_t vi1 = (int32_t) *i1++;
219 const int32_t vk1 = ((const int8_t*) w)[1];
220 vacc += vi1 * vk1;
221 const int32_t vi2 = (int32_t) *i2++;
222 const int32_t vk2 = ((const int8_t*) w)[2];
223 vacc += vi2 * vk2;
224 const int32_t vi3 = (int32_t) *i3++;
225 const int32_t vk3 = ((const int8_t*) w)[3];
226 vacc += vi3 * vk3;
227 const int32_t vi4 = (int32_t) *i4++;
228 const int32_t vk4 = ((const int8_t*) w)[4];
229 vacc += vi4 * vk4;
230 const int32_t vi5 = (int32_t) *i5++;
231 const int32_t vk5 = ((const int8_t*) w)[5];
232 vacc += vi5 * vk5;
233 const int32_t vi6 = (int32_t) *i6++;
234 const int32_t vk6 = ((const int8_t*) w)[6];
235 vacc += vi6 * vk6;
236
237 w = (const void*) ((uintptr_t) w + 7 * sizeof(int8_t));
238
239 float vfpacc = (float) vacc * vscale;
240
241 vfpacc += vmagic_bias;
242 int32_t vout = (int32_t) float_as_uint32(vfpacc);
243 vout = math_max_s32(vout, vmagic_min);
244 vout = math_min_s32(vout, vmagic_max);
245 vout -= vmagic_bias_less_zero_point;
246
247 *output++ = (int8_t) vout;
248 } while (--c != 0);
249 }
250
251 input = (const int8_t**) ((uintptr_t) input + input_stride);
252 output = (int8_t*) ((uintptr_t) output + output_increment);
253 } while (--output_width != 0);
254 }