• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-vadd/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_vadd_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_vadd_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;
24   const int32_t va_multiplier = params->scalar.a_multiplier;
25   const int32_t vb_multiplier = params->scalar.b_multiplier;
26   const uint32_t vshift = params->scalar.shift;
27   const int32_t voutput_min_less_zero_point = params->scalar.output_min_less_zero_point;
28   const int32_t voutput_max_less_zero_point = params->scalar.output_max_less_zero_point;
29   const int32_t voutput_zero_point = params->scalar.output_zero_point;
30 
31   for (; n >= 4 * sizeof(int8_t); n -= 4 * sizeof(int8_t)) {
32     const int32_t va0 = input_a[0];
33     const int32_t va1 = input_a[1];
34     const int32_t va2 = input_a[2];
35     const int32_t va3 = input_a[3];
36     input_a += 4;
37 
38     const int32_t vb0 = input_b[0];
39     int32_t vacc0 = vbias + va0 * va_multiplier;
40     const int32_t vb1 = input_b[1];
41     int32_t vacc1 = vbias + va1 * va_multiplier;
42     const int32_t vb2 = input_b[2];
43     int32_t vacc2 = vbias + va2 * va_multiplier;
44     const int32_t vb3 = input_b[3];
45     int32_t vacc3 = vbias + va3 * va_multiplier;
46     input_b += 4;
47 
48     vacc0 += vb0 * vb_multiplier;
49     vacc1 += vb1 * vb_multiplier;
50     vacc2 += vb2 * vb_multiplier;
51     vacc3 += vb3 * vb_multiplier;
52 
53     int32_t vout0 = math_asr_s32(vacc0, vshift);
54     int32_t vout1 = math_asr_s32(vacc1, vshift);
55     int32_t vout2 = math_asr_s32(vacc2, vshift);
56     int32_t vout3 = math_asr_s32(vacc3, vshift);
57 
58     vout0 = math_max_s32(vout0, voutput_min_less_zero_point);
59     vout1 = math_max_s32(vout1, voutput_min_less_zero_point);
60     vout2 = math_max_s32(vout2, voutput_min_less_zero_point);
61     vout3 = math_max_s32(vout3, voutput_min_less_zero_point);
62 
63     vout0 = math_min_s32(vout0, voutput_max_less_zero_point);
64     vout1 = math_min_s32(vout1, voutput_max_less_zero_point);
65     vout2 = math_min_s32(vout2, voutput_max_less_zero_point);
66     vout3 = math_min_s32(vout3, voutput_max_less_zero_point);
67 
68     vout0 += voutput_zero_point;
69     vout1 += voutput_zero_point;
70     vout2 += voutput_zero_point;
71     vout3 += voutput_zero_point;
72 
73     output[0] = (int8_t) vout0;
74     output[1] = (int8_t) vout1;
75     output[2] = (int8_t) vout2;
76     output[3] = (int8_t) vout3;
77     output += 4;
78   }
79   if XNN_UNLIKELY(n != 0) {
80     do {
81       const int32_t va = *input_a++;
82       const int32_t vb = *input_b++;
83       const int32_t vacc = vbias + va * va_multiplier + vb * vb_multiplier;
84 
85       int32_t vout = math_asr_s32(vacc, vshift);
86       vout = math_max_s32(vout, voutput_min_less_zero_point);
87       vout = math_min_s32(vout, voutput_max_less_zero_point);
88       *output++ = (int8_t) (vout + voutput_zero_point);
89 
90       n -= sizeof(int8_t);
91     } while (n != 0);
92   }
93 }
94