| 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_u1( |
| 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 |
do { |
| 33 |
int32_t vacc = *input++; |
| 34 |
vacc = vbias + vacc * vmultiplier; |
| 35 |
|
| 36 |
int32_t vout = math_asr_s32(vacc, 8); |
| 37 |
vout = math_max_s32(vout, 0); |
| 38 |
vout = math_min_s32(vout, 255); |
| 39 |
*output++ = (uint8_t) vout; |
| 40 |
|
| 41 |
batch -= sizeof(uint8_t); |
| 42 |
} while (batch != 0); |
| 43 |
} |