xref: /aosp_15_r20/external/XNNPACK/src/qs8-vcvt/gen/vcvt-scalar-x2.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-vcvt/scalar.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/vcvt.h>
14 
15 
xnn_qs8_vcvt_ukernel__scalar_x2(size_t n,const int8_t * x,int8_t * y,const union xnn_qs8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qs8_vcvt_ukernel__scalar_x2(
17     size_t n,
18     const int8_t* x,
19     int8_t* y,
20     const union xnn_qs8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)])
21 {
22   const int32_t vbias = params->scalar.bias;
23   const int32_t vmultiplier = params->scalar.multiplier;
24   for (; n >= 2 * sizeof(int8_t); n -= 2 * sizeof(int8_t)) {
25     int32_t vacc0 = x[0];
26     int32_t vacc1 = x[1];
27     x += 2;
28 
29     vacc0 = vbias + vacc0 * vmultiplier;
30     vacc1 = vbias + vacc1 * vmultiplier;
31 
32     int32_t vout0 = math_asr_s32(vacc0, 8);
33     int32_t vout1 = math_asr_s32(vacc1, 8);
34 
35     vout0 = math_max_s32(vout0, -128);
36     vout1 = math_max_s32(vout1, -128);
37 
38     vout0 = math_min_s32(vout0, 127);
39     vout1 = math_min_s32(vout1, 127);
40 
41     y[0] = (int8_t) vout0;
42     y[1] = (int8_t) vout1;
43     y += 2;
44   }
45   if XNN_UNLIKELY(n != 0) {
46     int32_t vacc = *x;
47     vacc = vbias + vacc * vmultiplier;
48 
49     int32_t vout = math_asr_s32(vacc, 8);
50     vout = math_max_s32(vout, -128);
51     vout = math_min_s32(vout, 127);
52     *y = (int8_t) vout;
53   }
54 }
55