xref: /aosp_15_r20/external/XNNPACK/src/qu8-vlrelu/gen/vlrelu-scalar-select-x4.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-vlrelu/scalar-select.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2022 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/vlrelu.h>
14 
15 
xnn_qu8_vlrelu_ukernel__scalar_select_x4(size_t n,const uint8_t * x,uint8_t * y,const union xnn_qu8_lrelu_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qu8_vlrelu_ukernel__scalar_select_x4(
17     size_t n,
18     const uint8_t* x,
19     uint8_t* y,
20     const union xnn_qu8_lrelu_params params[restrict XNN_MIN_ELEMENTS(1)])
21 {
22   const int32_t vinput_zero_point = params->scalar_select.input_zero_point;
23   const int32_t vpositive_multiplier = params->scalar_select.positive_multiplier;
24   const int32_t vnegative_multiplier = params->scalar_select.negative_multiplier;
25   const int32_t vbias = params->scalar_select.bias;
26   for (; n >= 4 * sizeof(uint8_t); n -= 4 * sizeof(uint8_t)) {
27     int32_t vacc0 = (int32_t) x[0];
28     int32_t vacc1 = (int32_t) x[1];
29     int32_t vacc2 = (int32_t) x[2];
30     int32_t vacc3 = (int32_t) x[3];
31     x += 4;
32 
33     vacc0 -= vinput_zero_point;
34     vacc1 -= vinput_zero_point;
35     vacc2 -= vinput_zero_point;
36     vacc3 -= vinput_zero_point;
37 
38     const int32_t vmultiplier0 = XNN_UNPREDICTABLE(vacc0 >= 0) ? vpositive_multiplier : vnegative_multiplier;
39     const int32_t vmultiplier1 = XNN_UNPREDICTABLE(vacc1 >= 0) ? vpositive_multiplier : vnegative_multiplier;
40     const int32_t vmultiplier2 = XNN_UNPREDICTABLE(vacc2 >= 0) ? vpositive_multiplier : vnegative_multiplier;
41     const int32_t vmultiplier3 = XNN_UNPREDICTABLE(vacc3 >= 0) ? vpositive_multiplier : vnegative_multiplier;
42 
43     vacc0 = vbias + vacc0 * vmultiplier0;
44     vacc1 = vbias + vacc1 * vmultiplier1;
45     vacc2 = vbias + vacc2 * vmultiplier2;
46     vacc3 = vbias + vacc3 * vmultiplier3;
47 
48     int32_t vout0 = math_asr_s32(vacc0, 8);
49     int32_t vout1 = math_asr_s32(vacc1, 8);
50     int32_t vout2 = math_asr_s32(vacc2, 8);
51     int32_t vout3 = math_asr_s32(vacc3, 8);
52 
53     vout0 = math_max_s32(vout0, 0);
54     vout1 = math_max_s32(vout1, 0);
55     vout2 = math_max_s32(vout2, 0);
56     vout3 = math_max_s32(vout3, 0);
57 
58     vout0 = math_min_s32(vout0, 255);
59     vout1 = math_min_s32(vout1, 255);
60     vout2 = math_min_s32(vout2, 255);
61     vout3 = math_min_s32(vout3, 255);
62 
63     y[0] = (uint8_t) vout0;
64     y[1] = (uint8_t) vout1;
65     y[2] = (uint8_t) vout2;
66     y[3] = (uint8_t) vout3;
67     y += 4;
68   }
69   if XNN_UNLIKELY(n != 0) {
70     do {
71       int32_t vacc = (int32_t) *x++ - vinput_zero_point;
72       const int32_t vmultiplier = XNN_UNPREDICTABLE(vacc >= 0) ? vpositive_multiplier : vnegative_multiplier;
73       vacc = vbias + vacc * vmultiplier;
74 
75       int32_t vout = math_asr_s32(vacc, 8);
76       vout = math_max_s32(vout, 0);
77       vout = math_min_s32(vout, 255);
78       *y++ = (uint8_t) vout;
79 
80       n -= sizeof(uint8_t);
81     } while (n != 0);
82   }
83 }
84