Skip to content

Commit 5735c8b

Browse files
authored
[RV64_DYNAREC] Optimize some opcodes by removing redundant some vsetvli (#4588)
When VLMUL, TU, and MU remain unchanged: For `vmv.s.x`, if SEW stays unchanged, the vector configuration does not need to change. For `vmv.v.v`, if the width stays unchanged, the vector configuration does not need to change.
1 parent 827f0ee commit 5735c8b

5 files changed

Lines changed: 7 additions & 13 deletions

‎src/dynarec/rv64/dynarec_rv64_avx_0f_vector.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ uintptr_t dynarec64_AVX_0F_vector(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t
8888
INST_NAME("VMOVLPS Gx, Vx, Ex");
8989
SMREAD();
9090
addr = geted(dyn, addr, ninst, nextop, &ed, x2, x3, &fixedaddress, rex, NULL, 1, 0);
91-
if (fixedaddress) { ADDI(x4, ed, fixedaddress); ed = x4; fixedaddress = 0; }
92-
vector_vsetvli(dyn, ninst, x1, VECTOR_SEW64, VECTOR_LMUL1, 0.5);
93-
VLE64_V(q1, ed, VECTOR_UNMASKED, VECTOR_NFIELD1);
91+
LD(x4, ed, fixedaddress);
92+
VMV_S_X(q1, x4);
9493
}
9594
GETGY_empty_vector(v0);
9695
q2 = fpu_get_scratch(dyn);
@@ -158,9 +157,8 @@ uintptr_t dynarec64_AVX_0F_vector(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t
158157
INST_NAME("VMOVHPS Gx, Vx, Ex");
159158
SMREAD();
160159
addr = geted(dyn, addr, ninst, nextop, &ed, x2, x3, &fixedaddress, rex, NULL, 1, 0);
161-
if (fixedaddress) { ADDI(x4, ed, fixedaddress); ed = x4; fixedaddress = 0; }
162-
vector_vsetvli(dyn, ninst, x1, VECTOR_SEW64, VECTOR_LMUL1, 0.5);
163-
VLE64_V(q1, ed, VECTOR_UNMASKED, VECTOR_NFIELD1);
160+
LD(x4, ed, fixedaddress);
161+
VMV_S_X(q1, x4);
164162
}
165163
GETGY_empty_vector(v0);
166164
avx_set_vector_width(dyn, ninst, x1, VECTOR_SEW64, 16);

‎src/dynarec/rv64/dynarec_rv64_avx_66_0f38_vector.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,6 @@ uintptr_t dynarec64_AVX_66_0F38_vector(dynarec_rv64_t* dyn, uintptr_t addr, uint
17801780
OR(x4, x4, x5);
17811781
vector_vsetvli(dyn, ninst, x1, VECTOR_SEW32, VECTOR_LMUL1, 1);
17821782
VXOR_VV(v0, v0, v0, VECTOR_UNMASKED);
1783-
vector_vsetvli(dyn, ninst, x1, VECTOR_SEW32, VECTOR_LMUL1, 0.25f);
17841783
VMV_S_X(v0, x4);
17851784
avx_store_reg_vector(dyn, ninst, x1, v0, gd, 16, VECTOR_SEW32);
17861785
break;

‎src/dynarec/rv64/dynarec_rv64_avx_66_0f3a_vector.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ uintptr_t dynarec64_AVX_66_0F3A_vector(dynarec_rv64_t* dyn, uintptr_t addr, uint
118118
VEC_SRC_KEEP(q0, v0);
119119
q1 = fpu_get_scratch(dyn);
120120
MOV64x(x4, (uint64_t)(u8 & 1) | ((uint64_t)((u8 >> 1) & 1) << 16) | ((uint64_t)(((u8 >> 2) & 1) + 2) << 32) | ((uint64_t)(((u8 >> 3) & 1) + 2) << 48));
121-
vector_vsetvli(dyn, ninst, x1, VECTOR_SEW64, VECTOR_LMUL1, 1);
122121
VMV_S_X(q1, x4);
123-
avx_set_vector_width(dyn, ninst, x1, VECTOR_SEW64, 16 << vex.l);
124122
VRGATHEREI16_VV(v0, q0, q1, VECTOR_UNMASKED);
125123
PUTGY_vector(v0, VECTOR_SEW64);
126124
break;

‎src/dynarec/rv64/dynarec_rv64_avx_66_0f_vector.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ uintptr_t dynarec64_AVX_66_0F_vector(dynarec_rv64_t* dyn, uintptr_t addr, uintpt
132132
} else {
133133
SMREAD();
134134
addr = geted(dyn, addr, ninst, nextop, &ed, x2, x3, &fixedaddress, rex, NULL, 1, 0);
135-
if (fixedaddress) { ADDI(x4, ed, fixedaddress); ed = x4; fixedaddress = 0; }
136-
vector_vsetvli(dyn, ninst, x1, VECTOR_SEW64, VECTOR_LMUL1, 0.5);
137-
VLE64_V(q1, ed, VECTOR_UNMASKED, VECTOR_NFIELD1);
135+
LD(x4, ed, fixedaddress);
136+
VMV_S_X(q1, x4);
138137
}
139138
GETGY_empty_vector(v0);
140139
avx_set_vector_width(dyn, ninst, x1, VECTOR_SEW64, 16);

‎src/dynarec/rv64/dynarec_rv64_helper.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ void avx_store_reg_vector(dynarec_rv64_t* dyn, int ninst, int s1, int vreg, int
30553055
dyn->insts[ninst].vec_write_full |= 1u << a;
30563056
int cache = sse_get_reg_empty_vector(dyn, ninst, s1, a);
30573057
if (cache != vreg) {
3058-
avx_set_vector_width(dyn, ninst, s1, VECTOR_SEW8, width);
3058+
avx_set_vector_width(dyn, ninst, s1, sew, width);
30593059
VMV_V_V(cache, vreg);
30603060
}
30613061
if (cpuext.vlen >= 32) {

0 commit comments

Comments
 (0)