xref: /aosp_15_r20/external/XNNPACK/src/qu8-vaddc/gen/minmax-scalar-x2.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_qu8_vaddc_minmax_ukernel__scalar_x2(size_t n,const uint8_t * input_a,const uint8_t * input_b,uint8_t * output,const union xnn_qu8_add_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qu8_vaddc_minmax_ukernel__scalar_x2(
17     size_t n,
18     const uint8_t* input_a,
19     const uint8_t* input_b,
20     uint8_t* output,
21     const union xnn_qu8_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 >= 2 * sizeof(uint8_t); n -= 2 * sizeof(uint8_t)) {
31     const int32_t va0 = input_a[0];
32     const int32_t va1 = input_a[1];
33     input_a += 2;
34 
35     const int32_t vacc0 = vbias + va0 * va_multiplier;
36     const int32_t vacc1 = vbias + va1 * va_multiplier;
37     input_b += 2;
38 
39     int32_t vout0 = math_asr_s32(vacc0, vshift);
40     int32_t vout1 = math_asr_s32(vacc1, vshift);
41 
42     vout0 = math_max_s32(vout0, voutput_min_less_zero_point);
43     vout1 = math_max_s32(vout1, voutput_min_less_zero_point);
44 
45     vout0 = math_min_s32(vout0, voutput_max_less_zero_point);
46     vout1 = math_min_s32(vout1, voutput_max_less_zero_point);
47 
48     vout0 += voutput_zero_point;
49     vout1 += voutput_zero_point;
50 
51     output[0] = (uint8_t) vout0;
52     output[1] = (uint8_t) vout1;
53     output += 2;
54   }
55   if XNN_UNLIKELY(n != 0) {
56     const int32_t va = *input_a;
57     const int32_t vacc = vbias + va * va_multiplier;
58 
59     int32_t vout = math_asr_s32(vacc, vshift);
60     vout = math_max_s32(vout, voutput_min_less_zero_point);
61     vout = math_min_s32(vout, voutput_max_less_zero_point);
62     *output++ = (uint8_t) (vout + voutput_zero_point);
63   }
64 }
65