xref: /aosp_15_r20/external/XNNPACK/src/qs8-vmulc/gen/minmax-fp32-neon-ld64-x8.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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/vmul.h>
15 
16 
xnn_qs8_vmulc_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_vmulc_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 float32x4_t vscale = vld1q_dup_f32(&params->fp32_neon.scale);
26   const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias);
27   const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point);
28   const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neon.output_min);
29   const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neon.output_max);
30 
31   const int8x8_t vb = vld1_dup_s8(input_b);
32   const int8x8_t vb_zero_point = vld1_dup_s8(params->fp32_neon.b_zero_point);
33   const int16x8_t vxb = vsubl_s8(vb, vb_zero_point);
34   for (; n >= 8 * sizeof(int8_t); n -= 8 * sizeof(int8_t)) {
35     const int8x8_t va01234567 = vld1_s8(input_a); input_a += 8;
36 
37     const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
38 
39     int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb));
40     int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb));
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 
77       const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
78 
79       int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb));
80       int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb));
81 
82       float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
83       float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
84 
85       vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
86       vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
87 
88       vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
89       vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
90 
91       vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
92       vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
93 
94       #if XNN_ARCH_ARM64
95         int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
96       #else
97         int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
98       #endif
99 
100 
101       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
102 
103       vout01234567 = vmax_s8(vout01234567, voutput_min);
104       vout01234567 = vmin_s8(vout01234567, voutput_max);
105       if (n & (4 * sizeof(int8_t))) {
106         vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
107         vout01234567 = vext_s8(vout01234567, vout01234567, 4);
108       }
109       if (n & (2 * sizeof(int8_t))) {
110         vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
111         vout01234567 = vext_s8(vout01234567, vout01234567, 2);
112       }
113       if (n & (1 * sizeof(int8_t))) {
114         vst1_lane_s8(output, vout01234567, 0);
115       }
116     }
117   }
118 }
119