Debian Codegraph @

src/qu8-vcvt/gen/qu8-vcvt-scalar-u2.c

raw
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
16 void xnn_qu8_vcvt_ukernel__scalar_u2(
17 size_t batch,
18 const uint8_t* input,
19 uint8_t* output,
20 const struct xnn_qu8_cvt_params params[restrict XNN_MIN_ELEMENTS(1)])
21 {
22 assert(batch != 0);
23 assert(batch % sizeof(uint8_t) == 0);
24 assert(input != NULL);
25 assert(output != NULL);
26
27 const int32_t vbias =
28 (int32_t) (((uint32_t) (int32_t) params->scalar.output_zero_point) << 8) -
29 (int32_t) params->scalar.multiplier * (int32_t) params->scalar.input_zero_point +
30 INT32_C(0x80);
31 const int32_t vmultiplier = params->scalar.multiplier;
32 for (; batch >= 2 * sizeof(uint8_t); batch -= 2 * sizeof(uint8_t)) {
33 int32_t vacc0 = input[0];
34 int32_t vacc1 = input[1];
35 input += 2;
36
37 vacc0 = vbias + vacc0 * vmultiplier;
38 vacc1 = vbias + vacc1 * vmultiplier;
39
40 int32_t vout0 = math_asr_s32(vacc0, 8);
41 int32_t vout1 = math_asr_s32(vacc1, 8);
42
43 vout0 = math_max_s32(vout0, 0);
44 vout1 = math_max_s32(vout1, 0);
45
46 vout0 = math_min_s32(vout0, 255);
47 vout1 = math_min_s32(vout1, 255);
48
49 output[0] = (uint8_t) vout0;
50 output[1] = (uint8_t) vout1;
51 output += 2;
52 }
53 if XNN_UNLIKELY(batch != 0) {
54 int32_t vacc = *input;
55 vacc = vbias + vacc * vmultiplier;
56
57 int32_t vout = math_asr_s32(vacc, 8);
58 vout = math_max_s32(vout, 0);
59 vout = math_min_s32(vout, 255);
60 *output = (uint8_t) vout;
61 }
62 }