xref: /aosp_15_r20/external/XNNPACK/src/qu8-vcvt/gen/vcvt-scalar-x1.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_qu8_vcvt_ukernel__scalar_x1(size_t n,const uint8_t * x,uint8_t * y,const union xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_qu8_vcvt_ukernel__scalar_x1(
17     size_t n,
18     const uint8_t* x,
19     uint8_t* y,
20     const union xnn_qu8_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   do {
25     int32_t vacc = *x++;
26     vacc = vbias + vacc * vmultiplier;
27 
28     int32_t vout = math_asr_s32(vacc, 8);
29     vout = math_max_s32(vout, 0);
30     vout = math_min_s32(vout, 255);
31     *y++ = (uint8_t) vout;
32 
33     n -= sizeof(uint8_t);
34   } while (n != 0);
35 }
36