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