| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-vaddc/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/math.h" |
| 13 |
#include "xnnpack/vbinary.h" |
| 14 |
|
| 15 |
|
| 16 |
void xnn_qu8_vaddc_minmax_ukernel__scalar_u4( |
| 17 |
size_t batch, |
| 18 |
const uint8_t* input_a, |
| 19 |
const uint8_t* input_b, |
| 20 |
uint8_t* output, |
| 21 |
const struct xnn_qu8_add_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 22 |
{ |
| 23 |
assert(batch != 0); |
| 24 |
assert(batch % sizeof(uint8_t) == 0); |
| 25 |
assert(input_a != NULL); |
| 26 |
assert(input_b != NULL); |
| 27 |
assert(output != NULL); |
| 28 |
|
| 29 |
const int32_t vbias = params->scalar.bias + (int32_t) *input_b * params->scalar.b_multiplier; |
| 30 |
const int32_t va_multiplier = params->scalar.a_multiplier; |
| 31 |
const uint32_t vshift = params->scalar.shift; |
| 32 |
const int32_t voutput_min = params->scalar.output_min; |
| 33 |
const int32_t voutput_max = params->scalar.output_max; |
| 34 |
const int32_t voutput_zero_point = params->scalar.output_zero_point; |
| 35 |
|
| 36 |
for (; batch >= 4 * sizeof(uint8_t); batch -= 4 * sizeof(uint8_t)) { |
| 37 |
const int32_t va0 = input_a[0]; |
| 38 |
const int32_t va1 = input_a[1]; |
| 39 |
const int32_t va2 = input_a[2]; |
| 40 |
const int32_t va3 = input_a[3]; |
| 41 |
input_a += 4; |
| 42 |
|
| 43 |
const int32_t vacc0 = vbias + va0 * va_multiplier; |
| 44 |
const int32_t vacc1 = vbias + va1 * va_multiplier; |
| 45 |
const int32_t vacc2 = vbias + va2 * va_multiplier; |
| 46 |
const int32_t vacc3 = vbias + va3 * va_multiplier; |
| 47 |
input_b += 4; |
| 48 |
|
| 49 |
int32_t vout0 = math_asr_s32(vacc0, vshift); |
| 50 |
int32_t vout1 = math_asr_s32(vacc1, vshift); |
| 51 |
int32_t vout2 = math_asr_s32(vacc2, vshift); |
| 52 |
int32_t vout3 = math_asr_s32(vacc3, vshift); |
| 53 |
|
| 54 |
vout0 += voutput_zero_point; |
| 55 |
vout1 += voutput_zero_point; |
| 56 |
vout2 += voutput_zero_point; |
| 57 |
vout3 += voutput_zero_point; |
| 58 |
|
| 59 |
vout0 = math_max_s32(vout0, voutput_min); |
| 60 |
vout1 = math_max_s32(vout1, voutput_min); |
| 61 |
vout2 = math_max_s32(vout2, voutput_min); |
| 62 |
vout3 = math_max_s32(vout3, voutput_min); |
| 63 |
|
| 64 |
vout0 = math_min_s32(vout0, voutput_max); |
| 65 |
vout1 = math_min_s32(vout1, voutput_max); |
| 66 |
vout2 = math_min_s32(vout2, voutput_max); |
| 67 |
vout3 = math_min_s32(vout3, voutput_max); |
| 68 |
|
| 69 |
output[0] = (uint8_t) vout0; |
| 70 |
output[1] = (uint8_t) vout1; |
| 71 |
output[2] = (uint8_t) vout2; |
| 72 |
output[3] = (uint8_t) vout3; |
| 73 |
output += 4; |
| 74 |
} |
| 75 |
if XNN_UNLIKELY(batch != 0) { |
| 76 |
do { |
| 77 |
const int32_t va = *input_a++; |
| 78 |
const int32_t vacc = vbias + va * va_multiplier; |
| 79 |
|
| 80 |
int32_t vout = math_asr_s32(vacc, vshift); |
| 81 |
vout = vout + voutput_zero_point; |
| 82 |
vout = math_max_s32(vout, voutput_min); |
| 83 |
vout = math_min_s32(vout, voutput_max); |
| 84 |
*output++ = (uint8_t) vout; |
| 85 |
|
| 86 |
batch -= sizeof(uint8_t); |
| 87 |
} while (batch != 0); |
| 88 |
} |
| 89 |
} |