Debian Codegraph @

src/qs8-vmulc/gen/qs8-vmulc-minmax-rndnu-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_rndnu_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->rndnu_neon.a_zero_point);
32 #else
33 const int8x8_t va_zero_point = vld1_dup_s8(&params->rndnu_neon.a_zero_point);
34 #endif
35 const int32x4_t vleft_pre_shift = vld1q_dup_s32(&params->rndnu_neon.left_pre_shift);
36 const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
37 const int32x4_t vleft_post_shift = vld1q_dup_s32(&params->rndnu_neon.left_post_shift);
38 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
39 const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
40 const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
41
42 const int8x8_t vb = vld1_dup_s8(input_b);
43 const int8x8_t vb_zero_point = vld1_dup_s8(&params->rndnu_neon.b_zero_point);
44 const int16x8_t vxb = vsubl_s8(vb, vb_zero_point);
45 for (; batch >= 16 * sizeof(int8_t); batch -= 16 * sizeof(int8_t)) {
46 const int8x16_t va0123456789ABCDEF = vld1q_s8(input_a); input_a += 16;
47
48 #if XNN_ARCH_ARM64
49 const int16x8_t vxa01234567 = vsubl_s8(vget_low_s8(va0123456789ABCDEF), vget_low_s8(va_zero_point));
50 const int16x8_t vxa89ABCDEF = vsubl_high_s8(va0123456789ABCDEF, va_zero_point);
51 #else // !XNN_ARCH_ARM64
52 const int16x8_t vxa01234567 = vsubl_s8(vget_low_s8(va0123456789ABCDEF), va_zero_point);
53 const int16x8_t vxa89ABCDEF = vsubl_s8(vget_high_s8(va0123456789ABCDEF), va_zero_point);
54 #endif // XNN_ARCH_ARM64
55
56 int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb));
57 int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb));
58 int32x4_t vacc89AB = vmull_s16(vget_low_s16(vxa89ABCDEF), vget_low_s16(vxb));
59 int32x4_t vaccCDEF = vmull_s16(vget_high_s16(vxa89ABCDEF), vget_high_s16(vxb));
60
61 vacc0123 = vqshlq_s32(vacc0123, vleft_pre_shift);
62 vacc4567 = vqshlq_s32(vacc4567, vleft_pre_shift);
63 vacc89AB = vqshlq_s32(vacc89AB, vleft_pre_shift);
64 vaccCDEF = vqshlq_s32(vaccCDEF, vleft_pre_shift);
65
66 vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
67 vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
68 vacc89AB = vqdmulhq_s32(vacc89AB, vmultiplier);
69 vaccCDEF = vqdmulhq_s32(vaccCDEF, vmultiplier);
70
71 vacc0123 = vrshlq_s32(vacc0123, vleft_post_shift);
72 vacc4567 = vrshlq_s32(vacc4567, vleft_post_shift);
73 vacc89AB = vrshlq_s32(vacc89AB, vleft_post_shift);
74 vaccCDEF = vrshlq_s32(vaccCDEF, vleft_post_shift);
75
76 #if XNN_ARCH_ARM64
77 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
78 int16x8_t vacc89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc89AB), vaccCDEF);
79 #else
80 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
81 int16x8_t vacc89ABCDEF = vcombine_s16(vqmovn_s32(vacc89AB), vqmovn_s32(vaccCDEF));
82 #endif
83
84 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
85 vacc89ABCDEF = vqaddq_s16(vacc89ABCDEF, voutput_zero_point);
86
87 #if XNN_ARCH_ARM64
88 int8x16_t vout0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc01234567), vacc89ABCDEF);
89 #else
90 int8x16_t vout0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc01234567), vqmovn_s16(vacc89ABCDEF));
91 #endif
92
93 vout0123456789ABCDEF = vmaxq_s8(vout0123456789ABCDEF, voutput_min);
94
95 vout0123456789ABCDEF = vminq_s8(vout0123456789ABCDEF, voutput_max);
96
97 vst1q_s8(output, vout0123456789ABCDEF); output += 16;
98 }
99 if XNN_UNLIKELY(batch != 0) {
100 do {
101 const int8x8_t va01234567 = vld1_s8(input_a); input_a += 8;
102
103 #if XNN_ARCH_ARM64
104 const int16x8_t vxa01234567 = vsubl_s8(va01234567, vget_low_s8(va_zero_point));
105 #else // !XNN_ARCH_ARM64
106 const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
107 #endif // XNN_ARCH_ARM64
108
109 int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb));
110 int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb));
111
112 vacc0123 = vqshlq_s32(vacc0123, vleft_pre_shift);
113 vacc4567 = vqshlq_s32(vacc4567, vleft_pre_shift);
114
115 vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
116 vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
117
118 vacc0123 = vrshlq_s32(vacc0123, vleft_post_shift);
119 vacc4567 = vrshlq_s32(vacc4567, vleft_post_shift);
120
121 #if XNN_ARCH_ARM64
122 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
123 #else
124 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
125 #endif
126
127 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
128
129 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
130
131 vout01234567 = vmax_s8(vout01234567, vget_low_s8(voutput_min));
132 vout01234567 = vmin_s8(vout01234567, vget_low_s8(voutput_max));
133 if XNN_LIKELY(batch >= (8 * sizeof(int8_t))) {
134 vst1_s8(output, vout01234567); output += 8;
135 batch -= 8 * sizeof(int8_t);
136 } else {
137 if (batch & (4 * sizeof(int8_t))) {
138 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
139 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
140 }
141 if (batch & (2 * sizeof(int8_t))) {
142 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
143 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
144 }
145 if (batch & (1 * sizeof(int8_t))) {
146 vst1_lane_s8(output, vout01234567, 0);
147 }
148 batch = 0;
149 }
150 } while (batch != 0);
151 }
152 }