| 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_u4( |
| 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 >= 4 * sizeof(uint8_t); batch -= 4 * sizeof(uint8_t)) { |
| 33 |
int32_t vacc0 = input[0]; |
| 34 |
int32_t vacc1 = input[1]; |
| 35 |
int32_t vacc2 = input[2]; |
| 36 |
int32_t vacc3 = input[3]; |
| 37 |
input += 4; |
| 38 |
|
| 39 |
vacc0 = vbias + vacc0 * vmultiplier; |
| 40 |
vacc1 = vbias + vacc1 * vmultiplier; |
| 41 |
vacc2 = vbias + vacc2 * vmultiplier; |
| 42 |
vacc3 = vbias + vacc3 * vmultiplier; |
| 43 |
|
| 44 |
int32_t vout0 = math_asr_s32(vacc0, 8); |
| 45 |
int32_t vout1 = math_asr_s32(vacc1, 8); |
| 46 |
int32_t vout2 = math_asr_s32(vacc2, 8); |
| 47 |
int32_t vout3 = math_asr_s32(vacc3, 8); |
| 48 |
|
| 49 |
vout0 = math_max_s32(vout0, 0); |
| 50 |
vout1 = math_max_s32(vout1, 0); |
| 51 |
vout2 = math_max_s32(vout2, 0); |
| 52 |
vout3 = math_max_s32(vout3, 0); |
| 53 |
|
| 54 |
vout0 = math_min_s32(vout0, 255); |
| 55 |
vout1 = math_min_s32(vout1, 255); |
| 56 |
vout2 = math_min_s32(vout2, 255); |
| 57 |
vout3 = math_min_s32(vout3, 255); |
| 58 |
|
| 59 |
output[0] = (uint8_t) vout0; |
| 60 |
output[1] = (uint8_t) vout1; |
| 61 |
output[2] = (uint8_t) vout2; |
| 62 |
output[3] = (uint8_t) vout3; |
| 63 |
output += 4; |
| 64 |
} |
| 65 |
if XNN_UNLIKELY(batch != 0) { |
| 66 |
do { |
| 67 |
int32_t vacc = *input++; |
| 68 |
vacc = vbias + vacc * vmultiplier; |
| 69 |
|
| 70 |
int32_t vout = math_asr_s32(vacc, 8); |
| 71 |
vout = math_max_s32(vout, 0); |
| 72 |
vout = math_min_s32(vout, 255); |
| 73 |
*output++ = (uint8_t) vout; |
| 74 |
|
| 75 |
batch -= sizeof(uint8_t); |
| 76 |
} while (batch != 0); |
| 77 |
} |
| 78 |
} |