| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/qs8-vmulc/rvv.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2023 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 |
#include <riscv_vector.h> |
| 12 |
#include "xnnpack/vbinary.h" |
| 13 |
|
| 14 |
|
| 15 |
void xnn_qs8_vmulc_minmax_fp32_ukernel__rvv_u2v( |
| 16 |
size_t batch, |
| 17 |
const int8_t* input_a, |
| 18 |
const int8_t* input_b, |
| 19 |
int8_t* output, |
| 20 |
const union xnn_qs8_mul_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 21 |
{ |
| 22 |
assert(batch != 0); |
| 23 |
assert(batch % sizeof(int8_t) == 0); |
| 24 |
assert(input_a != NULL); |
| 25 |
assert(input_b != NULL); |
| 26 |
assert(output != NULL); |
| 27 |
|
| 28 |
const int32_t a_zero_point = params->scalar.a_zero_point; |
| 29 |
const float scale = params->scalar.scale; |
| 30 |
const float output_min_less_zero_point = (int32_t) params->scalar.output_min - (int32_t) params->scalar.output_zero_point; |
| 31 |
const float output_max_less_zero_point = (int32_t) params->scalar.output_max - (int32_t) params->scalar.output_zero_point; |
| 32 |
const float magic_bias = 12582912.0f; |
| 33 |
const int32_t magic_bias_less_output_zero_point = INT32_C(0x4B400000) - (int32_t) params->scalar.output_zero_point; |
| 34 |
|
| 35 |
const int32_t vb = (int32_t) *input_b - params->scalar.b_zero_point; |
| 36 |
do { |
| 37 |
const size_t n = __riscv_vsetvl_e8m2(batch); |
| 38 |
|
| 39 |
vint8m2_t in_a_i8v = __riscv_vle8_v_i8m2(input_a, n); input_a += n; |
| 40 |
vint16m4_t a_i16v = __riscv_vwsub_vx_i16m4(in_a_i8v, a_zero_point, n); |
| 41 |
|
| 42 |
vint32m8_t acc_i32v = __riscv_vwmul_vx_i32m8(a_i16v, vb, n); |
| 43 |
vfloat32m8_t acc_f32v = __riscv_vfcvt_f_x_v_f32m8(acc_i32v, n); |
| 44 |
acc_f32v = __riscv_vfmul_vf_f32m8(acc_f32v, scale, n); |
| 45 |
acc_f32v = __riscv_vfmin_vf_f32m8(__riscv_vfmax_vf_f32m8(acc_f32v, output_min_less_zero_point, n), output_max_less_zero_point, n); |
| 46 |
acc_f32v = __riscv_vfadd_vf_f32m8(acc_f32v, magic_bias, n); |
| 47 |
|
| 48 |
vint32m8_t out_i32v = __riscv_vfcvt_x_f_v_i32m8(acc_f32v, n); |
| 49 |
out_i32v = __riscv_vsub_vx_i32m8(out_i32v, magic_bias_less_output_zero_point, n); |
| 50 |
vint16m4_t out_i16v = __riscv_vncvt_x_x_w_i16m4(out_i32v, n); |
| 51 |
vint8m2_t out_i8v = __riscv_vncvt_x_x_w_i8m2(out_i16v, n); |
| 52 |
__riscv_vse8_v_i8m2(output, out_i8v, n); output += n; |
| 53 |
|
| 54 |
batch -= n; |
| 55 |
} while (batch != 0); |
| 56 |
} |