xref: /aosp_15_r20/external/XNNPACK/src/qc8-dwconv/gen/up1x9-minmax-fp32-scalar-lrintf.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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 <math.h>
12 
13 #include <xnnpack/dwconv.h>
14 #include <xnnpack/math.h>
15 #include <xnnpack/unaligned.h>
16 
17 
xnn_qc8_dwconv_minmax_fp32_ukernel_up1x9__scalar_lrintf(size_t channels,size_t output_width,const int8_t ** input,const void * weights,int8_t * output,size_t input_stride,size_t output_increment,size_t input_offset,const int8_t * zero,const union xnn_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qc8_dwconv_minmax_fp32_ukernel_up1x9__scalar_lrintf(
19     size_t channels,
20     size_t output_width,
21     const int8_t** input,
22     const void* weights,
23     int8_t* output,
24     size_t input_stride,
25     size_t output_increment,
26     size_t input_offset,
27     const int8_t* zero,
28     const union xnn_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(channels != 0);
31   assert(output_width != 0);
32 
33   const float voutput_min_less_zero_point = params->fp32_scalar_lrintf.output_min_less_zero_point;
34   const float voutput_max_less_zero_point = params->fp32_scalar_lrintf.output_max_less_zero_point;
35   const int32_t voutput_zero_point = params->fp32_scalar_lrintf.output_zero_point;
36   do {
37     const int8_t* i0 = input[0];
38     assert(i0 != NULL);
39     if XNN_UNPREDICTABLE(i0 != zero) {
40       i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
41     }
42     const int8_t* i1 = input[1];
43     assert(i1 != NULL);
44     if XNN_UNPREDICTABLE(i1 != zero) {
45       i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
46     }
47     const int8_t* i2 = input[2];
48     assert(i2 != NULL);
49     if XNN_UNPREDICTABLE(i2 != zero) {
50       i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
51     }
52     const int8_t* i3 = input[3];
53     assert(i3 != NULL);
54     if XNN_UNPREDICTABLE(i3 != zero) {
55       i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
56     }
57     const int8_t* i4 = input[4];
58     assert(i4 != NULL);
59     if XNN_UNPREDICTABLE(i4 != zero) {
60       i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
61     }
62     const int8_t* i5 = input[5];
63     assert(i5 != NULL);
64     if XNN_UNPREDICTABLE(i5 != zero) {
65       i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
66     }
67     const int8_t* i6 = input[6];
68     assert(i6 != NULL);
69     if XNN_UNPREDICTABLE(i6 != zero) {
70       i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
71     }
72     const int8_t* i7 = input[7];
73     assert(i7 != NULL);
74     if XNN_UNPREDICTABLE(i7 != zero) {
75       i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
76     }
77     const int8_t* i8 = input[8];
78     assert(i8 != NULL);
79     if XNN_UNPREDICTABLE(i8 != zero) {
80       i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
81     }
82     input = (const int8_t**) ((uintptr_t) input + input_stride);
83 
84     size_t c = channels;
85     const void* w = weights;
86     do {
87       int32_t vacc = unaligned_load_s32(w);
88 
89       const int32_t vi0 = (int32_t) *i0++;
90       const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
91       vacc += vi0 * vk0;
92       const int32_t vi1 = (int32_t) *i1++;
93       const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
94       vacc += vi1 * vk1;
95       const int32_t vi2 = (int32_t) *i2++;
96       const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
97       vacc += vi2 * vk2;
98       const int32_t vi3 = (int32_t) *i3++;
99       const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
100       vacc += vi3 * vk3;
101       const int32_t vi4 = (int32_t) *i4++;
102       const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
103       vacc += vi4 * vk4;
104       const int32_t vi5 = (int32_t) *i5++;
105       const int32_t vk5 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[5];
106       vacc += vi5 * vk5;
107       const int32_t vi6 = (int32_t) *i6++;
108       const int32_t vk6 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[6];
109       vacc += vi6 * vk6;
110       const int32_t vi7 = (int32_t) *i7++;
111       const int32_t vk7 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[7];
112       vacc += vi7 * vk7;
113       const int32_t vi8 = (int32_t) *i8++;
114       const int32_t vk8 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[8];
115       vacc += vi8 * vk8;
116 
117       w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 9 * sizeof(int8_t));
118 
119       const float vscale = unaligned_load_f32(w);
120       w = (const void*) ((const float*) w + 1);
121       float vfpacc = (float) vacc * vscale;
122 
123       vfpacc = math_max_f32(vfpacc, voutput_min_less_zero_point);
124       vfpacc = math_min_f32(vfpacc, voutput_max_less_zero_point);
125       const int32_t vrndacc = (int32_t) lrintf(vfpacc);
126       int32_t vout = vrndacc + voutput_zero_point;
127 
128       *output++ = (int8_t) vout;
129     } while (--c != 0);
130 
131     output = (int8_t*) ((uintptr_t) output + output_increment);
132   } while (--output_width != 0);
133 }
134