• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_x4(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_x4(
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   for (; n >= 4 * sizeof(uint8_t); n -= 4 * sizeof(uint8_t)) {
25     int32_t vacc0 = x[0];
26     int32_t vacc1 = x[1];
27     int32_t vacc2 = x[2];
28     int32_t vacc3 = x[3];
29     x += 4;
30 
31     vacc0 = vbias + vacc0 * vmultiplier;
32     vacc1 = vbias + vacc1 * vmultiplier;
33     vacc2 = vbias + vacc2 * vmultiplier;
34     vacc3 = vbias + vacc3 * vmultiplier;
35 
36     int32_t vout0 = math_asr_s32(vacc0, 8);
37     int32_t vout1 = math_asr_s32(vacc1, 8);
38     int32_t vout2 = math_asr_s32(vacc2, 8);
39     int32_t vout3 = math_asr_s32(vacc3, 8);
40 
41     vout0 = math_max_s32(vout0, 0);
42     vout1 = math_max_s32(vout1, 0);
43     vout2 = math_max_s32(vout2, 0);
44     vout3 = math_max_s32(vout3, 0);
45 
46     vout0 = math_min_s32(vout0, 255);
47     vout1 = math_min_s32(vout1, 255);
48     vout2 = math_min_s32(vout2, 255);
49     vout3 = math_min_s32(vout3, 255);
50 
51     y[0] = (uint8_t) vout0;
52     y[1] = (uint8_t) vout1;
53     y[2] = (uint8_t) vout2;
54     y[3] = (uint8_t) vout3;
55     y += 4;
56   }
57   if XNN_UNLIKELY(n != 0) {
58     do {
59       int32_t vacc = *x++;
60       vacc = vbias + vacc * vmultiplier;
61 
62       int32_t vout = math_asr_s32(vacc, 8);
63       vout = math_max_s32(vout, 0);
64       vout = math_min_s32(vout, 255);
65       *y++ = (uint8_t) vout;
66 
67       n -= sizeof(uint8_t);
68     } while (n != 0);
69   }
70 }
71