xref: /aosp_15_r20/external/XNNPACK/src/qs8-f32-vcvt/gen/vcvt-scalar-x3.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-f32-vcvt/scalar.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 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/common.h>
13 #include <xnnpack/math.h>
14 #include <xnnpack/vcvt.h>
15 
16 
xnn_qs8_f32_vcvt_ukernel__scalar_x3(size_t n,const int8_t * x,float * y,const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_qs8_f32_vcvt_ukernel__scalar_x3(
18     size_t n,
19     const int8_t* x,
20     float* y,
21     const union xnn_qs8_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)])
22 {
23   assert(n != 0);
24   assert(n % sizeof(int8_t) == 0);
25   assert(x != NULL);
26   assert(y != NULL);
27 
28   const int32_t vzero_point = params->scalar.zero_point;
29   const float vscale = params->scalar.scale;
30 
31   for (; n >= 3 * sizeof(int8_t); n -= 3 * sizeof(int8_t)) {
32     int32_t vx0 = (int32_t) x[0];
33     int32_t vx1 = (int32_t) x[1];
34     int32_t vx2 = (int32_t) x[2];
35     x += 3;
36 
37     vx0 -= vzero_point;
38     vx1 -= vzero_point;
39     vx2 -= vzero_point;
40 
41     float vy0 = (float) vx0;
42     float vy1 = (float) vx1;
43     float vy2 = (float) vx2;
44 
45     vy0 *= vscale;
46     vy1 *= vscale;
47     vy2 *= vscale;
48 
49     y[0] = vy0;
50     y[1] = vy1;
51     y[2] = vy2;
52     y += 3;
53   }
54   if XNN_UNLIKELY(n != 0) {
55     do {
56       int32_t vx = *x++;
57       vx -= vzero_point;
58 
59       float vy = (float) vx;
60       vy *= vscale;
61       *y++ = vy;
62 
63       n -= sizeof(int8_t);
64     } while (n != 0);
65   }
66 }
67