1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-vmul/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_vmul_minmax_fp32_ukernel__neon_ld64_x8(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_vmul_minmax_fp32_ukernel__neon_ld64_x8(
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 const int8x8_t va_zero_point = vld1_dup_s8(params->fp32_neon.a_zero_point);
25 const int8x8_t vb_zero_point = vld1_dup_s8(params->fp32_neon.b_zero_point);
26 const float32x4_t vscale = vld1q_dup_f32(¶ms->fp32_neon.scale);
27 const float32x4_t vmagic_bias = vld1q_dup_f32(¶ms->fp32_neon.magic_bias);
28 const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(¶ms->fp32_neon.magic_bias_less_output_zero_point);
29 const int8x8_t voutput_min = vld1_dup_s8(¶ms->fp32_neon.output_min);
30 const int8x8_t voutput_max = vld1_dup_s8(¶ms->fp32_neon.output_max);
31
32 for (; n >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
33 const int8x8_t va01234567 = vld1_s8(input_a); input_a += 8;
34 const int8x8_t vb01234567 = vld1_s8(input_b); input_b += 8;
35
36 const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
37 const int16x8_t vxb01234567 = vsubl_s8(vb01234567, vb_zero_point);
38
39 int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb01234567));
40 int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb01234567));
41
42 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
43 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
44
45 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
46 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
47
48 vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
49 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
50
51 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
52 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
53
54 #if XNN_ARCH_ARM64
55 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
56 #else
57 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
58 #endif
59
60
61 #if XNN_ARCH_ARM64
62 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
63 #else
64 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
65 #endif
66
67 vout01234567 = vmax_s8(vout01234567, voutput_min);
68
69 vout01234567 = vmin_s8(vout01234567, voutput_max);
70
71 vst1_s8(output, vout01234567); output += 8;
72 }
73 if XNN_UNLIKELY(n != 0) {
74 {
75 const int8x8_t va01234567 = vld1_s8(input_a);
76 const int8x8_t vb01234567 = vld1_s8(input_b);
77
78 const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
79 const int16x8_t vxb01234567 = vsubl_s8(vb01234567, vb_zero_point);
80
81 int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb01234567));
82 int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb01234567));
83
84 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
85 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
86
87 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
88 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
89
90 vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
91 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
92
93 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
94 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
95
96 #if XNN_ARCH_ARM64
97 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
98 #else
99 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
100 #endif
101
102
103 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
104
105 vout01234567 = vmax_s8(vout01234567, voutput_min);
106 vout01234567 = vmin_s8(vout01234567, voutput_max);
107 if (n & (4 * sizeof(int8_t))) {
108 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
109 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
110 }
111 if (n & (2 * sizeof(int8_t))) {
112 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
113 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
114 }
115 if (n & (1 * sizeof(int8_t))) {
116 vst1_lane_s8(output, vout01234567, 0);
117 }
118 }
119 }
120 }
121