xref: /aosp_15_r20/external/XNNPACK/src/qs8-vaddc/gen/minmax-scalar-x4.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-vaddc/scalar.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 <xnnpack/math.h>
13 #include <xnnpack/vadd.h>
14 
15 
xnn_qs8_vaddc_minmax_ukernel__scalar_x4(size_t n,const int8_t * input_a,const int8_t * input_b,int8_t * output,const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qs8_vaddc_minmax_ukernel__scalar_x4(
17     size_t n,
18     const int8_t* input_a,
19     const int8_t* input_b,
20     int8_t* output,
21     const union xnn_qs8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
22 {
23   const int32_t vbias = params->scalar.bias + (int32_t) *input_b * params->scalar.b_multiplier;
24   const int32_t va_multiplier = params->scalar.a_multiplier;
25   const uint32_t vshift = params->scalar.shift;
26   const int32_t voutput_min_less_zero_point = params->scalar.output_min_less_zero_point;
27   const int32_t voutput_max_less_zero_point = params->scalar.output_max_less_zero_point;
28   const int32_t voutput_zero_point = params->scalar.output_zero_point;
29 
30   for (; n >= 4 * sizeof(int8_t); n -= 4 * sizeof(int8_t)) {
31     const int32_t va0 = input_a[0];
32     const int32_t va1 = input_a[1];
33     const int32_t va2 = input_a[2];
34     const int32_t va3 = input_a[3];
35     input_a += 4;
36 
37     const int32_t vacc0 = vbias + va0 * va_multiplier;
38     const int32_t vacc1 = vbias + va1 * va_multiplier;
39     const int32_t vacc2 = vbias + va2 * va_multiplier;
40     const int32_t vacc3 = vbias + va3 * va_multiplier;
41     input_b += 4;
42 
43     int32_t vout0 = math_asr_s32(vacc0, vshift);
44     int32_t vout1 = math_asr_s32(vacc1, vshift);
45     int32_t vout2 = math_asr_s32(vacc2, vshift);
46     int32_t vout3 = math_asr_s32(vacc3, vshift);
47 
48     vout0 = math_max_s32(vout0, voutput_min_less_zero_point);
49     vout1 = math_max_s32(vout1, voutput_min_less_zero_point);
50     vout2 = math_max_s32(vout2, voutput_min_less_zero_point);
51     vout3 = math_max_s32(vout3, voutput_min_less_zero_point);
52 
53     vout0 = math_min_s32(vout0, voutput_max_less_zero_point);
54     vout1 = math_min_s32(vout1, voutput_max_less_zero_point);
55     vout2 = math_min_s32(vout2, voutput_max_less_zero_point);
56     vout3 = math_min_s32(vout3, voutput_max_less_zero_point);
57 
58     vout0 += voutput_zero_point;
59     vout1 += voutput_zero_point;
60     vout2 += voutput_zero_point;
61     vout3 += voutput_zero_point;
62 
63     output[0] = (int8_t) vout0;
64     output[1] = (int8_t) vout1;
65     output[2] = (int8_t) vout2;
66     output[3] = (int8_t) vout3;
67     output += 4;
68   }
69   if XNN_UNLIKELY(n != 0) {
70     do {
71       const int32_t va = *input_a++;
72       const int32_t vacc = vbias + va * va_multiplier;
73 
74       int32_t vout = math_asr_s32(vacc, vshift);
75       vout = math_max_s32(vout, voutput_min_less_zero_point);
76       vout = math_min_s32(vout, voutput_max_less_zero_point);
77       *output++ = (int8_t) (vout + voutput_zero_point);
78 
79       n -= sizeof(int8_t);
80     } while (n != 0);
81   }
82 }
83