Skip to contentSkip to conversation

target/riscv: mask vxrm csrw write to the low 2 bits

PATCH Applied Abhigyan Kumar 3 participants 4 messages May 30 – Jun 3 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/riscv: mask vxrm csrw write to the low 2 bits

Citing the RISC-V specification:

"The vector fixed-point rounding-mode register holds a two-bit read-write rounding-mode field in the least-significant bits (vxrm[1:0]). The upper bits, vxrm[XLEN-1:2], should be written as zeros."

QEMU wrote full value into env->vxrm causing read of upper bits too. Used existing macros for bit-masking. Previous had a hard-coded value.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3470

---
 target/riscv/csr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -1
index 5514e0f45..7b98d66db 100644
@@ -977,7 +977,7 @@ static RISCVException write_vxrm(CPURISCVState *env, int csrno,
 #if !defined(CONFIG_USER_ONLY)
     env->mstatus |= MSTATUS_VS;
 #endif
-    env->vxrm = val;
+    env->vxrm = val & (VCSR_VXRM >> VCSR_VXRM_SHIFT);
     return RISCV_EXCP_NONE;
 }
 
Signature · 1 line
2.54.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Abhigyan Kumar

Citing the RISC-V specification:

"The vector fixed-point rounding-mode register holds a two-bit read-write rounding-mode field in the least-significant bits (vxrm[1:0]). The upper bits, vxrm[XLEN-1:2], should be written as zeros."

Quoted 6 lines

QEMU wrote full value into env->vxrm causing read of upper bits too. Used existing macros for bit-masking. Previous had a hard-coded value.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3470

---

Quoted 16 lines
  target/riscv/csr.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -1
index 5514e0f45..7b98d66db 100644
@@ -977,7 +977,7 @@ static RISCVException write_vxrm(CPURISCVState *env, int csrno,
  #if !defined(CONFIG_USER_ONLY)
      env->mstatus |= MSTATUS_VS;
  #endif
-    env->vxrm = val;
+    env->vxrm = val & (VCSR_VXRM >> VCSR_VXRM_SHIFT);
      return RISCV_EXCP_NONE;
  }
 
Reviewed-by on v2 1/1
#2 lore raw
In reply to Abhigyan Kumar
Quoted 8 lines · Abhigyan Kumar

Citing the RISC-V specification:

"The vector fixed-point rounding-mode register holds a two-bit read-write rounding-mode field in the least-significant bits (vxrm[1:0]). The upper bits, vxrm[XLEN-1:2], should be written as zeros."

Quoted 5 lines

QEMU wrote full value into env->vxrm causing read of upper bits too. Used existing macros for bit-masking. Previous had a hard-coded value.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3470

Alistair

Quoted 21 lines
---
 target/riscv/csr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -2
index 5514e0f45..7b98d66db 100644
@@ -977,7 +977,7 @@ static RISCVException write_vxrm(CPURISCVState *env, int csrno,
 #if !defined(CONFIG_USER_ONLY)
     env->mstatus |= MSTATUS_VS;
 #endif
-    env->vxrm = val;
+    env->vxrm = val & (VCSR_VXRM >> VCSR_VXRM_SHIFT);
     return RISCV_EXCP_NONE;
 }
 
--

2.54.0

#3 lore raw
In reply to Abhigyan Kumar
Quoted 8 lines · Abhigyan Kumar

Citing the RISC-V specification:

"The vector fixed-point rounding-mode register holds a two-bit read-write rounding-mode field in the least-significant bits (vxrm[1:0]). The upper bits, vxrm[XLEN-1:2], should be written as zeros."

Quoted 5 lines

QEMU wrote full value into env->vxrm causing read of upper bits too. Used existing macros for bit-masking. Previous had a hard-coded value.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3470

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 21 lines
---
 target/riscv/csr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -2
index 5514e0f45..7b98d66db 100644
@@ -977,7 +977,7 @@ static RISCVException write_vxrm(CPURISCVState *env, int csrno,
 #if !defined(CONFIG_USER_ONLY)
     env->mstatus |= MSTATUS_VS;
 #endif
-    env->vxrm = val;
+    env->vxrm = val & (VCSR_VXRM >> VCSR_VXRM_SHIFT);
     return RISCV_EXCP_NONE;
 }
 
--

2.54.0