Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-9p1c-minmax-fp32-scalar-fmagic.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_fp32_ukernel_9p1c__scalar_fmagic(
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 float vscale = params->fp32_scalar.scale;
36 const float voutput_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
37 const float voutput_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
38 const float vmagic_bias = 12582912.0f;
39 const int32_t vmagic_bias_less_output_zero_point = INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point;
40 do {
41 const int8_t* i0 = input[0];
42 assert(i0 != NULL);
43 if XNN_UNPREDICTABLE(i0 != zero) {
44 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
45 }
46 const int8_t* i1 = input[1];
47 assert(i1 != NULL);
48 if XNN_UNPREDICTABLE(i1 != zero) {
49 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
50 }
51 const int8_t* i2 = input[2];
52 assert(i2 != NULL);
53 if XNN_UNPREDICTABLE(i2 != zero) {
54 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
55 }
56 const int8_t* i3 = input[3];
57 assert(i3 != NULL);
58 if XNN_UNPREDICTABLE(i3 != zero) {
59 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
60 }
61 const int8_t* i4 = input[4];
62 assert(i4 != NULL);
63 if XNN_UNPREDICTABLE(i4 != zero) {
64 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
65 }
66 const int8_t* i5 = input[5];
67 assert(i5 != NULL);
68 if XNN_UNPREDICTABLE(i5 != zero) {
69 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
70 }
71 const int8_t* i6 = input[6];
72 assert(i6 != NULL);
73 if XNN_UNPREDICTABLE(i6 != zero) {
74 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
75 }
76 const int8_t* i7 = input[7];
77 assert(i7 != NULL);
78 if XNN_UNPREDICTABLE(i7 != zero) {
79 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
80 }
81 const int8_t* i8 = input[8];
82 assert(i8 != NULL);
83 if XNN_UNPREDICTABLE(i8 != zero) {
84 i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
85 }
86 input = (const int8_t**) ((uintptr_t) input + input_stride);
87
88 size_t c = channels;
89 const void* w = weights;
90 do {
91 int32_t vacc = unaligned_load_s32(w);
92
93 const int32_t vi0 = (int32_t) *i0++;
94 const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
95 vacc += vi0 * vk0;
96 const int32_t vi1 = (int32_t) *i1++;
97 const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
98 vacc += vi1 * vk1;
99 const int32_t vi2 = (int32_t) *i2++;
100 const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
101 vacc += vi2 * vk2;
102 const int32_t vi3 = (int32_t) *i3++;
103 const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
104 vacc += vi3 * vk3;
105 const int32_t vi4 = (int32_t) *i4++;
106 const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
107 vacc += vi4 * vk4;
108 const int32_t vi5 = (int32_t) *i5++;
109 const int32_t vk5 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[5];
110 vacc += vi5 * vk5;
111 const int32_t vi6 = (int32_t) *i6++;
112 const int32_t vk6 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[6];
113 vacc += vi6 * vk6;
114 const int32_t vi7 = (int32_t) *i7++;
115 const int32_t vk7 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[7];
116 vacc += vi7 * vk7;
117 const int32_t vi8 = (int32_t) *i8++;
118 const int32_t vk8 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[8];
119 vacc += vi8 * vk8;
120
121 w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 9 * sizeof(int8_t));
122
123 float vfpacc = (float) vacc * vscale;
124
125 vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
126 vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
127 vfpacc += vmagic_bias;
128 int32_t vout = (int32_t) float_as_uint32(vfpacc) - vmagic_bias_less_output_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 }