From 808fa1cab1abb2e339d6ed3cbd975418f7bb9b28 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Mon, 17 Apr 2023 17:05:28 -0700 Subject: Avoid declaring potentially out-of-bounds references in vmfeq etc. I don't think this was actually broken, since the references weren't used, but it was certainly unsanitary. Fixes #1325 --- riscv/v_ext_macros.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/riscv/v_ext_macros.h b/riscv/v_ext_macros.h index 3fc0162..7466a10 100644 --- a/riscv/v_ext_macros.h +++ b/riscv/v_ext_macros.h @@ -341,12 +341,12 @@ static inline bool is_aligned(const unsigned val, const unsigned pos) type_usew_t::type vs2 = P.VU.elt::type>(rs2_num, i); #define VV_PARAMS(x) \ - type_sew_t::type UNUSED &vd = P.VU.elt::type>(rd_num, i, true); \ + type_sew_t::type &vd = P.VU.elt::type>(rd_num, i, true); \ type_sew_t::type vs1 = P.VU.elt::type>(rs1_num, i); \ type_sew_t::type UNUSED vs2 = P.VU.elt::type>(rs2_num, i); #define VX_PARAMS(x) \ - type_sew_t::type UNUSED &vd = P.VU.elt::type>(rd_num, i, true); \ + type_sew_t::type &vd = P.VU.elt::type>(rd_num, i, true); \ type_sew_t::type rs1 = (type_sew_t::type)RS1; \ type_sew_t::type UNUSED vs2 = P.VU.elt::type>(rs2_num, i); @@ -442,16 +442,22 @@ static inline bool is_aligned(const unsigned val, const unsigned pos) float##width##_t &vd = P.VU.elt(rd_num, i, true); \ float##width##_t vs2 = P.VU.elt(rs2_num, i); -#define VFP_VV_PARAMS(width) \ - float##width##_t UNUSED &vd = P.VU.elt(rd_num, i, true); \ +#define VFP_VV_CMP_PARAMS(width) \ float##width##_t vs1 = P.VU.elt(rs1_num, i); \ float##width##_t vs2 = P.VU.elt(rs2_num, i); -#define VFP_VF_PARAMS(width) \ - float##width##_t UNUSED &vd = P.VU.elt(rd_num, i, true); \ +#define VFP_VV_PARAMS(width) \ + float##width##_t &vd = P.VU.elt(rd_num, i, true); \ + VFP_VV_CMP_PARAMS(width) + +#define VFP_VF_CMP_PARAMS(width) \ float##width##_t rs1 = f##width(READ_FREG(rs1_num)); \ float##width##_t vs2 = P.VU.elt(rs2_num, i); +#define VFP_VF_PARAMS(width) \ + float##width##_t &vd = P.VU.elt(rd_num, i, true); \ + VFP_VF_CMP_PARAMS(width) + #define CVT_FP_TO_FP_PARAMS(from_width, to_width) \ auto vs2 = P.VU.elt(rs2_num, i); \ auto &vd = P.VU.elt(rd_num, i, true); @@ -1739,19 +1745,19 @@ reg_t index[P.VU.vlmax]; \ VI_VFP_LOOP_CMP_BASE \ switch (P.VU.vsew) { \ case e16: { \ - VFP_VV_PARAMS(16); \ + VFP_VV_CMP_PARAMS(16); \ BODY16; \ set_fp_exceptions; \ break; \ } \ case e32: { \ - VFP_VV_PARAMS(32); \ + VFP_VV_CMP_PARAMS(32); \ BODY32; \ set_fp_exceptions; \ break; \ } \ case e64: { \ - VFP_VV_PARAMS(64); \ + VFP_VV_CMP_PARAMS(64); \ BODY64; \ set_fp_exceptions; \ break; \ @@ -1767,19 +1773,19 @@ reg_t index[P.VU.vlmax]; \ VI_VFP_LOOP_CMP_BASE \ switch (P.VU.vsew) { \ case e16: { \ - VFP_VF_PARAMS(16); \ + VFP_VF_CMP_PARAMS(16); \ BODY16; \ set_fp_exceptions; \ break; \ } \ case e32: { \ - VFP_VF_PARAMS(32); \ + VFP_VF_CMP_PARAMS(32); \ BODY32; \ set_fp_exceptions; \ break; \ } \ case e64: { \ - VFP_VF_PARAMS(64); \ + VFP_VF_CMP_PARAMS(64); \ BODY64; \ set_fp_exceptions; \ break; \ -- cgit v1.1