1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vmulc/neon.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 <arm_neon.h>
13
14 #include <xnnpack/vmul.h>
15
16
xnn_qs8_vmulc_minmax_fp32_ukernel__neon_ld128_x16(size_t n,const int8_t * input_a,const int8_t * input_b,int8_t * output,const union xnn_qs8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_vmulc_minmax_fp32_ukernel__neon_ld128_x16(
18 size_t n,
19 const int8_t* input_a,
20 const int8_t* input_b,
21 int8_t* output,
22 const union xnn_qs8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 #if XNN_ARCH_ARM64
25 const int8x16_t va_zero_point = vld1q_dup_s8(params->fp32_neon.a_zero_point);
26 #else
27 const int8x8_t va_zero_point = vld1_dup_s8(params->fp32_neon.a_zero_point);
28 #endif
29 const float32x4_t vscale = vld1q_dup_f32(¶ms->fp32_neon.scale);
30 const float32x4_t vmagic_bias = vld1q_dup_f32(¶ms->fp32_neon.magic_bias);
31 const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(¶ms->fp32_neon.magic_bias_less_output_zero_point);
32 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->fp32_neon.output_min);
33 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->fp32_neon.output_max);
34
35 const int8x8_t vb = vld1_dup_s8(input_b);
36 const int8x8_t vb_zero_point = vld1_dup_s8(params->fp32_neon.b_zero_point);
37 const int16x8_t vxb = vsubl_s8(vb, vb_zero_point);
38 for (; n >= 16 * sizeof(int8_t); n -= 16 * sizeof(int8_t)) {
39 const int8x16_t va0123456789ABCDEF = vld1q_s8(input_a); input_a += 16;
40
41 #if XNN_ARCH_ARM64
42 const int16x8_t vxa01234567 = vsubl_s8(vget_low_s8(va0123456789ABCDEF), vget_low_s8(va_zero_point));
43 const int16x8_t vxa89ABCDEF = vsubl_high_s8(va0123456789ABCDEF, va_zero_point);
44 #else // !XNN_ARCH_ARM64
45 const int16x8_t vxa01234567 = vsubl_s8(vget_low_s8(va0123456789ABCDEF), va_zero_point);
46 const int16x8_t vxa89ABCDEF = vsubl_s8(vget_high_s8(va0123456789ABCDEF), va_zero_point);
47 #endif // XNN_ARCH_ARM64
48
49 int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb));
50 int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb));
51 int32x4_t vacc89AB = vmull_s16(vget_low_s16(vxa89ABCDEF), vget_low_s16(vxb));
52 int32x4_t vaccCDEF = vmull_s16(vget_high_s16(vxa89ABCDEF), vget_high_s16(vxb));
53
54 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
55 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
56 float32x4_t vfpacc89AB = vcvtq_f32_s32(vacc89AB);
57 float32x4_t vfpaccCDEF = vcvtq_f32_s32(vaccCDEF);
58
59 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
60 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
61 vfpacc89AB = vmulq_f32(vfpacc89AB, vscale);
62 vfpaccCDEF = vmulq_f32(vfpaccCDEF, vscale);
63
64 vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
65 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
66 vacc89AB = vreinterpretq_s32_f32(vaddq_f32(vfpacc89AB, vmagic_bias));
67 vaccCDEF = vreinterpretq_s32_f32(vaddq_f32(vfpaccCDEF, vmagic_bias));
68
69 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
70 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
71 vacc89AB = vqsubq_s32(vacc89AB, vmagic_bias_less_output_zero_point);
72 vaccCDEF = vqsubq_s32(vaccCDEF, vmagic_bias_less_output_zero_point);
73
74 #if XNN_ARCH_ARM64
75 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
76 int16x8_t vacc89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc89AB), vaccCDEF);
77 #else
78 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
79 int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
80 #endif
81
82
83 #if XNN_ARCH_ARM64
84 int8x16_t vout0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc01234567), vacc89ABCDEF);
85 #else
86 int8x16_t vout0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc01234567), vqmovn_s16(vacc89ABCDEF));
87 #endif
88
89 vout0123456789ABCDEF = vmaxq_s8(vout0123456789ABCDEF, voutput_min);
90
91 vout0123456789ABCDEF = vminq_s8(vout0123456789ABCDEF, voutput_max);
92
93 vst1q_s8(output, vout0123456789ABCDEF); output += 16;
94 }
95 if XNN_UNLIKELY(n != 0) {
96 do {
97 const int8x8_t va01234567 = vld1_s8(input_a); input_a += 8;
98
99 #if XNN_ARCH_ARM64
100 const int16x8_t vxa01234567 = vsubl_s8(va01234567, vget_low_s8(va_zero_point));
101 #else // !XNN_ARCH_ARM64
102 const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
103 #endif // XNN_ARCH_ARM64
104
105 int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb));
106 int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb));
107
108 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
109 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
110
111 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
112 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
113
114 vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
115 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
116
117 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
118 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
119
120 #if XNN_ARCH_ARM64
121 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
122 #else
123 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
124 #endif
125
126
127 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
128
129 vout01234567 = vmax_s8(vout01234567, vget_low_s8(voutput_min));
130 vout01234567 = vmin_s8(vout01234567, vget_low_s8(voutput_max));
131 if XNN_LIKELY(n >= (8 * sizeof(int8_t))) {
132 vst1_s8(output, vout01234567); output += 8;
133 n -= 8 * sizeof(int8_t);
134 } else {
135 if (n & (4 * sizeof(int8_t))) {
136 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
137 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
138 }
139 if (n & (2 * sizeof(int8_t))) {
140 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
141 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
142 }
143 if (n & (1 * sizeof(int8_t))) {
144 vst1_lane_s8(output, vout01234567, 0);
145 }
146 n = 0;
147 }
148 } while (n != 0);
149 }
150 }
151