Debian Codegraph @

src/qs8-vmulc/gen/qs8-vmulc-minmax-fp32-neon-ld128-u16.c

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