1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/unipass-neon-mul8.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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 <arm_neon.h>
13
14 #include <xnnpack/dwconv.h>
15 #include <xnnpack/intrinsics-polyfill.h>
16
17
xnn_qc8_dwconv_minmax_fp32_ukernel_up16x3__neonv8_mla8_ld64(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_up16x3__neonv8_mla8_ld64(
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)]) XNN_OOB_READS
29 {
30 assert(channels != 0);
31 assert(output_width != 0);
32
33 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->fp32_neonv8.output_zero_point);
34 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neonv8.output_min);
35 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neonv8.output_max);
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 input = (const int8_t**) ((uintptr_t) input + input_stride);
53
54 size_t c = channels;
55 const void* w = weights;
56 for (; c >= 16; c -= 16) {
57 int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
58 int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
59 int32x4_t vacc89AB = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
60 int32x4_t vaccCDEF = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
61
62 const int8x8_t vi0x01234567 = vld1_s8(i0); i0 += 8;
63 const int8x8_t vk0x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
64 const int8x8_t vi0x89ABCDEF = vld1_s8(i0); i0 += 8;
65 const int8x8_t vk0x89ABCDEF = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
66
67 int16x8_t vprod01234567 = vmull_s8(vi0x01234567, vk0x01234567);
68 int16x8_t vprod89ABCDEF = vmull_s8(vi0x89ABCDEF, vk0x89ABCDEF);
69
70 const int8x8_t vi1x01234567 = vld1_s8(i1); i1 += 8;
71 const int8x8_t vk1x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
72 const int8x8_t vi1x89ABCDEF = vld1_s8(i1); i1 += 8;
73 const int8x8_t vk1x89ABCDEF = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
74
75 vprod01234567 = vmlal_s8(vprod01234567, vi1x01234567, vk1x01234567);
76 vprod89ABCDEF = vmlal_s8(vprod89ABCDEF, vi1x89ABCDEF, vk1x89ABCDEF);
77
78 vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
79 vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
80 vacc89AB = vaddw_s16(vacc89AB, vget_low_s16(vprod89ABCDEF));
81 vaccCDEF = vaddw_s16(vaccCDEF, vget_high_s16(vprod89ABCDEF));
82 const int8x8_t vi2x01234567 = vld1_s8(i2); i2 += 8;
83 const int8x8_t vk2x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
84 const int8x8_t vi2x89ABCDEF = vld1_s8(i2); i2 += 8;
85 const int8x8_t vk2x89ABCDEF = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
86
87 vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
88 vprod89ABCDEF = vmull_s8(vi2x89ABCDEF, vk2x89ABCDEF);
89
90 vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
91 vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
92 vacc89AB = vaddw_s16(vacc89AB, vget_low_s16(vprod89ABCDEF));
93 vaccCDEF = vaddw_s16(vaccCDEF, vget_high_s16(vprod89ABCDEF));
94
95 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
96 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
97 float32x4_t vfpacc89AB = vcvtq_f32_s32(vacc89AB);
98 float32x4_t vfpaccCDEF = vcvtq_f32_s32(vaccCDEF);
99
100 const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
101 const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
102 const float32x4_t vscale89AB = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
103 const float32x4_t vscaleCDEF = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
104
105 vfpacc0123 = vmulq_f32(vfpacc0123, vscale0123);
106 vfpacc4567 = vmulq_f32(vfpacc4567, vscale4567);
107 vfpacc89AB = vmulq_f32(vfpacc89AB, vscale89AB);
108 vfpaccCDEF = vmulq_f32(vfpaccCDEF, vscaleCDEF);
109
110 vacc0123 = vcvtnq_s32_f32(vfpacc0123);
111 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
112 vacc89AB = vcvtnq_s32_f32(vfpacc89AB);
113 vaccCDEF = vcvtnq_s32_f32(vfpaccCDEF);
114
115 #if XNN_ARCH_ARM64
116 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
117 int16x8_t vacc89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc89AB), vaccCDEF);
118
119 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
120 vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
121
122 int8x16_t vout0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc01234567), vacc89ABCDEF);
123 #else // !XNN_ARCH_ARM64
124 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
125 int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
126
127 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
128 vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
129
130 int8x16_t vout0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc01234567), vqmovn_s16(vacc89ABCDEF));
131 #endif // !XNN_ARCH_ARM64
132
133 vout0123456789ABCDEF = vmaxq_s8(vout0123456789ABCDEF, voutput_min);
134
135 vout0123456789ABCDEF = vminq_s8(vout0123456789ABCDEF, voutput_max);
136
137 vst1q_s8(output, vout0123456789ABCDEF); output += 16;
138 }
139 if XNN_UNLIKELY(c != 0) {
140 const int8_t* k = (const int8_t*) ((const int32_t*) w + 16);
141 do {
142 int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
143 int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
144
145 const int8x8_t vi0x01234567 = vld1_s8(i0); i0 += 8;
146 const int8x8_t vk0x01234567 = vld1_s8(k); k += 8;
147
148 int16x8_t vprod01234567 = vmull_s8(vi0x01234567, vk0x01234567);
149
150 const int8x8_t vi1x01234567 = vld1_s8(i1); i1 += 8;
151 const int8x8_t vk1x01234567 = vld1_s8((const void*) (k + 8));
152
153 vprod01234567 = vmlal_s8(vprod01234567, vi1x01234567, vk1x01234567);
154
155 vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
156 vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
157 const int8x8_t vi2x01234567 = vld1_s8(i2); i2 += 8;
158 const int8x8_t vk2x01234567 = vld1_s8((const void*) (k + 24));
159
160 vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
161
162 vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
163 vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
164
165 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
166 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
167
168 const float32x4_t vscale0123 = vld1q_f32((const float*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t)));
169 const float32x4_t vscale4567 = vld1q_f32((const float*) ((uintptr_t) w + 8 * sizeof(int32_t) + 48 * sizeof(int8_t) + 4 * sizeof(float)));
170 vfpacc0123 = vmulq_f32(vfpacc0123, vscale0123);
171 vfpacc4567 = vmulq_f32(vfpacc4567, vscale4567);
172
173 vacc0123 = vcvtnq_s32_f32(vfpacc0123);
174 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
175
176 #if XNN_ARCH_ARM64
177 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
178 #else
179 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
180 #endif
181 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
182
183 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
184 vout01234567 = vmax_s8(vout01234567, vget_low_s8(voutput_min));
185 vout01234567 = vmin_s8(vout01234567, vget_low_s8(voutput_max));
186
187 if XNN_LIKELY(c >= 8) {
188 vst1_s8(output, vout01234567); output += 8;
189 c -= 8;
190 } else {
191 if (c & 4) {
192 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
193 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
194 }
195 if (c & 2) {
196 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
197 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
198 }
199 if (c & 1) {
200 vst1_lane_s8(output, vout01234567, 0); output += 1;
201 }
202 c = 0;
203 }
204 } while (c != 0);
205 }
206
207 output = (int8_t*) ((uintptr_t) output + output_increment);
208 } while (--output_width != 0);
209 }
210