Skip to contentSkip to conversation

target/riscv: fix vrgather macro index variable type bug

PATCH In review [email protected] 2 participants 2 messages Apr 19, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: fix vrgather macro index variable type bug

From: Frank Chang <[email protected]>

ETYPE may be type of uint64_t, thus index variable has to be declared as type of uint64_t, too. Otherwise the value read from vs1 register may be truncated to type of uint32_t.

---
 target/riscv/vector_helper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/riscv/vector_helper.c +4 -2
index a156573d281..4a70776af32 100644
@@ -4796,7 +4796,8 @@ void HELPER(NAME)(void *vd, void *v0, void *vs1, void *vs2,               \
     uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen;                   \
     uint32_t vm = vext_vm(desc);                                          \
     uint32_t vl = env->vl;                                                \
-    uint32_t index, i;                                                    \
+    uint64_t index;                                                       \
+    uint32_t i;                                                           \
                                                                           \
     for (i = 0; i < vl; i++) {                                            \
         if (!vm && !vext_elem_mask(v0, mlen, i)) {                        \
@@ -4826,7 +4827,8 @@ void HELPER(NAME)(void *vd, void *v0, target_ulong s1, void *vs2,         \
     uint32_t vlmax = env_archcpu(env)->cfg.vlen / mlen;                   \
     uint32_t vm = vext_vm(desc);                                          \
     uint32_t vl = env->vl;                                                \
-    uint32_t index = s1, i;                                               \
+    uint64_t index = s1;                                                  \
+    uint32_t i;                                                           \
                                                                           \
     for (i = 0; i < vl; i++) {                                            \
         if (!vm && !vext_elem_mask(v0, mlen, i)) {                        \
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · On 4/18/21 11:03 PM, [email protected] wrote:

From: Frank Chang<[email protected]>

ETYPE may be type of uint64_t, thus index variable has to be declared as type of uint64_t, too. Otherwise the value read from vs1 register may be truncated to type of uint32_t.

---
  target/riscv/vector_helper.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

r~