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_qs8_vlrelu_ukernel__scalar_andxor_x2(size_t n,const int8_t * x,int8_t * y,const union xnn_qs8_lrelu_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qs8_vlrelu_ukernel__scalar_andxor_x2(
17 size_t n,
18 const int8_t* x,
19 int8_t* y,
20 const union xnn_qs8_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 >= 2 * sizeof(int8_t); n -= 2 * sizeof(int8_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 int32_t vmultiplier0 = math_asr_s32(vacc0, 31);
35 int32_t vmultiplier1 = math_asr_s32(vacc1, 31);
36
37 vmultiplier0 &= vmultiplier_diff;
38 vmultiplier1 &= vmultiplier_diff;
39
40 vmultiplier0 ^= vmultiplier_base;
41 vmultiplier1 ^= vmultiplier_base;
42
43 vacc0 = vbias + vacc0 * vmultiplier0;
44 vacc1 = vbias + vacc1 * vmultiplier1;
45
46 int32_t vout0 = math_asr_s32(vacc0, 8);
47 int32_t vout1 = math_asr_s32(vacc1, 8);
48
49 vout0 = math_max_s32(vout0, -128);
50 vout1 = math_max_s32(vout1, -128);
51
52 vout0 = math_min_s32(vout0, 127);
53 vout1 = math_min_s32(vout1, 127);
54
55 y[0] = (int8_t) vout0;
56 y[1] = (int8_t) vout1;
57 y += 2;
58 }
59 if XNN_UNLIKELY(n != 0) {
60 int32_t vacc = (int32_t) *x++ - vinput_zero_point;
61 const int32_t vmultiplier = vmultiplier_base ^ (vmultiplier_diff & math_asr_s32(vacc, 31));
62 vacc = vbias + vacc * vmultiplier;
63
64 int32_t vout = math_asr_s32(vacc, 8);
65 vout = math_max_s32(vout, -128);
66 vout = math_min_s32(vout, 127);
67 *y = (int8_t) vout;
68 }
69 }
70