Debian Codegraph @

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