qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-9.0 v14 4/8] target/riscv/vector_helpers: do early exit w


From: Max Chou
Subject: Re: [PATCH for-9.0 v14 4/8] target/riscv/vector_helpers: do early exit when vstart >= vl
Date: Thu, 14 Mar 2024 11:52:42 +0800
User-agent: Mozilla Thunderbird

Hi Daniel,

According the v spec section 15.2 & 15.3.

"The vcpop.m instruction writes x[rd] even if vl=0 (with the value 0, since no mask elements are active).
  Traps on
vcpop.m are always reported with a vstart of 0. The vcpop.m instruction will raise an illegal instruction exception if vstart is non-zero."

"
The vfirst.m instruction writes x[rd] even if vl=0 (with the value -1, since no mask elements are active).
 Traps on
vfirst are always reported with a vstart of 0. The vfirst instruction will raise an illegal instruction exception if vstart is non-zero."

Both the vcpop.m and vfirst.m instructions will raise illegal instruction exception with non-zero vstart.

And currently both the trans_vcpop_m and trans_vfirst_m translate functions check the vstart_eq_zero flag.
So I think the early exit checking in the vcpop.m and vfirstm helper functions may be redundant.

@@ -4585,6 +4641,11 @@ target_ulong HELPER(vcpop_m)(void *v0, void *vs2, CPURISCVState *env,
     uint32_t vl = env->vl;
     int i;
 
+    if (env->vstart >= env->vl) {
+        env->vstart = 0;
+        return 0;
+    }
+
     for (i = env->vstart; i < vl; i++) {
         if (vm || vext_elem_mask(v0, i)) {
             if (vext_elem_mask(vs2, i)) {

According v spec section 15.3

""The vfirst.m instruction writes x[rd] even if vl=0 (with the value -1, since no mask elements are active)."

If both the vstart and vl are 0 here, the early exit checking will return the wrong value 0 (the return value should be -1) here.

@@ -4604,6 +4665,11 @@ target_ulong HELPER(vfirst_m)(void *v0, void *vs2, CPURISCVState *env,
     uint32_t vl = env->vl;
     int i;
 
+    if (env->vstart >= env->vl) {
+        env->vstart = 0;
+        return 0;
+    }
+
     for (i = env->vstart; i < vl; i++) {
         if (vm || vext_elem_mask(v0, i)) {
             if (vext_elem_mask(vs2, i)) {


reply via email to

[Prev in Thread] Current Thread [Next in Thread]