Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-5f5m5l1c1s1r-minmax-fp32-scalar-lrintf.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 <math.h>
12 #include <stddef.h>
13 #include <stdint.h>
14
15 #include "xnnpack/common.h"
16 #include "xnnpack/dwconv.h"
17 #include "xnnpack/math.h"
18 #include "xnnpack/microparams.h"
19 #include "xnnpack/unaligned.h"
20
21
22 void xnn_qs8_dwconv_minmax_fp32_ukernel_5f5m5l1c1s1r__scalar_lrintf(
23 size_t channels,
24 size_t output_width,
25 const int8_t** input,
26 const void* weights,
27 int8_t* output,
28 intptr_t input_stride,
29 size_t output_increment,
30 size_t input_offset,
31 const int8_t* zero,
32 size_t kernel_size,
33 int32_t* buffer,
34 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
35 {
36 assert(channels != 0);
37 assert(output_width != 0);
38 assert(kernel_size > 5);
39
40 const float vscale = params->fp32_scalar.scale;
41 const float voutput_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
42 const float voutput_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
43 const int32_t voutput_zero_point = params->fp32_scalar.output_zero_point;
44 do {
45 const void* w = weights;
46
47 // First pass to process 5 inputs.
48 {
49 int32_t* b = buffer;
50 const int8_t* i0 = input[0];
51 assert(i0 != NULL);
52 if XNN_UNPREDICTABLE(i0 != zero) {
53 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
54 }
55 const int8_t* i1 = input[1];
56 assert(i1 != NULL);
57 if XNN_UNPREDICTABLE(i1 != zero) {
58 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
59 }
60 const int8_t* i2 = input[2];
61 assert(i2 != NULL);
62 if XNN_UNPREDICTABLE(i2 != zero) {
63 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
64 }
65 const int8_t* i3 = input[3];
66 assert(i3 != NULL);
67 if XNN_UNPREDICTABLE(i3 != zero) {
68 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
69 }
70 const int8_t* i4 = input[4];
71 assert(i4 != NULL);
72 if XNN_UNPREDICTABLE(i4 != zero) {
73 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
74 }
75 input += 5;
76
77 size_t c = channels;
78 do {
79 int32_t vacc = unaligned_load_s32(w);
80 const int32_t vi0 = (int32_t) *i0++;
81 const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
82 vacc += vi0 * vk0;
83 const int32_t vi1 = (int32_t) *i1++;
84 const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
85 vacc += vi1 * vk1;
86 const int32_t vi2 = (int32_t) *i2++;
87 const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
88 vacc += vi2 * vk2;
89 const int32_t vi3 = (int32_t) *i3++;
90 const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
91 vacc += vi3 * vk3;
92 const int32_t vi4 = (int32_t) *i4++;
93 const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
94 vacc += vi4 * vk4;
95
96 w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 5 * sizeof(int8_t));
97 *b++ = vacc;
98 } while (--c != 0);
99 }
100
101 // Middle pass to process 5 inputs in each iteration.
102 for (size_t ks = kernel_size - 5; ks > 5; ks -= 5) {
103 int32_t* b = buffer;
104 const int8_t* i0 = input[0];
105 assert(i0 != NULL);
106 if XNN_UNPREDICTABLE(i0 != zero) {
107 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
108 }
109 const int8_t* i1 = input[1];
110 assert(i1 != NULL);
111 if XNN_UNPREDICTABLE(i1 != zero) {
112 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
113 }
114 const int8_t* i2 = input[2];
115 assert(i2 != NULL);
116 if XNN_UNPREDICTABLE(i2 != zero) {
117 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
118 }
119 const int8_t* i3 = input[3];
120 assert(i3 != NULL);
121 if XNN_UNPREDICTABLE(i3 != zero) {
122 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
123 }
124 const int8_t* i4 = input[4];
125 assert(i4 != NULL);
126 if XNN_UNPREDICTABLE(i4 != zero) {
127 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
128 }
129 input += 5;
130
131 size_t c = channels;
132 do {
133 int32_t vacc = *b;
134 const int32_t vi0 = (int32_t) *i0++;
135 const int32_t vk0 = ((const int8_t*) w)[0];
136 vacc += vi0 * vk0;
137 const int32_t vi1 = (int32_t) *i1++;
138 const int32_t vk1 = ((const int8_t*) w)[1];
139 vacc += vi1 * vk1;
140 const int32_t vi2 = (int32_t) *i2++;
141 const int32_t vk2 = ((const int8_t*) w)[2];
142 vacc += vi2 * vk2;
143 const int32_t vi3 = (int32_t) *i3++;
144 const int32_t vk3 = ((const int8_t*) w)[3];
145 vacc += vi3 * vk3;
146 const int32_t vi4 = (int32_t) *i4++;
147 const int32_t vk4 = ((const int8_t*) w)[4];
148 vacc += vi4 * vk4;
149
150 w = (const void*) ((uintptr_t) w + 5 * sizeof(int8_t));
151 *b++ = vacc;
152 } while (--c != 0);
153 }
154
155 // Last pass to process up to 5 inputs.
156 {
157 const int32_t* b = buffer;
158 const int8_t* i0 = input[0];
159 assert(i0 != NULL);
160 if XNN_UNPREDICTABLE(i0 != zero) {
161 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
162 }
163 const int8_t* i1 = input[1];
164 assert(i1 != NULL);
165 if XNN_UNPREDICTABLE(i1 != zero) {
166 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
167 }
168 const int8_t* i2 = input[2];
169 assert(i2 != NULL);
170 if XNN_UNPREDICTABLE(i2 != zero) {
171 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
172 }
173 const int8_t* i3 = input[3];
174 assert(i3 != NULL);
175 if XNN_UNPREDICTABLE(i3 != zero) {
176 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
177 }
178 const int8_t* i4 = input[4];
179 assert(i4 != NULL);
180 if XNN_UNPREDICTABLE(i4 != zero) {
181 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
182 }
183
184 size_t c = channels;
185 do {
186 int32_t vacc = unaligned_load_s32(b++);
187 const int32_t vi0 = (int32_t) *i0++;
188 const int32_t vk0 = ((const int8_t*) w)[0];
189 vacc += vi0 * vk0;
190 const int32_t vi1 = (int32_t) *i1++;
191 const int32_t vk1 = ((const int8_t*) w)[1];
192 vacc += vi1 * vk1;
193 const int32_t vi2 = (int32_t) *i2++;
194 const int32_t vk2 = ((const int8_t*) w)[2];
195 vacc += vi2 * vk2;
196 const int32_t vi3 = (int32_t) *i3++;
197 const int32_t vk3 = ((const int8_t*) w)[3];
198 vacc += vi3 * vk3;
199 const int32_t vi4 = (int32_t) *i4++;
200 const int32_t vk4 = ((const int8_t*) w)[4];
201 vacc += vi4 * vk4;
202
203 w = (const void*) ((uintptr_t) w + 5 * sizeof(int8_t));
204
205 float vfpacc = (float) vacc * vscale;
206
207 vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
208 vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
209 const int32_t vrndacc = (int32_t) lrintf(vfpacc);
210 int32_t vout = vrndacc + voutput_zero_point;
211
212 *output++ = (int8_t) vout;
213 } while (--c != 0);
214 }
215
216 input = (const int8_t**) ((uintptr_t) input + input_stride);
217 output = (int8_t*) ((uintptr_t) output + output_increment);
218 } while (--output_width != 0);
219 }