Debian Codegraph @

src/qs8-vmulc/gen/qs8-vmulc-minmax-fp32-neonv8-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/intrinsics-polyfill.h"
15 #include "xnnpack/vbinary.h"
16
17
18 void xnn_qs8_vmulc_minmax_fp32_ukernel__neonv8_ld128_u16(
19 size_t batch,
20 const int8_t* input_a,
21 const int8_t* input_b,
22 int8_t* output,
23 const union xnn_qs8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(int8_t) == 0);
27 assert(input_a != NULL);
28 assert(input_b != NULL);
29 assert(output != NULL);
30
31 #if XNN_ARCH_ARM64
32 const int8x16_t va_zero_point = vld1q_dup_s8(&params->scalar.a_zero_point);
33 #else
34 const int8x8_t va_zero_point = vld1_dup_s8(&params->scalar.a_zero_point);
35 #endif
36 const float32x4_t vscale = vld1q_dup_f32(&params->scalar.scale);
37 const int16x8_t voutput_zero_point = vld1q_dup_s16(&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 = vcvtnq_s32_f32(vfpacc0123);
71 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
72 vacc89AB = vcvtnq_s32_f32(vfpacc89AB);
73 vaccCDEF = vcvtnq_s32_f32(vfpaccCDEF);
74
75 #if XNN_ARCH_ARM64
76 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
77 int16x8_t vacc89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc89AB), vaccCDEF);
78 #else
79 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
80 int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
81 #endif
82
83 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
84 vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
85
86 #if XNN_ARCH_ARM64
87 int8x16_t vout0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc01234567), vacc89ABCDEF);
88 #else
89 int8x16_t vout0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc01234567), vqmovn_s16(vacc89ABCDEF));
90 #endif
91
92 vout0123456789ABCDEF = vmaxq_s8(vout0123456789ABCDEF, voutput_min);
93
94 vout0123456789ABCDEF = vminq_s8(vout0123456789ABCDEF, voutput_max);
95
96 vst1q_s8(output, vout0123456789ABCDEF); output += 16;
97 }
98 if XNN_UNLIKELY(batch != 0) {
99 do {
100 const int8x8_t va01234567 = vld1_s8(input_a); input_a += 8;
101
102 #if XNN_ARCH_ARM64
103 const int16x8_t vxa01234567 = vsubl_s8(va01234567, vget_low_s8(va_zero_point));
104 #else // !XNN_ARCH_ARM64
105 const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
106 #endif // XNN_ARCH_ARM64
107
108 int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb));
109 int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb));
110
111 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
112 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
113
114 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
115 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
116
117 vacc0123 = vcvtnq_s32_f32(vfpacc0123);
118 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
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 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
127
128 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
129
130 vout01234567 = vmax_s8(vout01234567, vget_low_s8(voutput_min));
131 vout01234567 = vmin_s8(vout01234567, vget_low_s8(voutput_max));
132 if XNN_LIKELY(batch >= (8 * sizeof(int8_t))) {
133 vst1_s8(output, vout01234567); output += 8;
134 batch -= 8 * sizeof(int8_t);
135 } else {
136 if (batch & (4 * sizeof(int8_t))) {
137 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
138 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
139 }
140 if (batch & (2 * sizeof(int8_t))) {
141 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
142 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
143 }
144 if (batch & (1 * sizeof(int8_t))) {
145 vst1_lane_s8(output, vout01234567, 0);
146 }
147 batch = 0;
148 }
149 } while (batch != 0);
150 }
151 }