Improve the performance of RISC-V vector unit-stride/whole register ld/st instructions
v4 cover Improve the performance of RISC-V vector unit-stride/whole register ld/st instructions
Hi,
Sorry for the quick update the version, this version fixes the cross-page probe checking bug that I forgot to apply to the v3 version.
This RFC patch set tries to fix the issue of
https://gitlab.com/qemu-project/qemu/-/issues/2137.
In this RFC, we added patches that
1. Provide a fast path to direct access the host ram for some vector load/store instructions (e.g. unmasked vector unit-stride load/store instructions) and perform virtual address resolution once for the entire vector at beginning of helper function. (Thanks for Richard Henderson's suggestion)
2. Replace the group elements load/store TCG ops by the group element load/store flow in helper functions with some assumption (e.g. no masking, continuous memory load/store, the endian of host and guest architecture are the same). (Thanks for Richard Henderson's suggestion)
3. Try inline the vector load/store related functions that corresponding most of the execution time.
This version can improve the performance of the test case provided in
https://gitlab.com/qemu-project/qemu/-/issues/2137#note_1757501369
- QEMU user mode (vlen=512): from ~51.8 sec. to ~4.5 sec.
- QEMU system mode (vlen=512): from ~125.6 sec to ~6.6 sec.
This RFC is tested with SPEC CPU2006 with test input. We will try to measure the performance on SPEC CPU2006 benchmarks.
Series based on riscv-to-apply.next branch (commit d82f37f).
Changes from v3:
- patch 2
- Modify vext_cont_ldst_pages for corss-page checking
- patch 3
- Modify vext_ldst_whole for vext_cont_ldst_pages
Previous version:
- v1: https://lore.kernel.org/all/[email protected]/
- v2: https://lore.kernel.org/all/[email protected]/
- v3: https://lore.kernel.org/all/[email protected]/
Max Chou (5):
accel/tcg: Avoid unnecessary call overhead from
qemu_plugin_vcpu_mem_cb
target/riscv: rvv: Provide a fast path using direct access to host ram
for unmasked unit-stride load/store
target/riscv: rvv: Provide a fast path using direct access to host ram
for unit-stride whole register load/store
target/riscv: rvv: Provide group continuous ld/st flow for unit-stride
ld/st instructions
target/riscv: Inline unit-stride ld/st and corresponding functions for
performance
accel/tcg/ldst_common.c.inc | 8 +- target/riscv/insn_trans/trans_rvv.c.inc | 3 + target/riscv/vector_helper.c | 854 +++++++++++++++++++----- target/riscv/vector_internals.h | 48 ++ 4 files changed, 745 insertions(+), 168 deletions(-)
Signature · 1 line
2.34.1
RFC PATCH v4 1/5 accel/tcg: Avoid unnecessary call overhead from qemu_plugin_vcpu_mem_cb
If there are not any QEMU plugin memory callback functions, checking before calling the qemu_plugin_vcpu_mem_cb function can reduce the function call overhead.
--- accel/tcg/ldst_common.c.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
accel/tcg/ldst_common.c.inc +6 -2
@@ -125,7 +125,9 @@ void helper_st_i128(CPUArchState *env, uint64_t addr, Int128 val, MemOpIdx oi) static void plugin_load_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); + if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); + } } uint8_t cpu_ldb_mmu(CPUArchState *env, abi_ptr addr, MemOpIdx oi, uintptr_t ra)
@@ -188,7 +190,9 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, static void plugin_store_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); + if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); + } } void cpu_stb_mmu(CPUArchState *env, abi_ptr addr, uint8_t val,
Signature · 1 line
2.34.1
Re: [RFC PATCH v4 1/5] accel/tcg: Avoid unnecessary call overhead from qemu_plugin_vcpu_mem_cb
Quoted 8 lines · Max Chou
If there are not any QEMU plugin memory callback functions, checking before calling the
qemu_plugin_vcpu_mem_cbfunction can reduce the function call overhead.Signed-off-by Max Chou<[email protected]>--- accel/tcg/ldst_common.c.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
r~
Re: [RFC PATCH v4 1/5] accel/tcg: Avoid unnecessary call overhead from qemu_plugin_vcpu_mem_cb
In reply to Max ChouMax Chou <[email protected]> 於 2024年6月14日 週五 上午1:52寫道:
Quoted 40 lines
If there are not any QEMU plugin memory callback functions, checking before calling the
qemu_plugin_vcpu_mem_cbfunction can reduce the function call overhead.Signed-off-by Max Chou <[email protected]>--- accel/tcg/ldst_common.c.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)accel/tcg/ldst_common.c.inc +6
-3@@ -125,7 +125,9 @@ void helper_st_i128(CPUArchState *env, uint64_t addr, Int128 val, MemOpIdx oi) static void plugin_load_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); + if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_R); + } } uint8_t cpu_ldb_mmu(CPUArchState *env, abi_ptr addr, MemOpIdx oi, uintptr_t ra)@@ -188,7 +190,9 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, static void plugin_store_cb(CPUArchState *env, abi_ptr addr, MemOpIdx oi) { - qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); + if (cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + qemu_plugin_vcpu_mem_cb(env_cpu(env), addr, oi, QEMU_PLUGIN_MEM_W); + } } void cpu_stb_mmu(CPUArchState *env, abi_ptr addr, uint8_t val, --2.34.1
Alex Bennée
AppliedRe: [RFC PATCH v4 1/5] accel/tcg: Avoid unnecessary call overhead from qemu_plugin_vcpu_mem_cb
In reply to Max ChouQuoted 5 lines · Max Chou
If there are not any QEMU plugin memory callback functions, checking before calling the
qemu_plugin_vcpu_mem_cbfunction can reduce the function call overhead.Signed-off-by Max Chou <[email protected]>
Queued this patch to maintainer/june-2024-omnibus, thanks.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
RFC PATCH v4 2/5 target/riscv: rvv: Provide a fast path using direct access to host ram for unmasked unit-stride load/store
In reply to Max ChouThis commit references the sve_ldN_r/sve_stN_r helper functions in ARM target to optimize the vector unmasked unit-stride load/store instructions by following items:
* Get the loose bound of activate elements
* Probing pages/resolving host memory address/handling watchpoint at beginning
* Provide new interface to direct access host memory
The original element load/store interface is replaced by the new element load/store functions with _tlb & _host postfix that means doing the element load/store through the original softmmu flow and the direct access host memory flow.
--- target/riscv/insn_trans/trans_rvv.c.inc | 3 + target/riscv/vector_helper.c | 637 +++++++++++++++++++----- target/riscv/vector_internals.h | 48 ++ 3 files changed, 551 insertions(+), 137 deletions(-)
target/riscv/insn_trans/trans_rvv.c.inc +3 -0
@@ -770,6 +770,7 @@ static bool ld_us_mask_op(DisasContext *s, arg_vlm_v *a, uint8_t eew) /* Mask destination register are always tail-agnostic */ data = FIELD_DP32(data, VDATA, VTA, s->cfg_vta_all_1s); data = FIELD_DP32(data, VDATA, VMA, s->vma); + data = FIELD_DP32(data, VDATA, VM, 1); return ldst_us_trans(a->rd, a->rs1, data, fn, s, false); }
@@ -787,6 +788,7 @@ static bool st_us_mask_op(DisasContext *s, arg_vsm_v *a, uint8_t eew) /* EMUL = 1, NFIELDS = 1 */ data = FIELD_DP32(data, VDATA, LMUL, 0); data = FIELD_DP32(data, VDATA, NF, 1); + data = FIELD_DP32(data, VDATA, VM, 1); return ldst_us_trans(a->rd, a->rs1, data, fn, s, true); }
@@ -1106,6 +1108,7 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, TCGv_i32 desc; uint32_t data = FIELD_DP32(0, VDATA, NF, nf); + data = FIELD_DP32(data, VDATA, VM, 1); dest = tcg_temp_new_ptr(); desc = tcg_constant_i32(simd_desc(s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, data));
target/riscv/vector_helper.c +500 -137
805 lines not on this page · raw message
target/riscv/vector_internals.h +48 -0
52 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [RFC PATCH v4 2/5] target/riscv: rvv: Provide a fast path using direct access to host ram for unmasked unit-stride load/store
Quoted 41 lines · Max Chou
This commit references the sve_ldN_r/sve_stN_r helper functions in ARM target to optimize the vector unmasked unit-stride load/store instructions by following items:
* Get the loose bound of activate elements
* Probing pages/resolving host memory address/handling watchpoint at beginning
* Provide new interface to direct access host memoryThe original element load/store interface is replaced by the new element load/store functions with
_tlb&_hostpostfix that means doing the element load/store through the original softmmu flow and the direct access host memory flow.Signed-off-by Max Chou <[email protected]>--- target/riscv/insn_trans/trans_rvv.c.inc | 3 + target/riscv/vector_helper.c | 637 +++++++++++++++++++----- target/riscv/vector_internals.h | 48 ++ 3 files changed, 551 insertions(+), 137 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +2
-0@@ -770,6 +770,7 @@ static bool ld_us_mask_op(DisasContext *s, arg_vlm_v *a, uint8_t eew) /* Mask destination register are always tail-agnostic */ data = FIELD_DP32(data, VDATA, VTA, s->cfg_vta_all_1s); data = FIELD_DP32(data, VDATA, VMA, s->vma); + data = FIELD_DP32(data, VDATA, VM, 1); return ldst_us_trans(a->rd, a->rs1, data, fn, s, false); }@@ -787,6 +788,7 @@ static bool st_us_mask_op(DisasContext *s, arg_vsm_v *a, uint8_t eew) /* EMUL = 1, NFIELDS = 1 */ data = FIELD_DP32(data, VDATA, LMUL, 0); data = FIELD_DP32(data, VDATA, NF, 1); + data = FIELD_DP32(data, VDATA, VM, 1); return ldst_us_trans(a->rd, a->rs1, data, fn, s, true); }
target/riscv/insn_trans/trans_rvv.c.inc static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, · line 1114
Quoted 7 lines
target/riscv/insn_trans/trans_rvv.c.inc +1
-0@@ -1106,6 +1108,7 @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, TCGv_i32 desc; uint32_t data = FIELD_DP32(0, VDATA, NF, nf); + data = FIELD_DP32(data, VDATA, VM, 1); dest = tcg_temp_new_ptr(); desc = tcg_constant_i32(simd_desc(s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, data));
This is ok, and would warrant a separate patch.
target/riscv/insn_trans/trans_rvv.c.inc
Quoted 9 lines
target/riscv/insn_trans/trans_rvv.c.inc +9
-0+ if (vm == 0) { + for (i = vstart; i < evl; ++i) { + if (vext_elem_mask(v0, i)) { + reg_idx_last = i; + if (reg_idx_first < 0) { + reg_idx_first = i; + } + } + }
This isn't great, and isn't used for now, since only unmasked unit-stride is handled so far. I think this first patch should be simpler and *assume* VM is set.
target/riscv/insn_trans/trans_rvv.c.inc
Quoted 13 lines
target/riscv/insn_trans/trans_rvv.c.inc +13
-0+/* + * Resolve the guest virtual addresses to info->page[]. + * Control the generation of page faults with @fault. Return false if + * there is no work to do, which can only happen with @fault == FAULT_NO. + */ +static bool vext_cont_ldst_pages(CPURISCVState *env, RVVContLdSt *info, + target_ulong addr, bool is_load, + uint32_t desc, uint32_t esz, uintptr_t ra, + bool is_us_whole) +{ + uint32_t vm = vext_vm(desc); + uint32_t nf = vext_nf(desc); + bool nofault = (vm == 1 ? false : true);
Why is nofault == "!vm"?
Also, it's silly to use ?: with true/false -- use the proper boolean expression in the first place.
That said... faults with RVV must interact with vstart.
I'm not sure what the best code organization is.
Perhaps a subroutine, passed the first and last elements for a single page.
Update vstart, resolve the page, allowing the exception.
If watchpoints, one call to cpu_check_watchpoint for the entire memory range. If ram, iterate through the rest of the page using host accesses; otherwise, iterate through the rest of the page using tlb accesses, making sure vstart is always up-to-date.
The main routine looks for the page_split, invokes the subroutine for the first (and likely only) page. Special case any split-page element. Invoke the subroutine for the second page.
r~
Re: [RFC PATCH v4 2/5] target/riscv: rvv: Provide a fast path using direct access to host ram for unmasked unit-stride load/store
Quoted 41 lines · Richard Henderson
Quoted 40 lines · Max Chou
This commit references the sve_ldN_r/sve_stN_r helper functions in ARM target to optimize the vector unmasked unit-stride load/store instructions by following items:
* Get the loose bound of activate elements
* Probing pages/resolving host memory address/handling watchpoint at beginning
* Provide new interface to direct access host memoryThe original element load/store interface is replaced by the new element load/store functions with
_tlb&_hostpostfix that means doing the element load/store through the original softmmu flow and the direct access host memory flow.Signed-off-by Max Chou <[email protected]>---
target/riscv/insn_trans/trans_rvv.c.inc | 3 + target/riscv/vector_helper.c | 637 +++++++++++++++++++----- target/riscv/vector_internals.h | 48 ++3 files changed, 551 insertions(+), 137 deletions(-)target/riscv/insn_trans/trans_rvv.c.inc +1
-0@@ -770,6 +770,7 @@ static bool ld_us_mask_op(DisasContext *s, arg_vlm_v *a, uint8_t eew) /* Mask destination register are always tail-agnostic */ data = FIELD_DP32(data, VDATA, VTA, s->cfg_vta_all_1s); data = FIELD_DP32(data, VDATA, VMA, s->vma); + data = FIELD_DP32(data, VDATA, VM, 1); return ldst_us_trans(a->rd, a->rs1, data, fn, s, false); }@@ -787,6 +788,7 @@ static bool
st_us_mask_op(DisasContext *s, arg_vsm_v *a, uint8_t eew)/* EMUL = 1, NFIELDS = 1 */
data =FIELD_DP32(data, VDATA, LMUL, 0);
data =FIELD_DP32(data, VDATA, NF, 1);
+ data =FIELD_DP32(data, VDATA, VM, 1);
returnldst_us_trans(a->rd, a->rs1, data, fn, s, true);
}
@@ -1106,6 +1108,7 @@ static bool ldst_whole_trans(uint32_t vd,uint32_trs1,uint32_tnf,
Quoted 8 lines
Quoted 6 lines
TCGv_i32desc;
uint32_tdata =FIELD_DP32(0, VDATA, NF, nf);
+ data =FIELD_DP32(data, VDATA, VM, 1);
dest =tcg_temp_new_ptr();
desc =tcg_constant_i32(simd_desc(s->cfg_ptr->vlenb, s->cfg_ptr->vlenb, data));This is ok, and would warrant a separate patch.
Ok, I'll split this part to a separate patch at next version. Thanks.
Quoted 12 lines
Quoted 11 lines
+ if (vm == 0) {
+ for (i = vstart; i < evl; ++i) {
+ if (vext_elem_mask(v0, i)) {
+reg_idx_last= i;
+ if (reg_idx_first< 0) {
+reg_idx_first= i;
+ }
+ }
+ }
Quoted 1 line
This isn't great, and isn't used for now, since only unmasked unit-stride is handled so far. I think this first patch should be simpler and *assume* VM is set.
Indeed. I'll remove this part at next version.
I agree that this first patch should be simpler and assume VM is set. Thank you for the suggestion.
Quoted 33 lines
Quoted 16 lines
+/*
+ * Resolve the guest virtual addresses to info->page[].
+ * Control the generation of page faults with @fault. Return false if
+ * there is no work to do, which can only happen with @fault ==FAULT_NO.
+ */
+static bool vext_cont_ldst_pages(CPURISCVState *env, RVVContLdSt *info, +target_ulongaddr, boolis_load, +uint32_tdesc,uint32_tesz,uintptr_tra,
+ boolis_us_whole)
+{
+uint32_tvm =vext_vm(desc);
+uint32_tnf =vext_nf(desc);
+ bool nofault = (vm == 1 ? false : true);Why is nofault == "!vm"?
Also, it's silly to use ?: with true/false -- use the proper boolean expression in the first place.
That said... faults with RVV must interact with vstart.
I'm not sure what the best code organization is.
Perhaps a subroutine, passed the first and last elements for a single page.
Update vstart, resolve the page, allowing the exception.
If watchpoints, one call tocpu_check_watchpointfor the entire memory range. If ram, iterate through the rest of the page using host accesses; otherwise, iterate through the rest of the page using tlb accesses, making sure vstart is always up-to-date.
Quoted 4 lines
The main routine looks for the
page_split, invokes the subroutine for the first (and likely only) page. Special case any split-page element. Invoke the subroutine for the second page.r~
According to the v spec, the vector unit-stride and constant-stride memory accesses do not guarantee ordering between individual element accesses. So it may affects how we handle the precise vector traps here.
I'll replace the nofault part and try to update the subroutine flow with the suggestion and think about how to update vstart here. Thanks you for the suggestions.
Re: [RFC PATCH v4 2/5] target/riscv: rvv: Provide a fast path using direct access to host ram for unmasked unit-stride load/store
In reply to Max ChouQuoted 5 lines · Max Chou
target/riscv/vector_helper.c +5
-0+#define GEN_VEXT_LD_ELEM (NAME ,ETYPE ,H ,LDSUF ) \ +static void NAME##_tlb(CPURISCVState *env, abi_ptr addr, \ + uint32_t byte_off, void *vd, uintptr_t retaddr) \ +{ \ + uint8_t *reg = ((uint8_t *)vd + byte_off); \
target/riscv/vector_helper.c static inline void vext_set_elem_mask(void *v0, int index, · line 432
Quoted 10 lines
target/riscv/vector_helper.c +10
-0+ETYPE *cur = ((ETYPE *)reg); \ + *cur = cpu_##LDSUF##_data_ra(env, addr, retaddr); \ +} \ + \ +static void NAME##_host(void *vd, uint32_t byte_off, void *host) \ +{ \ + ETYPE val = LDSUF##_p(host); \ + uint8_t *reg = (uint8_t *)(vd + byte_off); \ + *(ETYPE *)(reg) = val; \ +}
Why are you casting to and from uint8_t* ?
Surely this is cleaner as
ETYPE *cur = vd + byte_off;
r~
RFC PATCH v4 3/5 target/riscv: rvv: Provide a fast path using direct access to host ram for unit-stride whole register load/store
In reply to Max ChouThe vector unit-stride whole register load/store instructions are similar to unmasked unit-stride load/store instructions that is suitable to be optimized by using a direct access to host ram fast path.
--- target/riscv/vector_helper.c | 185 +++++++++++++++++++++++++---------- 1 file changed, 133 insertions(+), 52 deletions(-)
target/riscv/vector_helper.c +133 -52
@@ -935,81 +935,162 @@ GEN_VEXT_LDFF(vle64ff_v, int64_t, lde_d_tlb)*/ static void vext_ldst_whole (void *vd,target_ulong base,CPURISCVState *env,uint32_t desc, -vext_ldst_elem_fn_tlb *ldst_elem,uint32_t log2_esz, -uintptr_t ra) +vext_ldst_elem_fn_tlb *ldst_tlb, +vext_ldst_elem_fn_host *ldst_host,uint32_t log2_esz, +uintptr_t ra,bool is_load) { -uint32_t i, k, off, pos; +RVVContLdSt info; +target_ulong addr; +void *host; +int flags; +intptr_t reg_start, reg_last; +uint32_t idx_nf, off, evl;uint32_t nf =vext_nf (desc);uint32_t vlenb =riscv_cpu_cfg (env)->vlenb;uint32_t max_elems = vlenb >> log2_esz; +uint32_t esz =1 << log2_esz;if (env->vstart >= ((vlenb * nf) >> log2_esz)) { env->vstart =0 ;return ; } - k = env->vstart / max_elems; - off = env->vstart % max_elems; +vext_cont_ldst_elements (&info, base, env->vreg, env->vstart, + nf * max_elems, desc, log2_esz, true); +vext_cont_ldst_pages (env, &info, base, is_load, desc, esz, ra, true); +vext_cont_ldst_watchpoints (env, &info, env->vreg, base, esz, is_load, ra, + desc); + + flags = info.page[0 ].flags | info.page[1 ].flags; +if (unlikely (flags !=0 )) { +/* At least one page includes MMIO. */ + reg_start = info.reg_idx_first[0 ]; + idx_nf = reg_start / max_elems; + off = reg_start % max_elems; + evl = (idx_nf +1 ) * max_elems; + +if (off) { +/* +* load/store rest of elements of current segment pointed by vstart +*/ + addr = base + (reg_start << log2_esz); +for (; reg_start < evl; reg_start++, addr += esz) { +ldst_tlb (env,adjust_addr (env, addr), reg_start << log2_esz, + vd, ra); + } + idx_nf++; + } + +/* load/store elements for rest of segments */ + evl = nf * max_elems; + addr = base + (reg_start << log2_esz); +for (; reg_start < evl; reg_start++, addr += esz) { +ldst_tlb (env,adjust_addr (env, addr), reg_start << log2_esz, vd, + ra); + } + + env->vstart =0 ; +return ; + } + +/* The entire operation is in RAM, on valid pages. */ + reg_start = info.reg_idx_first[0 ]; + reg_last = info.reg_idx_last[0 ] +1 ; + host = info.page[0 ].host; + idx_nf = reg_start / max_elems; + off = reg_start % max_elems; + evl = (idx_nf +1 ) * max_elems;if (off) {/* load/store rest of elements of current segment pointed by vstart */ -for (pos = off; pos < max_elems; pos++, env->vstart++) { -target_ulong addr = base + ((pos + k * max_elems) << log2_esz); -ldst_elem (env,adjust_addr (env, addr), - (pos + k * max_elems) << log2_esz, vd, ra); +for (; reg_start < evl; reg_start++) { +ldst_host (vd, reg_start << log2_esz, + host + (reg_start << log2_esz)); } - k++; + idx_nf++; }/* load/store elements for rest of segments */ -for (; k < nf; k++) { -for (i =0 ; i < max_elems; i++, env->vstart++) { -target_ulong addr = base + ((i + k * max_elems) << log2_esz); -ldst_elem (env,adjust_addr (env, addr), - (i + k * max_elems) << log2_esz, vd, ra); +for (; reg_start < reg_last; reg_start++) { +ldst_host (vd, reg_start << log2_esz, host + (reg_start << log2_esz)); + } + +/* +* Use the slow path to manage the cross-page misalignment. +* But we know this is RAM and cannot trap. +*/ +if (unlikely (info.mem_off_split >=0 )) { + reg_start = info.reg_idx_split; + addr = base + (reg_start << log2_esz); +ldst_tlb (env,adjust_addr (env, addr), reg_start << log2_esz, vd, ra); + } + +if (unlikely (info.mem_off_first[1 ] >=0 )) { + reg_start = info.reg_idx_first[1 ]; + reg_last = info.reg_idx_last[1 ] +1 ; + host = info.page[1 ].host; + idx_nf = reg_start / max_elems; + off = reg_start % max_elems; + evl = (idx_nf +1 ) * max_elems; + +if (off) { +/* +* load/store rest of elements of current segment pointed by vstart +*/ +for (; reg_start < evl; reg_start++) { +ldst_host (vd, reg_start << log2_esz, + host + (reg_start << log2_esz)); + } + idx_nf++; + } + +/* load/store elements for rest of segments */ +for (; reg_start < reg_last; reg_start++) { +ldst_host (vd, reg_start << log2_esz, + host + (reg_start << log2_esz)); } } env->vstart =0 ; } -#define GEN_VEXT_LD_WHOLE (NAME ,ETYPE ,LOAD_FN ) \ -void HELPER(NAME)(void *vd, target_ulong base, \ - CPURISCVState *env, uint32_t desc) \ -{ \ - vext_ldst_whole(vd, base, env, desc, LOAD_FN, \ - ctzl(sizeof(ETYPE)), GETPC()); \ -} - -GEN_VEXT_LD_WHOLE(vl1re8_v, int8_t, lde_b_tlb) -GEN_VEXT_LD_WHOLE(vl1re16_v, int16_t, lde_h_tlb) -GEN_VEXT_LD_WHOLE(vl1re32_v, int32_t, lde_w_tlb) -GEN_VEXT_LD_WHOLE(vl1re64_v, int64_t, lde_d_tlb) -GEN_VEXT_LD_WHOLE(vl2re8_v, int8_t, lde_b_tlb) -GEN_VEXT_LD_WHOLE(vl2re16_v, int16_t, lde_h_tlb) -GEN_VEXT_LD_WHOLE(vl2re32_v, int32_t, lde_w_tlb) -GEN_VEXT_LD_WHOLE(vl2re64_v, int64_t, lde_d_tlb) -GEN_VEXT_LD_WHOLE(vl4re8_v, int8_t, lde_b_tlb) -GEN_VEXT_LD_WHOLE(vl4re16_v, int16_t, lde_h_tlb) -GEN_VEXT_LD_WHOLE(vl4re32_v, int32_t, lde_w_tlb) -GEN_VEXT_LD_WHOLE(vl4re64_v, int64_t, lde_d_tlb) -GEN_VEXT_LD_WHOLE(vl8re8_v, int8_t, lde_b_tlb) -GEN_VEXT_LD_WHOLE(vl8re16_v, int16_t, lde_h_tlb) -GEN_VEXT_LD_WHOLE(vl8re32_v, int32_t, lde_w_tlb) -GEN_VEXT_LD_WHOLE(vl8re64_v, int64_t, lde_d_tlb) - -#define GEN_VEXT_ST_WHOLE (NAME ,ETYPE ,STORE_FN ) \ -void HELPER(NAME)(void *vd, target_ulong base, \ - CPURISCVState *env, uint32_t desc) \ -{ \ - vext_ldst_whole(vd, base, env, desc, STORE_FN, \ - ctzl(sizeof(ETYPE)), GETPC()); \ -} - -GEN_VEXT_ST_WHOLE(vs1r_v, int8_t, ste_b_tlb) -GEN_VEXT_ST_WHOLE(vs2r_v, int8_t, ste_b_tlb) -GEN_VEXT_ST_WHOLE(vs4r_v, int8_t, ste_b_tlb) -GEN_VEXT_ST_WHOLE (vs8r_v, int8_t, ste_b_tlb) +#define GEN_VEXT_LD_WHOLE (NAME ,ETYPE ,LOAD_FN_TLB ,LOAD_FN_HOST ) \ +void HELPER(NAME)(void *vd, target_ulong base, CPURISCVState *env, \ + uint32_t desc) \ +{ \ + vext_ldst_whole(vd, base, env, desc, LOAD_FN_TLB, LOAD_FN_HOST, \ + ctzl(sizeof(ETYPE)), GETPC(), true); \ +} + +GEN_VEXT_LD_WHOLE(vl1re8_v, int8_t, lde_b_tlb, lde_b_host) +GEN_VEXT_LD_WHOLE(vl1re16_v, int16_t, lde_h_tlb, lde_h_host) +GEN_VEXT_LD_WHOLE(vl1re32_v, int32_t, lde_w_tlb, lde_w_host) +GEN_VEXT_LD_WHOLE(vl1re64_v, int64_t, lde_d_tlb, lde_d_host) +GEN_VEXT_LD_WHOLE(vl2re8_v, int8_t, lde_b_tlb, lde_b_host) +GEN_VEXT_LD_WHOLE(vl2re16_v, int16_t, lde_h_tlb, lde_h_host) +GEN_VEXT_LD_WHOLE(vl2re32_v, int32_t, lde_w_tlb, lde_w_host) +GEN_VEXT_LD_WHOLE(vl2re64_v, int64_t, lde_d_tlb, lde_d_host) +GEN_VEXT_LD_WHOLE(vl4re8_v, int8_t, lde_b_tlb, lde_b_host) +GEN_VEXT_LD_WHOLE(vl4re16_v, int16_t, lde_h_tlb, lde_h_host) +GEN_VEXT_LD_WHOLE(vl4re32_v, int32_t, lde_w_tlb, lde_w_host) +GEN_VEXT_LD_WHOLE(vl4re64_v, int64_t, lde_d_tlb, lde_d_host) +GEN_VEXT_LD_WHOLE(vl8re8_v, int8_t, lde_b_tlb, lde_b_host) +GEN_VEXT_LD_WHOLE(vl8re16_v, int16_t, lde_h_tlb, lde_h_host) +GEN_VEXT_LD_WHOLE(vl8re32_v, int32_t, lde_w_tlb, lde_w_host) +GEN_VEXT_LD_WHOLE(vl8re64_v, int64_t, lde_d_tlb, lde_d_host) + +#define GEN_VEXT_ST_WHOLE (NAME ,ETYPE ,STORE_FN_TLB ,STORE_FN_HOST ) \ +void HELPER(NAME)(void *vd, target_ulong base, CPURISCVState *env, \ + uint32_t desc) \ +{ \ + vext_ldst_whole(vd, base, env, desc, STORE_FN_TLB, STORE_FN_HOST, \ + ctzl(sizeof(ETYPE)), GETPC(), false); \ +} + +GEN_VEXT_ST_WHOLE(vs1r_v, int8_t, ste_b_tlb, ste_b_host) +GEN_VEXT_ST_WHOLE(vs2r_v, int8_t, ste_b_tlb, ste_b_host) +GEN_VEXT_ST_WHOLE(vs4r_v, int8_t, ste_b_tlb, ste_b_host) +GEN_VEXT_ST_WHOLE (vs8r_v, int8_t, ste_b_tlb, ste_b_host)/* * Vector Integer Arithmetic Instructions
Signature · 1 line
2.34.1
RFC PATCH v4 4/5 target/riscv: rvv: Provide group continuous ld/st flow for unit-stride ld/st instructions
In reply to Max ChouThe vector unmasked unit-stride and whole register load/store instructions will load/store continuous memory. If the endian of both the host and guest architecture are the same, then we can group the element load/store to load/store more data at a time.
--- target/riscv/vector_helper.c | 160 +++++++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 43 deletions(-)
target/riscv/vector_helper.c +117 -43
@@ -457,6 +457,69 @@ GEN_VEXT_ST_ELEM(ste_h, uint16_t, H2, stw) GEN_VEXT_ST_ELEM(ste_w, uint32_t, H4, stl) GEN_VEXT_ST_ELEM(ste_d, uint64_t, H8, stq) +static inline uint32_t +vext_group_ldst_host (CPURISCVState *env,void *vd,uint32_t byte_end, +uint32_t byte_offset,void *host,uint32_t esz, +bool is_load) +{ +uint32_t group_size; +static vext_ldst_elem_fn_host *const fns[2 ][4 ] = { +/* Store */ + { ste_b_host, ste_h_host, ste_w_host, ste_d_host }, +/* Load */ + { lde_b_host, lde_h_host, lde_w_host, lde_d_host } + }; +vext_ldst_elem_fn_host *fn; + +if (byte_offset +8 < byte_end) { + group_size =MO_64 ; + }else if (byte_offset +4 < byte_end) { + group_size =MO_32 ; + }else if (byte_offset +2 < byte_end) { + group_size =MO_16 ; + }else { + group_size =MO_8 ; + } + + fn = fns[is_load][group_size]; +fn (vd, byte_offset, host + byte_offset); + +return 1 << group_size; +} + +static inline void +vext_continus_ldst_tlb (CPURISCVState *env,vext_ldst_elem_fn_tlb *ldst_tlb, +void *vd,uint32_t evl,target_ulong addr, +uint32_t reg_start,uintptr_t ra,uint32_t esz, +bool is_load) +{ +for (; reg_start < evl; reg_start++, addr += esz) { +ldst_tlb (env,adjust_addr (env, addr), reg_start * esz, vd, ra); + } +} + +static inline void +vext_continus_ldst_host (CPURISCVState *env,vext_ldst_elem_fn_host *ldst_host, +void *vd,uint32_t evl,uint32_t reg_start,void *host, +uint32_t esz,bool is_load) +{ +#if TARGET_BIG_ENDIAN !=HOST_BIG_ENDIAN +for (; reg_start < evl; reg_start++) { +uint32_t byte_off = reg_start * esz; +ldst_host (vd, byte_off, host + byte_off); + } +#else +uint32_t group_byte; +uint32_t byte_start = reg_start * esz; +uint32_t byte_end = evl * esz; +while (byte_start < byte_end) { + group_byte =vext_group_ldst_host (env, vd, byte_end, byte_start, host, + esz, is_load); + byte_start += group_byte; + } +#endif +} +static void vext_set_tail_elems_1s (target_ulong vl,void *vd,uint32_t desc,uint32_t nf,uint32_t esz,uint32_t max_elems)
@@ -555,6 +618,7 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, uint32_t evl, uintptr_t ra, bool is_load) { RVVContLdSt info; +target_ulong addr;void *host;int flags;intptr_t reg_start, reg_last;
@@ -587,13 +651,19 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, } reg_last +=1 ; -for (i = reg_start; i < reg_last; ++i) { - k =0 ; -while (k < nf) { -target_ulong addr = base + ((i * nf + k) << log2_esz); -ldst_tlb (env,adjust_addr (env, addr), - (i + k * max_elems) << log2_esz, vd, ra); - k++; +if (nf ==1 ) { + addr = base + reg_start * esz; +vext_continus_ldst_tlb (env, ldst_tlb, vd, reg_last, addr, + reg_start, ra, esz, is_load); + }else { +for (i = reg_start; i < reg_last; ++i) { + k =0 ; +while (k < nf) { + addr = base + ((i * nf + k) * esz); +ldst_tlb (env,adjust_addr (env, addr), + (i + k * max_elems) << log2_esz, vd, ra); + k++; + } } }
@@ -607,12 +677,17 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, reg_last = info.reg_idx_last[0 ] +1 ; host = info.page[0 ].host; -for (i = reg_start; i < reg_last; ++i) { - k =0 ; -while (k < nf) { -ldst_host (vd, (i + k * max_elems) << log2_esz, - host + ((i * nf + k) << log2_esz)); - k++; +if (nf ==1 ) { +vext_continus_ldst_host (env, ldst_host, vd, reg_last, reg_start, host, + esz, is_load); + }else { +for (i = reg_start; i < reg_last; ++i) { + k =0 ; +while (k < nf) { +ldst_host (vd, (i + k * max_elems) << log2_esz, + host + ((i * nf + k) * esz)); + k++; + } } }
@@ -624,7 +699,7 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, reg_start = info.reg_idx_split; k =0 ;while (k < nf) { -target_ulong addr = base + ((reg_start * nf + k) << log2_esz); + addr = base + ((reg_start * nf + k) << log2_esz);ldst_tlb (env,adjust_addr (env, addr), (reg_start + k * max_elems) << log2_esz, vd, ra); k++;
@@ -636,12 +711,17 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, reg_last = info.reg_idx_last[1 ] +1 ; host = info.page[1 ].host; -for (i = reg_start; i < reg_last; ++i) { - k =0 ; -while (k < nf) { -ldst_host (vd, (i + k * max_elems) << log2_esz, - host + ((i * nf + k) << log2_esz)); - k++; +if (nf ==1 ) { +vext_continus_ldst_host (env, ldst_host, vd, reg_last, reg_start, + host, esz, is_load); + }else { +for (i = reg_start; i < reg_last; ++i) { + k =0 ; +while (k < nf) { +ldst_host (vd, (i + k * max_elems) << log2_esz, + host + ((i * nf + k) << log2_esz)); + k++; + } } } }
@@ -974,20 +1054,17 @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,* load/store rest of elements of current segment pointed by vstart */ addr = base + (reg_start << log2_esz); -for (; reg_start < evl; reg_start++, addr += esz) { -ldst_tlb (env,adjust_addr (env, addr), reg_start << log2_esz, - vd, ra); - } +vext_continus_ldst_tlb (env, ldst_tlb, vd, evl, addr, reg_start, ra, + esz, is_load); idx_nf++; }/* load/store elements for rest of segments */ evl = nf * max_elems; addr = base + (reg_start << log2_esz); -for (; reg_start < evl; reg_start++, addr += esz) { -ldst_tlb (env,adjust_addr (env, addr), reg_start << log2_esz, vd, - ra); - } + reg_start = idx_nf * max_elems; +vext_continus_ldst_tlb (env, ldst_tlb, vd, evl, addr, reg_start, ra, + esz, is_load); env->vstart =0 ;return ;
@@ -1003,17 +1080,16 @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,if (off) {/* load/store rest of elements of current segment pointed by vstart */ -for (; reg_start < evl; reg_start++) { -ldst_host (vd, reg_start << log2_esz, - host + (reg_start << log2_esz)); - } +vext_continus_ldst_host (env, ldst_host, vd, evl, reg_start, host, esz, + is_load); idx_nf++; }/* load/store elements for rest of segments */ -for (; reg_start < reg_last; reg_start++) { -ldst_host (vd, reg_start << log2_esz, host + (reg_start << log2_esz)); - } + evl = reg_last; + reg_start = idx_nf * max_elems; +vext_continus_ldst_host (env, ldst_host, vd, evl, reg_start, host, esz, + is_load);/* * Use the slow path to manage the cross-page misalignment.
@@ -1037,18 +1113,16 @@ vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,/* * load/store rest of elements of current segment pointed by vstart */ -for (; reg_start < evl; reg_start++) { -ldst_host (vd, reg_start << log2_esz, - host + (reg_start << log2_esz)); - } +vext_continus_ldst_host (env, ldst_host, vd, evl, reg_start, host, + esz, is_load); idx_nf++; }/* load/store elements for rest of segments */ -for (; reg_start < reg_last; reg_start++) { -ldst_host (vd, reg_start << log2_esz, - host + (reg_start << log2_esz)); - } + evl = reg_last; + reg_start = idx_nf * max_elems; +vext_continus_ldst_host (env, ldst_host, vd, evl, reg_start, host, esz, + is_load); } env->vstart =0 ;
Signature · 1 line
2.34.1
Re: [RFC PATCH v4 4/5] target/riscv: rvv: Provide group continuous ld/st flow for unit-stride ld/st instructions
Quoted 34 lines · Max Chou
The vector unmasked unit-stride and whole register load/store instructions will load/store continuous memory. If the endian of both the host and guest architecture are the same, then we can group the element load/store to load/store more data at a time.
Signed-off-by Max Chou <[email protected]>--- target/riscv/vector_helper.c | 160 +++++++++++++++++++++++++---------- 1 file changed, 117 insertions(+), 43 deletions(-)target/riscv/vector_helper.c +16
-0@@ -457,6 +457,69 @@ GEN_VEXT_ST_ELEM(ste_h, uint16_t, H2, stw) GEN_VEXT_ST_ELEM(ste_w, uint32_t, H4, stl) GEN_VEXT_ST_ELEM(ste_d, uint64_t, H8, stq) +static inline uint32_t +vext_group_ldst_host (CPURISCVState *env,void *vd,uint32_t byte_end, +uint32_t byte_offset,void *host,uint32_t esz, +bool is_load) +{ +uint32_t group_size; +static vext_ldst_elem_fn_host *const fns[2 ][4 ] = { +/* Store */ + { ste_b_host, ste_h_host, ste_w_host, ste_d_host }, +/* Load */ + { lde_b_host, lde_h_host, lde_w_host, lde_d_host } + }; +vext_ldst_elem_fn_host *fn; + +if (byte_offset +8 < byte_end) { + group_size =MO_64 ;
target/riscv/vector_helper.c GEN_VEXT_ST_ELEM(ste_h, uint16_t, H2, stw) · line 485
Quoted 10 lines
target/riscv/vector_helper.c +10
-0+ }else if (byte_offset +4 < byte_end) { + group_size =MO_32 ; + }else if (byte_offset +2 < byte_end) { + group_size =MO_16 ; + }else { + group_size =MO_8 ; + } + + fn = fns[is_load][group_size]; +fn (vd, byte_offset, host + byte_offset);
This is a really bad idea. The table and indirect call means that none of these will be properly inlined. Anyway...
Quoted 24 lines
target/riscv/vector_helper.c +24
-0+ +return 1 << group_size; +} + +static inline void +vext_continus_ldst_tlb (CPURISCVState *env,vext_ldst_elem_fn_tlb *ldst_tlb, +void *vd,uint32_t evl,target_ulong addr, +uint32_t reg_start,uintptr_t ra,uint32_t esz, +bool is_load) +{ +for (; reg_start < evl; reg_start++, addr += esz) { +ldst_tlb (env,adjust_addr (env, addr), reg_start * esz, vd, ra); + } +} + +static inline void +vext_continus_ldst_host (CPURISCVState *env,vext_ldst_elem_fn_host *ldst_host, +void *vd,uint32_t evl,uint32_t reg_start,void *host, +uint32_t esz,bool is_load) +{ +#if TARGET_BIG_ENDIAN !=HOST_BIG_ENDIAN +for (; reg_start < evl; reg_start++) { +uint32_t byte_off = reg_start * esz; +ldst_host (vd, byte_off, host + byte_off);
target/riscv/vector_helper.c GEN_VEXT_ST_ELEM(ste_h, uint16_t, H2, stw) · line 519
Quoted 10 lines
target/riscv/vector_helper.c +10
-0+ } +#else +uint32_t group_byte; +uint32_t byte_start = reg_start * esz; +uint32_t byte_end = evl * esz; +while (byte_start < byte_end) { + group_byte =vext_group_ldst_host (env, vd, byte_end, byte_start, host, + esz, is_load); + byte_start += group_byte; + }
... this is much better handled with memcpy, given that you know endianness matches.
r~
Re: [RFC PATCH v4 4/5] target/riscv: rvv: Provide group continuous ld/st flow for unit-stride ld/st instructions
Quoted 79 lines · Richard Henderson
Quoted 33 lines · Max Chou
The vector unmasked unit-stride and whole register load/store instructions will load/store continuous memory. If the endian of both the host and guest architecture are the same, then we can group the element load/store to load/store more data at a time.
Signed-off-by Max Chou <[email protected]>---
target/riscv/vector_helper.c| 160 +++++++++++++++++++++++++----------1 file changed, 117 insertions(+), 43 deletions(-)target/riscv/vector_helper.c +0
-0@@ -457,6 +457,69 @@ GEN_VEXT_ST_ELEM(ste_h, uint16_t, H2, stw) GEN_VEXT_ST_ELEM(ste_w, uint32_t, H4, stl) GEN_VEXT_ST_ELEM(ste_d, uint64_t, H8, stq)+static inline
uint32_ttarget/riscv/vector_helper.c +15
-0+vext_group_ldst_host(CPURISCVState *env, void *vd, uint32_t byte_end, + uint32_t byte_offset, void *host, uint32_t esz, + bool is_load) +{ + uint32_t group_size; + static vext_ldst_elem_fn_host * const fns[2][4] = { + /* Store */ + { ste_b_host, ste_h_host, ste_w_host, ste_d_host }, + /* Load */ + { lde_b_host, lde_h_host, lde_w_host, lde_d_host } + }; + vext_ldst_elem_fn_host *fn; + + if (byte_offset + 8 < byte_end) { + group_size = MO_64;target/riscv/vector_helper.c GEN_VEXT_ST_ELEM(ste_h, uint16_t, H2, stw) · line 485
Quoted 10 lines
target/riscv/vector_helper.c +10
-0+ } else if (byte_offset + 4 < byte_end) { + group_size = MO_32; + } else if (byte_offset + 2 < byte_end) { + group_size = MO_16; + } else { + group_size = MO_8; + } + + fn = fns[is_load][group_size]; + fn(vd, byte_offset, host + byte_offset);This is a really bad idea. The table and indirect call means that none of these will be properly inlined. Anyway...
Quoted 32 lines
target/riscv/vector_helper.c +6
-0+ + return 1 << group_size; +} + +static inline void +vext_continus_ldst_tlb(CPURISCVState *env, vext_ldst_elem_fn_tlb
*ldst_tlb,
+ void *vd,uint32_tevl,target_ulongaddr, +uint32_treg_start,uintptr_tra,uint32_tesz, + boolis_load)target/riscv/vector_helper.c +8
-0+{ + for (; reg_start < evl; reg_start++, addr += esz) { + ldst_tlb(env, adjust_addr(env, addr), reg_start * esz, vd, ra); + } +} + +static inline void +vext_continus_ldst_host(CPURISCVState *env, vext_ldst_elem_fn_host
*ldst_host,
+ void *vd,uint32_tevl,uint32_treg_start, void *host,
+uint32_tesz, boolis_load)target/riscv/vector_helper.c +10
-0+{ +#if TARGET_BIG_ENDIAN !=HOST_BIG_ENDIAN + for (; reg_start < evl; reg_start++) { + uint32_t byte_off = reg_start * esz; + ldst_host(vd, byte_off, host + byte_off); + } +#else + uint32_t group_byte; + uint32_t byte_start = reg_start * esz; + uint32_t byte_end = evl * esz;
Quoted 8 lines
Quoted 6 lines
+ while (
byte_start<byte_end) {
+group_byte= vext_group_ldst_host(env, vd,byte_end,byte_start, host,
+ esz,is_load); +byte_start+=group_byte;
+ }... this is much better handled with memcpy, given that you know endianness matches.
Thanks for the suggestion.
I'll try to replace the original implementation of the table and indirect calls by handled with memcpy at the next version.
Max.
Quoted 3 lines
r~
RFC PATCH v4 5/5 target/riscv: Inline unit-stride ld/st and corresponding functions for performance
In reply to Max ChouIn the vector unit-stride load/store helper functions. the vext_ldst_us & vext_ldst_whole functions corresponding most of the execution time. Inline the functions can avoid the function call overhead to improve the helper function performance.
--- target/riscv/vector_helper.c | 64 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 30 deletions(-)
target/riscv/vector_helper.c +34 -30
@@ -415,20 +415,22 @@ typedef void vext_ldst_elem_fn_tlb(CPURISCVState *env, abi_ptr addr, uint32_t idx, void *vd, uintptr_t retaddr);typedef void vext_ldst_elem_fn_host (void *vd,uint32_t idx,void *host); -#define GEN_VEXT_LD_ELEM (NAME ,ETYPE ,H ,LDSUF ) \ -static void NAME##_tlb(CPURISCVState *env, abi_ptr addr, \ - uint32_t byte_off, void *vd, uintptr_t retaddr) \ -{ \ - uint8_t *reg = ((uint8_t *)vd + byte_off); \ - ETYPE *cur = ((ETYPE *)reg); \ - *cur = cpu_##LDSUF##_data_ra(env, addr, retaddr); \ -} \ - \ -static void NAME##_host(void *vd, uint32_t byte_off, void *host) \ -{ \ - ETYPE val = LDSUF##_p(host); \ - uint8_t *reg = (uint8_t *)(vd + byte_off); \ - *(ETYPE *)(reg) = val; \ +#define GEN_VEXT_LD_ELEM (NAME ,ETYPE ,H ,LDSUF ) \ +static inline QEMU_ALWAYS_INLINE \ +void NAME##_tlb(CPURISCVState *env, abi_ptr addr, \ + uint32_t byte_off, void *vd, uintptr_t retaddr) \ +{ \ + uint8_t *reg = ((uint8_t *)vd + byte_off); \ + ETYPE *cur = ((ETYPE *)reg); \ + *cur = cpu_##LDSUF##_data_ra(env, addr, retaddr); \ +} \ + \ +static inline QEMU_ALWAYS_INLINE \ +void NAME##_host(void *vd, uint32_t byte_off, void *host) \ +{ \ + ETYPE val = LDSUF##_p(host); \ + uint8_t *reg = (uint8_t *)(vd + byte_off); \ + *(ETYPE *)(reg) = val; \ }GEN_VEXT_LD_ELEM (lde_b, uint8_t,H1 , ldub)
@@ -436,20 +438,22 @@ GEN_VEXT_LD_ELEM(lde_h, uint16_t, H2, lduw) GEN_VEXT_LD_ELEM(lde_w, uint32_t, H4, ldl) GEN_VEXT_LD_ELEM(lde_d, uint64_t, H8, ldq) -#define GEN_VEXT_ST_ELEM (NAME ,ETYPE ,H ,STSUF ) \ -static void NAME##_tlb(CPURISCVState *env, abi_ptr addr, \ - uint32_t byte_off, void *vd, uintptr_t retaddr) \ -{ \ - uint8_t *reg = ((uint8_t *)vd + byte_off); \ - ETYPE data = *((ETYPE *)reg); \ - cpu_##STSUF##_data_ra(env, addr, data, retaddr); \ -} \ - \ -static void NAME##_host(void *vd, uint32_t byte_off, void *host) \ -{ \ - uint8_t *reg = ((uint8_t *)vd + byte_off); \ - ETYPE val = *(ETYPE *)(reg); \ - STSUF##_p(host, val); \ +#define GEN_VEXT_ST_ELEM (NAME ,ETYPE ,H ,STSUF ) \ +static inline QEMU_ALWAYS_INLINE \ +void NAME##_tlb(CPURISCVState *env, abi_ptr addr, \ + uint32_t byte_off, void *vd, uintptr_t retaddr) \ +{ \ + uint8_t *reg = ((uint8_t *)vd + byte_off); \ + ETYPE data = *((ETYPE *)reg); \ + cpu_##STSUF##_data_ra(env, addr, data, retaddr); \ +} \ + \ +static inline QEMU_ALWAYS_INLINE \ +void NAME##_host(void *vd, uint32_t byte_off, void *host) \ +{ \ + uint8_t *reg = ((uint8_t *)vd + byte_off); \ + ETYPE val = *(ETYPE *)(reg); \ + STSUF##_p(host, val); \ }GEN_VEXT_ST_ELEM (ste_b, uint8_t,H1 , stb)
@@ -611,7 +615,7 @@ GEN_VEXT_ST_STRIDE(vsse64_v, int64_t, ste_d_tlb)*/ /* unmasked unit-stride load and store operation */ -static void +static inline QEMU_ALWAYS_INLINE void vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, vext_ldst_elem_fn_tlb *ldst_tlb, vext_ldst_elem_fn_host *ldst_host, uint32_t log2_esz,
@@ -1013,7 +1017,7 @@ GEN_VEXT_LDFF(vle64ff_v, int64_t, lde_d_tlb)/* * load and store whole register instructions */ -static void +static inline QEMU_ALWAYS_INLINE void vext_ldst_whole(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc, vext_ldst_elem_fn_tlb *ldst_tlb, vext_ldst_elem_fn_host *ldst_host, uint32_t log2_esz,
Signature · 1 line
2.34.1
Re: [RFC PATCH v4 5/5] target/riscv: Inline unit-stride ld/st and corresponding functions for performance
Quoted 9 lines · Max Chou
In the vector unit-stride load/store helper functions. the
vext_ldst_us&vext_ldst_wholefunctions corresponding most of the execution time. Inline the functions can avoid the function call overhead to improve the helper function performance.Signed-off-by Max Chou <[email protected]>--- target/riscv/vector_helper.c | 64 +++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 30 deletions(-)
r~