xref: /aosp_15_r20/external/XNNPACK/src/qu8-vlrelu/gen/vlrelu-scalar-select-x2.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_x2(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_x2(
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 >= 2 * sizeof(uint8_t); n -= 2 * sizeof(uint8_t)) {
27     int32_t vacc0 = (int32_t) x[0];
28     int32_t vacc1 = (int32_t) x[1];
29     x += 2;
30 
31     vacc0 -= vinput_zero_point;
32     vacc1 -= vinput_zero_point;
33 
34     const int32_t vmultiplier0 = XNN_UNPREDICTABLE(vacc0 >= 0) ? vpositive_multiplier : vnegative_multiplier;
35     const int32_t vmultiplier1 = XNN_UNPREDICTABLE(vacc1 >= 0) ? vpositive_multiplier : vnegative_multiplier;
36 
37     vacc0 = vbias + vacc0 * vmultiplier0;
38     vacc1 = vbias + vacc1 * vmultiplier1;
39 
40     int32_t vout0 = math_asr_s32(vacc0, 8);
41     int32_t vout1 = math_asr_s32(vacc1, 8);
42 
43     vout0 = math_max_s32(vout0, 0);
44     vout1 = math_max_s32(vout1, 0);
45 
46     vout0 = math_min_s32(vout0, 255);
47     vout1 = math_min_s32(vout1, 255);
48 
49     y[0] = (uint8_t) vout0;
50     y[1] = (uint8_t) vout1;
51     y += 2;
52   }
53   if XNN_UNLIKELY(n != 0) {
54     int32_t vacc = (int32_t) *x++ - vinput_zero_point;
55     const int32_t vmultiplier = XNN_UNPREDICTABLE(vacc >= 0) ? vpositive_multiplier : vnegative_multiplier;
56     vacc = vbias + vacc * vmultiplier;
57 
58     int32_t vout = math_asr_s32(vacc, 8);
59     vout = math_max_s32(vout, 0);
60     vout = math_min_s32(vout, 255);
61     *y = (uint8_t) vout;
62   }
63 }
64