xref: /aosp_15_r20/external/XNNPACK/src/qu8-vlrelu/gen/vlrelu-scalar-andxor-x1.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-vlrelu/scalar-andxor.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_andxor_x1(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_andxor_x1(
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_andxor.input_zero_point;
23   const int32_t vmultiplier_diff = params->scalar_andxor.multiplier_diff;
24   const int32_t vmultiplier_base = params->scalar_andxor.multiplier_base;
25   const int32_t vbias = params->scalar_andxor.bias;
26   do {
27     int32_t vacc = (int32_t) *x++ - vinput_zero_point;
28     const int32_t vmultiplier = vmultiplier_base ^ (vmultiplier_diff & math_asr_s32(vacc, 31));
29     vacc = vbias + vacc * vmultiplier;
30 
31     int32_t vout = math_asr_s32(vacc, 8);
32     vout = math_max_s32(vout, 0);
33     vout = math_min_s32(vout, 255);
34     *y++ = (uint8_t) vout;
35 
36     n -= sizeof(uint8_t);
37   } while (n != 0);
38 }
39