Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-5f5m5l1c1s1r-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_5f5m5l1c1s1r__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 > 5);
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 5 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 input += 5;
78
79 size_t c = channels;
80 do {
81 int32_t vacc = unaligned_load_s32(w);
82 const int32_t vi0 = (int32_t) *i0++;
83 const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
84 vacc += vi0 * vk0;
85 const int32_t vi1 = (int32_t) *i1++;
86 const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
87 vacc += vi1 * vk1;
88 const int32_t vi2 = (int32_t) *i2++;
89 const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
90 vacc += vi2 * vk2;
91 const int32_t vi3 = (int32_t) *i3++;
92 const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
93 vacc += vi3 * vk3;
94 const int32_t vi4 = (int32_t) *i4++;
95 const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
96 vacc += vi4 * vk4;
97
98 w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 5 * sizeof(int8_t));
99 *b++ = vacc;
100 } while (--c != 0);
101 }
102
103 // Middle pass to process 5 inputs in each iteration.
104 for (size_t ks = kernel_size - 5; ks > 5; ks -= 5) {
105 int32_t* b = buffer;
106 const int8_t* i0 = input[0];
107 assert(i0 != NULL);
108 if XNN_UNPREDICTABLE(i0 != zero) {
109 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
110 }
111 const int8_t* i1 = input[1];
112 assert(i1 != NULL);
113 if XNN_UNPREDICTABLE(i1 != zero) {
114 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
115 }
116 const int8_t* i2 = input[2];
117 assert(i2 != NULL);
118 if XNN_UNPREDICTABLE(i2 != zero) {
119 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
120 }
121 const int8_t* i3 = input[3];
122 assert(i3 != NULL);
123 if XNN_UNPREDICTABLE(i3 != zero) {
124 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
125 }
126 const int8_t* i4 = input[4];
127 assert(i4 != NULL);
128 if XNN_UNPREDICTABLE(i4 != zero) {
129 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
130 }
131 input += 5;
132
133 size_t c = channels;
134 do {
135 int32_t vacc = *b;
136 const int32_t vi0 = (int32_t) *i0++;
137 const int32_t vk0 = ((const int8_t*) w)[0];
138 vacc += vi0 * vk0;
139 const int32_t vi1 = (int32_t) *i1++;
140 const int32_t vk1 = ((const int8_t*) w)[1];
141 vacc += vi1 * vk1;
142 const int32_t vi2 = (int32_t) *i2++;
143 const int32_t vk2 = ((const int8_t*) w)[2];
144 vacc += vi2 * vk2;
145 const int32_t vi3 = (int32_t) *i3++;
146 const int32_t vk3 = ((const int8_t*) w)[3];
147 vacc += vi3 * vk3;
148 const int32_t vi4 = (int32_t) *i4++;
149 const int32_t vk4 = ((const int8_t*) w)[4];
150 vacc += vi4 * vk4;
151
152 w = (const void*) ((uintptr_t) w + 5 * sizeof(int8_t));
153 *b++ = vacc;
154 } while (--c != 0);
155 }
156
157 // Last pass to process up to 5 inputs.
158 {
159 const int32_t* b = buffer;
160 const int8_t* i0 = input[0];
161 assert(i0 != NULL);
162 if XNN_UNPREDICTABLE(i0 != zero) {
163 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
164 }
165 const int8_t* i1 = input[1];
166 assert(i1 != NULL);
167 if XNN_UNPREDICTABLE(i1 != zero) {
168 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
169 }
170 const int8_t* i2 = input[2];
171 assert(i2 != NULL);
172 if XNN_UNPREDICTABLE(i2 != zero) {
173 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
174 }
175 const int8_t* i3 = input[3];
176 assert(i3 != NULL);
177 if XNN_UNPREDICTABLE(i3 != zero) {
178 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
179 }
180 const int8_t* i4 = input[4];
181 assert(i4 != NULL);
182 if XNN_UNPREDICTABLE(i4 != zero) {
183 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
184 }
185
186 size_t c = channels;
187 do {
188 int32_t vacc = unaligned_load_s32(b++);
189 const int32_t vi0 = (int32_t) *i0++;
190 const int32_t vk0 = ((const int8_t*) w)[0];
191 vacc += vi0 * vk0;
192 const int32_t vi1 = (int32_t) *i1++;
193 const int32_t vk1 = ((const int8_t*) w)[1];
194 vacc += vi1 * vk1;
195 const int32_t vi2 = (int32_t) *i2++;
196 const int32_t vk2 = ((const int8_t*) w)[2];
197 vacc += vi2 * vk2;
198 const int32_t vi3 = (int32_t) *i3++;
199 const int32_t vk3 = ((const int8_t*) w)[3];
200 vacc += vi3 * vk3;
201 const int32_t vi4 = (int32_t) *i4++;
202 const int32_t vk4 = ((const int8_t*) w)[4];
203 vacc += vi4 * vk4;
204
205 w = (const void*) ((uintptr_t) w + 5 * sizeof(int8_t));
206
207 float vfpacc = (float) vacc * vscale;
208
209 vfpacc += vmagic_bias;
210 int32_t vout = (int32_t) float_as_uint32(vfpacc);
211 vout = math_max_s32(vout, vmagic_min);
212 vout = math_min_s32(vout, vmagic_max);
213 vout -= vmagic_bias_less_zero_point;
214
215 *output++ = (int8_t) vout;
216 } while (--c != 0);
217 }
218
219 input = (const int8_t**) ((uintptr_t) input + input_stride);
220 output = (int8_t*) ((uintptr_t) output + output_increment);
221 } while (--output_width != 0);
222 }