Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/backend/cpu/riscv/rvv/MNNFloat2Int8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by MNN on 2026/04/01.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include <algorithm>
#include <riscv_vector.h>
#include <stdint.h>
#include <sys/types.h>
Expand Down Expand Up @@ -68,10 +69,10 @@ void MNNFloat2Int8_RVV(const float* src, int8_t* dst, size_t sizeQuad, const flo
vfloat32m2_t v_min = __riscv_vfmv_v_f_f32m2(minf, vl_template);
vfloat32m2_t v_max = __riscv_vfmv_v_f_f32m2(maxf, vl_template);

// main loop
// Cap AVL at VLMAX so every non-final chunk preserves the C4 template phase.
size_t i = 0;
while (i < total) {
size_t vl = __riscv_vsetvl_e32m2(total - i);
size_t vl = __riscv_vsetvl_e32m2(std::min(total - i, vl_template));

vfloat32m2_t v_src = __riscv_vle32_v_f32m2(src + i, vl);

Expand Down
5 changes: 3 additions & 2 deletions source/backend/cpu/riscv/rvv/MNNInt8ScaleToFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2018, Alibaba Group Holding Limited
//

#include <algorithm>
#include <riscv_vector.h>
#include <stdint.h>
#include <sys/types.h>
Expand Down Expand Up @@ -49,9 +50,9 @@ void MNNInt8ScaleToFloat_RVV(float* dst, const int8_t* src, const float* scale,
vfloat32m4_t v_scale_tpl = __riscv_vloxei32_v_f32m4(scale4, v_byte_off, vl_max);
vfloat32m4_t v_zero_tpl = __riscv_vloxei32_v_f32m4(zero4, v_byte_off, vl_max);

// Main loop: vl <= vl_max, so the first `vl` elements of the template are always aligned
// Cap AVL at VLMAX so every non-final chunk preserves the C4 template phase.
while (i < total_elems) {
size_t vl = __riscv_vsetvl_e32m4(total_elems - i);
size_t vl = __riscv_vsetvl_e32m4(std::min(total_elems - i, vl_max));

vint8m1_t v_src_i8 = __riscv_vle8_v_i8m1(src + i, vl);
vint32m4_t v_src_i32 = __riscv_vsext_vf4_i32m4(v_src_i8, vl);
Expand Down
Loading