xref: /aosp_15_r20/external/XNNPACK/src/qc8-dwconv/gen/up8x3-minmax-fp32-neon-mla8-ld64.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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 
16 
xnn_qc8_dwconv_minmax_fp32_ukernel_up8x3__neon_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)])17 void xnn_qc8_dwconv_minmax_fp32_ukernel_up8x3__neon_mla8_ld64(
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_qc8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
28 {
29   assert(channels != 0);
30   assert(output_width != 0);
31 
32   const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias);
33   const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point);
34   const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neon.output_min);
35   const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neon.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 >= 8; c -= 8) {
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 
60       const int8x8_t vi0x01234567 = vld1_s8(i0); i0 += 8;
61       const int8x8_t vk0x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
62 
63       int16x8_t vprod01234567 = vmull_s8(vi0x01234567, vk0x01234567);
64 
65       const int8x8_t vi1x01234567 = vld1_s8(i1); i1 += 8;
66       const int8x8_t vk1x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
67 
68       vprod01234567 = vmlal_s8(vprod01234567, vi1x01234567, vk1x01234567);
69 
70       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
71       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
72       const int8x8_t vi2x01234567 = vld1_s8(i2); i2 += 8;
73       const int8x8_t vk2x01234567 = vld1_s8(w); w = (const void*) ((const int8_t*) w + 8);
74 
75       vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
76 
77       vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
78       vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
79 
80       float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
81       float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
82 
83       const float32x4_t vscale0123 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
84       const float32x4_t vscale4567 = vld1q_f32((const float*) w); w = (const void*) ((const float*) w + 4);
85 
86       vfpacc0123 = vmulq_f32(vfpacc0123, vscale0123);
87       vfpacc4567 = vmulq_f32(vfpacc4567, vscale4567);
88 
89       vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
90       vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
91 
92       vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
93       vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
94 
95 #if XNN_ARCH_ARM64
96       int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
97 
98 
99       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
100 #else  // !XNN_ARCH_ARM64
101       int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
102 
103 
104       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
105 #endif  // !XNN_ARCH_ARM64
106 
107       vout01234567 = vmax_s8(vout01234567, voutput_min);
108 
109       vout01234567 = vmin_s8(vout01234567, voutput_max);
110 
111       vst1_s8(output, vout01234567); output += 8;
112     }
113     if XNN_UNLIKELY(c != 0) {
114       {
115         int32x4_t vacc0123 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
116         int32x4_t vacc4567 = vld1q_s32(w); w = (const void*) ((const int32_t*) w + 4);
117 
118         const int8x8_t vi0x01234567 = vld1_s8(i0);
119         const int8x8_t vk0x01234567 = vld1_s8(w);
120 
121         int16x8_t vprod01234567 = vmull_s8(vi0x01234567, vk0x01234567);
122 
123         const int8x8_t vi1x01234567 = vld1_s8(i1);
124         const int8x8_t vk1x01234567 = vld1_s8((const void*) ((const int8_t*) w + 8));
125 
126         vprod01234567 = vmlal_s8(vprod01234567, vi1x01234567, vk1x01234567);
127 
128         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
129         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
130         const int8x8_t vi2x01234567 = vld1_s8(i2);
131         const int8x8_t vk2x01234567 = vld1_s8((const void*) ((const int8_t*) w + 16));
132 
133         vprod01234567 = vmull_s8(vi2x01234567, vk2x01234567);
134 
135         vacc0123 = vaddw_s16(vacc0123, vget_low_s16(vprod01234567));
136         vacc4567 = vaddw_s16(vacc4567, vget_high_s16(vprod01234567));
137 
138         float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
139         float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
140 
141         const float32x4_t vscale0123 = vld1q_f32((const float*) ((uintptr_t) w + 0 * sizeof(int32_t) + 24 * sizeof(int8_t)));
142         const float32x4_t vscale4567 = vld1q_f32((const float*) ((uintptr_t) w + 0 * sizeof(int32_t) + 24 * sizeof(int8_t) + 4 * sizeof(float)));
143         vfpacc0123 = vmulq_f32(vfpacc0123, vscale0123);
144         vfpacc4567 = vmulq_f32(vfpacc4567, vscale4567);
145 
146         vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
147         vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
148 
149         vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
150         vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
151 
152 #if XNN_ARCH_ARM64
153         int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
154 #else
155         int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
156 #endif
157 
158         int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
159         vout01234567 = vmax_s8(vout01234567, voutput_min);
160         vout01234567 = vmin_s8(vout01234567, voutput_max);
161 
162         if (c & 4) {
163           vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
164           vout01234567 = vext_s8(vout01234567, vout01234567, 4);
165         }
166         if (c & 2) {
167           vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
168           vout01234567 = vext_s8(vout01234567, vout01234567, 2);
169         }
170         if (c & 1) {
171           vst1_lane_s8(output, vout01234567, 0); output += 1;
172         }
173       }
174     }
175 
176     output = (int8_t*) ((uintptr_t) output + output_increment);
177   } while (--output_width != 0);
178 }
179