Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-9p1c-minmax-rndnu-scalar.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/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 #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 void xnn_qs8_dwconv_minmax_rndnu_ukernel_9p1c__scalar(
21 size_t channels,
22 size_t output_width,
23 const int8_t** input,
24 const void* weights,
25 int8_t* output,
26 intptr_t input_stride,
27 size_t output_increment,
28 size_t input_offset,
29 const int8_t* zero,
30 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32 assert(channels != 0);
33 assert(output_width != 0);
34
35 const int32_t vmultiplier = params->rndnu_scalar.multiplier;
36 const int64_t vrounding = params->rndnu_scalar.rounding;
37 const uint32_t vshift = params->rndnu_scalar.shift;
38 const int32_t voutput_min_less_zero_point = (int32_t) params->rndnu_scalar.output_min - (int32_t) params->rndnu_scalar.output_zero_point;
39 const int32_t voutput_max_less_zero_point = (int32_t) params->rndnu_scalar.output_max - (int32_t) params->rndnu_scalar.output_zero_point;
40 const int32_t voutput_zero_point = params->rndnu_scalar.output_zero_point;
41 do {
42 const int8_t* i0 = input[0];
43 assert(i0 != NULL);
44 if XNN_UNPREDICTABLE(i0 != zero) {
45 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
46 }
47 const int8_t* i1 = input[1];
48 assert(i1 != NULL);
49 if XNN_UNPREDICTABLE(i1 != zero) {
50 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
51 }
52 const int8_t* i2 = input[2];
53 assert(i2 != NULL);
54 if XNN_UNPREDICTABLE(i2 != zero) {
55 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
56 }
57 const int8_t* i3 = input[3];
58 assert(i3 != NULL);
59 if XNN_UNPREDICTABLE(i3 != zero) {
60 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
61 }
62 const int8_t* i4 = input[4];
63 assert(i4 != NULL);
64 if XNN_UNPREDICTABLE(i4 != zero) {
65 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
66 }
67 const int8_t* i5 = input[5];
68 assert(i5 != NULL);
69 if XNN_UNPREDICTABLE(i5 != zero) {
70 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
71 }
72 const int8_t* i6 = input[6];
73 assert(i6 != NULL);
74 if XNN_UNPREDICTABLE(i6 != zero) {
75 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
76 }
77 const int8_t* i7 = input[7];
78 assert(i7 != NULL);
79 if XNN_UNPREDICTABLE(i7 != zero) {
80 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
81 }
82 const int8_t* i8 = input[8];
83 assert(i8 != NULL);
84 if XNN_UNPREDICTABLE(i8 != zero) {
85 i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
86 }
87 input = (const int8_t**) ((uintptr_t) input + input_stride);
88
89 size_t c = channels;
90 const void* w = weights;
91 do {
92 int32_t vacc = unaligned_load_s32(w);
93
94 const int32_t vi0 = (int32_t) *i0++;
95 const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
96 vacc += vi0 * vk0;
97 const int32_t vi1 = (int32_t) *i1++;
98 const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
99 vacc += vi1 * vk1;
100 const int32_t vi2 = (int32_t) *i2++;
101 const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
102 vacc += vi2 * vk2;
103 const int32_t vi3 = (int32_t) *i3++;
104 const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
105 vacc += vi3 * vk3;
106 const int32_t vi4 = (int32_t) *i4++;
107 const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
108 vacc += vi4 * vk4;
109 const int32_t vi5 = (int32_t) *i5++;
110 const int32_t vk5 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[5];
111 vacc += vi5 * vk5;
112 const int32_t vi6 = (int32_t) *i6++;
113 const int32_t vk6 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[6];
114 vacc += vi6 * vk6;
115 const int32_t vi7 = (int32_t) *i7++;
116 const int32_t vk7 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[7];
117 vacc += vi7 * vk7;
118 const int32_t vi8 = (int32_t) *i8++;
119 const int32_t vk8 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[8];
120 vacc += vi8 * vk8;
121
122 w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 9 * sizeof(int8_t));
123
124 const int64_t vextacc = math_mulext_s32(vacc, vmultiplier) + vrounding;
125 int32_t vout = (int32_t) math_asr_s64(vextacc, vshift);
126 vout = math_max_s32(vout, voutput_min_less_zero_point);
127 vout = math_min_s32(vout, voutput_max_less_zero_point);
128 vout += voutput_zero_point;
129
130 *output++ = (int8_t) vout;
131 } while (--c != 0);
132
133 output = (int8_t*) ((uintptr_t) output + output_increment);
134 } while (--output_width != 0);
135 }