xref: /aosp_15_r20/external/XNNPACK/src/qs8-vmul/gen/minmax-fp32-neonv8-ld64-x8.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
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/intrinsics-polyfill.h>
15 #include <xnnpack/vmul.h>
16 
17 
xnn_qs8_vmul_minmax_fp32_ukernel__neonv8_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)])18 void xnn_qs8_vmul_minmax_fp32_ukernel__neonv8_ld64_x8(
19     size_t n,
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   const int8x8_t va_zero_point = vld1_dup_s8(params->fp32_neonv8.a_zero_point);
26   const int8x8_t vb_zero_point = vld1_dup_s8(params->fp32_neonv8.b_zero_point);
27   const float32x4_t vscale = vld1q_dup_f32(&params->fp32_neonv8.scale);
28   const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
29   const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neonv8.output_min);
30   const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neonv8.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 = vcvtnq_s32_f32(vfpacc0123);
49     vacc4567 = vcvtnq_s32_f32(vfpacc4567);
50 
51     #if XNN_ARCH_ARM64
52       int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
53     #else
54       int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
55     #endif
56 
57     vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
58 
59     #if XNN_ARCH_ARM64
60       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
61     #else
62       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
63     #endif
64 
65     vout01234567 = vmax_s8(vout01234567, voutput_min);
66 
67     vout01234567 = vmin_s8(vout01234567, voutput_max);
68 
69     vst1_s8(output, vout01234567); output += 8;
70   }
71   if XNN_UNLIKELY(n != 0) {
72     {
73       const int8x8_t va01234567 = vld1_s8(input_a);
74       const int8x8_t vb01234567 = vld1_s8(input_b);
75 
76       const int16x8_t vxa01234567 = vsubl_s8(va01234567, va_zero_point);
77       const int16x8_t vxb01234567 = vsubl_s8(vb01234567, vb_zero_point);
78 
79       int32x4_t vacc0123 = vmull_s16(vget_low_s16(vxa01234567), vget_low_s16(vxb01234567));
80       int32x4_t vacc4567 = vmull_s16(vget_high_s16(vxa01234567), vget_high_s16(vxb01234567));
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 = vcvtnq_s32_f32(vfpacc0123);
89       vacc4567 = vcvtnq_s32_f32(vfpacc4567);
90 
91       #if XNN_ARCH_ARM64
92         int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
93       #else
94         int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
95       #endif
96 
97       vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
98 
99       int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
100 
101       vout01234567 = vmax_s8(vout01234567, voutput_min);
102       vout01234567 = vmin_s8(vout01234567, voutput_max);
103       if (n & (4 * sizeof(int8_t))) {
104         vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
105         vout01234567 = vext_s8(vout01234567, vout01234567, 4);
106       }
107       if (n & (2 * sizeof(int8_t))) {
108         vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
109         vout01234567 = vext_s8(vout01234567, vout01234567, 2);
110       }
111       if (n & (1 * sizeof(int8_t))) {
112         vst1_lane_s8(output, vout01234567, 0);
113       }
114     }
115   }
116 }
117