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_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_andxor_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_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 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 int32_t vmultiplier0 = math_asr_s32(vacc0, 31);
39 int32_t vmultiplier1 = math_asr_s32(vacc1, 31);
40 int32_t vmultiplier2 = math_asr_s32(vacc2, 31);
41 int32_t vmultiplier3 = math_asr_s32(vacc3, 31);
42
43 vmultiplier0 &= vmultiplier_diff;
44 vmultiplier1 &= vmultiplier_diff;
45 vmultiplier2 &= vmultiplier_diff;
46 vmultiplier3 &= vmultiplier_diff;
47
48 vmultiplier0 ^= vmultiplier_base;
49 vmultiplier1 ^= vmultiplier_base;
50 vmultiplier2 ^= vmultiplier_base;
51 vmultiplier3 ^= vmultiplier_base;
52
53 vacc0 = vbias + vacc0 * vmultiplier0;
54 vacc1 = vbias + vacc1 * vmultiplier1;
55 vacc2 = vbias + vacc2 * vmultiplier2;
56 vacc3 = vbias + vacc3 * vmultiplier3;
57
58 int32_t vout0 = math_asr_s32(vacc0, 8);
59 int32_t vout1 = math_asr_s32(vacc1, 8);
60 int32_t vout2 = math_asr_s32(vacc2, 8);
61 int32_t vout3 = math_asr_s32(vacc3, 8);
62
63 vout0 = math_max_s32(vout0, 0);
64 vout1 = math_max_s32(vout1, 0);
65 vout2 = math_max_s32(vout2, 0);
66 vout3 = math_max_s32(vout3, 0);
67
68 vout0 = math_min_s32(vout0, 255);
69 vout1 = math_min_s32(vout1, 255);
70 vout2 = math_min_s32(vout2, 255);
71 vout3 = math_min_s32(vout3, 255);
72
73 y[0] = (uint8_t) vout0;
74 y[1] = (uint8_t) vout1;
75 y[2] = (uint8_t) vout2;
76 y[3] = (uint8_t) vout3;
77 y += 4;
78 }
79 if XNN_UNLIKELY(n != 0) {
80 do {
81 int32_t vacc = (int32_t) *x++ - vinput_zero_point;
82 const int32_t vmultiplier = vmultiplier_base ^ (vmultiplier_diff & math_asr_s32(vacc, 31));
83 vacc = vbias + vacc * vmultiplier;
84
85 int32_t vout = math_asr_s32(vacc, 8);
86 vout = math_max_s32(vout, 0);
87 vout = math_min_s32(vout, 255);
88 *y++ = (uint8_t) vout;
89
90 n -= sizeof(uint8_t);
91 } while (n != 0);
92 }
93 }
94