qemu-devel
[Top][All Lists]
Advanced

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

[PATCH v2 31/46] target/loongarch: Implement xvssrlrn xvssrarn


From: Song Gao
Subject: [PATCH v2 31/46] target/loongarch: Implement xvssrlrn xvssrarn
Date: Fri, 30 Jun 2023 15:58:49 +0800

This patch includes:
- XVSSRLRN.{B.H/H.W/W.D};
- XVSSRARN.{B.H/H.W/W.D};
- XVSSRLRN.{BU.H/HU.W/WU.D};
- XVSSRARN.{BU.H/HU.W/WU.D};
- XVSSRLRNI.{B.H/H.W/W.D/D.Q};
- XVSSRARNI.{B.H/H.W/W.D/D.Q};
- XVSSRLRNI.{BU.H/HU.W/WU.D/DU.Q};
- XVSSRARNI.{BU.H/HU.W/WU.D/DU.Q}.

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 target/loongarch/disas.c                     |  30 ++
 target/loongarch/helper.h                    |  58 +--
 target/loongarch/insn_trans/trans_lasx.c.inc |  30 ++
 target/loongarch/insns.decode                |  30 ++
 target/loongarch/vec_helper.c                | 496 +++++++++++--------
 5 files changed, 400 insertions(+), 244 deletions(-)

diff --git a/target/loongarch/disas.c b/target/loongarch/disas.c
index 04e8d42044..f043a2f9b6 100644
--- a/target/loongarch/disas.c
+++ b/target/loongarch/disas.c
@@ -2166,6 +2166,36 @@ INSN_LASX(xvssrani_hu_w,     vv_i)
 INSN_LASX(xvssrani_wu_d,     vv_i)
 INSN_LASX(xvssrani_du_q,     vv_i)
 
+INSN_LASX(xvssrlrn_b_h,      vvv)
+INSN_LASX(xvssrlrn_h_w,      vvv)
+INSN_LASX(xvssrlrn_w_d,      vvv)
+INSN_LASX(xvssrarn_b_h,      vvv)
+INSN_LASX(xvssrarn_h_w,      vvv)
+INSN_LASX(xvssrarn_w_d,      vvv)
+INSN_LASX(xvssrlrn_bu_h,     vvv)
+INSN_LASX(xvssrlrn_hu_w,     vvv)
+INSN_LASX(xvssrlrn_wu_d,     vvv)
+INSN_LASX(xvssrarn_bu_h,     vvv)
+INSN_LASX(xvssrarn_hu_w,     vvv)
+INSN_LASX(xvssrarn_wu_d,     vvv)
+
+INSN_LASX(xvssrlrni_b_h,     vv_i)
+INSN_LASX(xvssrlrni_h_w,     vv_i)
+INSN_LASX(xvssrlrni_w_d,     vv_i)
+INSN_LASX(xvssrlrni_d_q,     vv_i)
+INSN_LASX(xvssrlrni_bu_h,    vv_i)
+INSN_LASX(xvssrlrni_hu_w,    vv_i)
+INSN_LASX(xvssrlrni_wu_d,    vv_i)
+INSN_LASX(xvssrlrni_du_q,    vv_i)
+INSN_LASX(xvssrarni_b_h,     vv_i)
+INSN_LASX(xvssrarni_h_w,     vv_i)
+INSN_LASX(xvssrarni_w_d,     vv_i)
+INSN_LASX(xvssrarni_d_q,     vv_i)
+INSN_LASX(xvssrarni_bu_h,    vv_i)
+INSN_LASX(xvssrarni_hu_w,    vv_i)
+INSN_LASX(xvssrarni_wu_d,    vv_i)
+INSN_LASX(xvssrarni_du_q,    vv_i)
+
 INSN_LASX(xvreplgr2vr_b,     vr)
 INSN_LASX(xvreplgr2vr_h,     vr)
 INSN_LASX(xvreplgr2vr_w,     vr)
diff --git a/target/loongarch/helper.h b/target/loongarch/helper.h
index 5f768b31b7..896624a435 100644
--- a/target/loongarch/helper.h
+++ b/target/loongarch/helper.h
@@ -455,35 +455,35 @@ DEF_HELPER_5(vssrani_hu_w, void, env, i32, i32, i32, i32)
 DEF_HELPER_5(vssrani_wu_d, void, env, i32, i32, i32, i32)
 DEF_HELPER_5(vssrani_du_q, void, env, i32, i32, i32, i32)
 
-DEF_HELPER_4(vssrlrn_b_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrn_h_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrn_w_d, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarn_b_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarn_h_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarn_w_d, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrn_bu_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrn_hu_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrn_wu_d, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarn_bu_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarn_hu_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarn_wu_d, void, env, i32, i32, i32)
-
-DEF_HELPER_4(vssrlrni_b_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrni_h_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrni_w_d, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrni_d_q, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_b_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_h_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_w_d, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_d_q, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrni_bu_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrni_hu_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrni_wu_d, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrlrni_du_q, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_bu_h, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_hu_w, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_wu_d, void, env, i32, i32, i32)
-DEF_HELPER_4(vssrarni_du_q, void, env, i32, i32, i32)
+DEF_HELPER_5(vssrlrn_b_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrn_h_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrn_w_d, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarn_b_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarn_h_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarn_w_d, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrn_bu_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrn_hu_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrn_wu_d, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarn_bu_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarn_hu_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarn_wu_d, void, env, i32, i32, i32, i32)
+
+DEF_HELPER_5(vssrlrni_b_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrni_h_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrni_w_d, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrni_d_q, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_b_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_h_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_w_d, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_d_q, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrni_bu_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrni_hu_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrni_wu_d, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrlrni_du_q, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_bu_h, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_hu_w, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_wu_d, void, env, i32, i32, i32, i32)
+DEF_HELPER_5(vssrarni_du_q, void, env, i32, i32, i32, i32)
 
 DEF_HELPER_3(vclo_b, void, env, i32, i32)
 DEF_HELPER_3(vclo_h, void, env, i32, i32)
diff --git a/target/loongarch/insn_trans/trans_lasx.c.inc 
b/target/loongarch/insn_trans/trans_lasx.c.inc
index d55b6239e8..e74ad51797 100644
--- a/target/loongarch/insn_trans/trans_lasx.c.inc
+++ b/target/loongarch/insn_trans/trans_lasx.c.inc
@@ -542,6 +542,36 @@ TRANS(xvssrani_hu_w, gen_vv_i, 32, gen_helper_vssrani_hu_w)
 TRANS(xvssrani_wu_d, gen_vv_i, 32, gen_helper_vssrani_wu_d)
 TRANS(xvssrani_du_q, gen_vv_i, 32, gen_helper_vssrani_du_q)
 
+TRANS(xvssrlrn_b_h, gen_vvv, 32, gen_helper_vssrlrn_b_h)
+TRANS(xvssrlrn_h_w, gen_vvv, 32, gen_helper_vssrlrn_h_w)
+TRANS(xvssrlrn_w_d, gen_vvv, 32, gen_helper_vssrlrn_w_d)
+TRANS(xvssrarn_b_h, gen_vvv, 32, gen_helper_vssrarn_b_h)
+TRANS(xvssrarn_h_w, gen_vvv, 32, gen_helper_vssrarn_h_w)
+TRANS(xvssrarn_w_d, gen_vvv, 32, gen_helper_vssrarn_w_d)
+TRANS(xvssrlrn_bu_h, gen_vvv, 32, gen_helper_vssrlrn_bu_h)
+TRANS(xvssrlrn_hu_w, gen_vvv, 32, gen_helper_vssrlrn_hu_w)
+TRANS(xvssrlrn_wu_d, gen_vvv, 32, gen_helper_vssrlrn_wu_d)
+TRANS(xvssrarn_bu_h, gen_vvv, 32, gen_helper_vssrarn_bu_h)
+TRANS(xvssrarn_hu_w, gen_vvv, 32, gen_helper_vssrarn_hu_w)
+TRANS(xvssrarn_wu_d, gen_vvv, 32, gen_helper_vssrarn_wu_d)
+
+TRANS(xvssrlrni_b_h, gen_vv_i, 32, gen_helper_vssrlrni_b_h)
+TRANS(xvssrlrni_h_w, gen_vv_i, 32, gen_helper_vssrlrni_h_w)
+TRANS(xvssrlrni_w_d, gen_vv_i, 32, gen_helper_vssrlrni_w_d)
+TRANS(xvssrlrni_d_q, gen_vv_i, 32, gen_helper_vssrlrni_d_q)
+TRANS(xvssrarni_b_h, gen_vv_i, 32, gen_helper_vssrarni_b_h)
+TRANS(xvssrarni_h_w, gen_vv_i, 32, gen_helper_vssrarni_h_w)
+TRANS(xvssrarni_w_d, gen_vv_i, 32, gen_helper_vssrarni_w_d)
+TRANS(xvssrarni_d_q, gen_vv_i, 32, gen_helper_vssrarni_d_q)
+TRANS(xvssrlrni_bu_h, gen_vv_i, 32, gen_helper_vssrlrni_bu_h)
+TRANS(xvssrlrni_hu_w, gen_vv_i, 32, gen_helper_vssrlrni_hu_w)
+TRANS(xvssrlrni_wu_d, gen_vv_i, 32, gen_helper_vssrlrni_wu_d)
+TRANS(xvssrlrni_du_q, gen_vv_i, 32, gen_helper_vssrlrni_du_q)
+TRANS(xvssrarni_bu_h, gen_vv_i, 32, gen_helper_vssrarni_bu_h)
+TRANS(xvssrarni_hu_w, gen_vv_i, 32, gen_helper_vssrarni_hu_w)
+TRANS(xvssrarni_wu_d, gen_vv_i, 32, gen_helper_vssrarni_wu_d)
+TRANS(xvssrarni_du_q, gen_vv_i, 32, gen_helper_vssrarni_du_q)
+
 TRANS(xvreplgr2vr_b, gvec_dup, 32, MO_8)
 TRANS(xvreplgr2vr_h, gvec_dup, 32, MO_16)
 TRANS(xvreplgr2vr_w, gvec_dup, 32, MO_32)
diff --git a/target/loongarch/insns.decode b/target/loongarch/insns.decode
index 022dd9bfd1..dc74bae7a5 100644
--- a/target/loongarch/insns.decode
+++ b/target/loongarch/insns.decode
@@ -1740,6 +1740,36 @@ xvssrani_hu_w    0111 01110110 01001 ..... ..... .....   
 @vv_ui5
 xvssrani_wu_d    0111 01110110 0101 ...... ..... .....    @vv_ui6
 xvssrani_du_q    0111 01110110 011 ....... ..... .....    @vv_ui7
 
+xvssrlrn_b_h     0111 01010000 00001 ..... ..... .....    @vvv
+xvssrlrn_h_w     0111 01010000 00010 ..... ..... .....    @vvv
+xvssrlrn_w_d     0111 01010000 00011 ..... ..... .....    @vvv
+xvssrarn_b_h     0111 01010000 00101 ..... ..... .....    @vvv
+xvssrarn_h_w     0111 01010000 00110 ..... ..... .....    @vvv
+xvssrarn_w_d     0111 01010000 00111 ..... ..... .....    @vvv
+xvssrlrn_bu_h    0111 01010000 10001 ..... ..... .....    @vvv
+xvssrlrn_hu_w    0111 01010000 10010 ..... ..... .....    @vvv
+xvssrlrn_wu_d    0111 01010000 10011 ..... ..... .....    @vvv
+xvssrarn_bu_h    0111 01010000 10101 ..... ..... .....    @vvv
+xvssrarn_hu_w    0111 01010000 10110 ..... ..... .....    @vvv
+xvssrarn_wu_d    0111 01010000 10111 ..... ..... .....    @vvv
+
+xvssrlrni_b_h    0111 01110101 00000 1 .... ..... .....   @vv_ui4
+xvssrlrni_h_w    0111 01110101 00001 ..... ..... .....    @vv_ui5
+xvssrlrni_w_d    0111 01110101 0001 ...... ..... .....    @vv_ui6
+xvssrlrni_d_q    0111 01110101 001 ....... ..... .....    @vv_ui7
+xvssrarni_b_h    0111 01110110 10000 1 .... ..... .....   @vv_ui4
+xvssrarni_h_w    0111 01110110 10001 ..... ..... .....    @vv_ui5
+xvssrarni_w_d    0111 01110110 1001 ...... ..... .....    @vv_ui6
+xvssrarni_d_q    0111 01110110 101 ....... ..... .....    @vv_ui7
+xvssrlrni_bu_h   0111 01110101 01000 1 .... ..... .....   @vv_ui4
+xvssrlrni_hu_w   0111 01110101 01001 ..... ..... .....    @vv_ui5
+xvssrlrni_wu_d   0111 01110101 0101 ...... ..... .....    @vv_ui6
+xvssrlrni_du_q   0111 01110101 011 ....... ..... .....    @vv_ui7
+xvssrarni_bu_h   0111 01110110 11000 1 .... ..... .....   @vv_ui4
+xvssrarni_hu_w   0111 01110110 11001 ..... ..... .....    @vv_ui5
+xvssrarni_wu_d   0111 01110110 1101 ...... ..... .....    @vv_ui6
+xvssrarni_du_q   0111 01110110 111 ....... ..... .....    @vv_ui7
+
 xvreplgr2vr_b    0111 01101001 11110 00000 ..... .....    @vr
 xvreplgr2vr_h    0111 01101001 11110 00001 ..... .....    @vr
 xvreplgr2vr_w    0111 01101001 11110 00010 ..... .....    @vr
diff --git a/target/loongarch/vec_helper.c b/target/loongarch/vec_helper.c
index 27a5a5253a..c61eb1c558 100644
--- a/target/loongarch/vec_helper.c
+++ b/target/loongarch/vec_helper.c
@@ -1875,7 +1875,7 @@ static T1 do_ssrlrns_ ## E1(T2 e2, int sa, int sh) \
                                                    \
     shft_res = do_vsrlr_ ## E2(e2, sa);            \
     T1 mask;                                       \
-    mask = (1ull << sh) -1;                        \
+    mask = (1ull << sh) - 1;                       \
     if (shft_res > mask) {                         \
         return mask;                               \
     } else {                                       \
@@ -1887,24 +1887,33 @@ SSRLRNS(B, H, uint16_t, int16_t, uint8_t)
 SSRLRNS(H, W, uint32_t, int32_t, uint16_t)
 SSRLRNS(W, D, uint64_t, int64_t, uint32_t)
 
-#define VSSRLRN(NAME, BIT, T, E1, E2)                                         \
-void HELPER(NAME)(CPULoongArchState *env,                                     \
-                  uint32_t vd, uint32_t vj, uint32_t vk)                      \
-{                                                                             \
-    int i;                                                                    \
-    VReg *Vd = &(env->fpr[vd].vreg);                                          \
-    VReg *Vj = &(env->fpr[vj].vreg);                                          \
-    VReg *Vk = &(env->fpr[vk].vreg);                                          \
-                                                                              \
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                       \
-        Vd->E1(i) = do_ssrlrns_ ## E1(Vj->E2(i), (T)Vk->E2(i)%BIT, BIT/2 -1); \
-    }                                                                         \
-    Vd->D(1) = 0;                                                             \
+#define VSSRLRN(NAME, BIT, E1, E2, E3)                                         
\
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,                      
\
+                  uint32_t vd, uint32_t vj, uint32_t vk)                       
\
+{                                                                              
\
+    int i, max;                                                                
\
+    VReg *Vd = &(env->fpr[vd].vreg);                                           
\
+    VReg *Vj = &(env->fpr[vj].vreg);                                           
\
+    VReg *Vk = &(env->fpr[vk].vreg);                                           
\
+                                                                               
\
+    max = LSX_LEN / BIT;                                                       
\
+    for (i = 0; i < max; i++) {                                                
\
+        Vd->E1(i) = do_ssrlrns_ ## E1(Vj->E2(i), Vk->E3(i) % BIT, BIT / 2 -1); 
\
+        if (oprsz == 32) {                                                     
\
+            Vd->E1(i + max * 2) = do_ssrlrns_ ## E1(Vj->E2(i + max),           
\
+                                                    Vk->E3(i + max) % BIT,     
\
+                                                    BIT / 2 - 1);              
\
+        }                                                                      
\
+    }                                                                          
\
+    Vd->D(1) = 0;                                                              
\
+    if (oprsz == 32) {                                                         
\
+        Vd->D(3) = 0;                                                          
\
+    }                                                                          
\
 }
 
-VSSRLRN(vssrlrn_b_h, 16, uint16_t, B, H)
-VSSRLRN(vssrlrn_h_w, 32, uint32_t, H, W)
-VSSRLRN(vssrlrn_w_d, 64, uint64_t, W, D)
+VSSRLRN(vssrlrn_b_h, 16, B, H, UH)
+VSSRLRN(vssrlrn_h_w, 32, H, W, UW)
+VSSRLRN(vssrlrn_w_d, 64, W, D, UD)
 
 #define SSRARNS(E1, E2, T1, T2)                    \
 static T1 do_ssrarns_ ## E1(T1 e2, int sa, int sh) \
@@ -1913,7 +1922,7 @@ static T1 do_ssrarns_ ## E1(T1 e2, int sa, int sh) \
                                                    \
     shft_res = do_vsrar_ ## E2(e2, sa);            \
     T2 mask;                                       \
-    mask = (1ll << sh) -1;                         \
+    mask = (1ll << sh) - 1;                        \
     if (shft_res > mask) {                         \
         return  mask;                              \
     } else if (shft_res < -(mask +1)) {            \
@@ -1927,24 +1936,34 @@ SSRARNS(B, H, int16_t, int8_t)
 SSRARNS(H, W, int32_t, int16_t)
 SSRARNS(W, D, int64_t, int32_t)
 
-#define VSSRARN(NAME, BIT, T, E1, E2)                                         \
-void HELPER(NAME)(CPULoongArchState *env,                                     \
-                  uint32_t vd, uint32_t vj, uint32_t vk)                      \
-{                                                                             \
-    int i;                                                                    \
-    VReg *Vd = &(env->fpr[vd].vreg);                                          \
-    VReg *Vj = &(env->fpr[vj].vreg);                                          \
-    VReg *Vk = &(env->fpr[vk].vreg);                                          \
-                                                                              \
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                       \
-        Vd->E1(i) = do_ssrarns_ ## E1(Vj->E2(i), (T)Vk->E2(i)%BIT, BIT/2 -1); \
-    }                                                                         \
-    Vd->D(1) = 0;                                                             \
+#define VSSRARN(NAME, BIT, E1, E2, E3)                                    \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,                 \
+                  uint32_t vd, uint32_t vj, uint32_t vk)                  \
+{                                                                         \
+    int i, max;                                                           \
+    VReg *Vd = &(env->fpr[vd].vreg);                                      \
+    VReg *Vj = &(env->fpr[vj].vreg);                                      \
+    VReg *Vk = &(env->fpr[vk].vreg);                                      \
+                                                                          \
+    max = LSX_LEN / BIT;                                                  \
+    for (i = 0; i < max; i++) {                                           \
+        Vd->E1(i) = do_ssrarns_ ## E1(Vj->E2(i),                          \
+                                      Vk->E3(i) % BIT, BIT / 2 - 1);      \
+        if (oprsz == 32) {                                                \
+            Vd->E1(i + max * 2) = do_ssrarns_ ## E1(Vj->E2(i + max),      \
+                                                   Vk->E3(i + max) % BIT, \
+                                                   BIT/ 2 - 1);           \
+        }                                                                 \
+    }                                                                     \
+    Vd->D(1) = 0;                                                         \
+    if (oprsz == 32) {                                                    \
+        Vd->D(3) = 0;                                                     \
+    }                                                                     \
 }
 
-VSSRARN(vssrarn_b_h, 16, uint16_t, B, H)
-VSSRARN(vssrarn_h_w, 32, uint32_t, H, W)
-VSSRARN(vssrarn_w_d, 64, uint64_t, W, D)
+VSSRARN(vssrarn_b_h, 16, B, H, UH)
+VSSRARN(vssrarn_h_w, 32, H, W, UW)
+VSSRARN(vssrarn_w_d, 64, W, D, UD)
 
 #define SSRLRNU(E1, E2, T1, T2, T3)                \
 static T1 do_ssrlrnu_ ## E1(T3 e2, int sa, int sh) \
@@ -1954,7 +1973,7 @@ static T1 do_ssrlrnu_ ## E1(T3 e2, int sa, int sh) \
     shft_res = do_vsrlr_ ## E2(e2, sa);            \
                                                    \
     T2 mask;                                       \
-    mask = (1ull << sh) -1;                        \
+    mask = (1ull << sh) - 1;                       \
     if (shft_res > mask) {                         \
         return mask;                               \
     } else {                                       \
@@ -1966,24 +1985,33 @@ SSRLRNU(B, H, uint16_t, uint8_t, int16_t)
 SSRLRNU(H, W, uint32_t, uint16_t, int32_t)
 SSRLRNU(W, D, uint64_t, uint32_t, int64_t)
 
-#define VSSRLRNU(NAME, BIT, T, E1, E2)                                     \
-void HELPER(NAME)(CPULoongArchState *env,                                  \
-                  uint32_t vd, uint32_t vj, uint32_t vk)                   \
-{                                                                          \
-    int i;                                                                 \
-    VReg *Vd = &(env->fpr[vd].vreg);                                       \
-    VReg *Vj = &(env->fpr[vj].vreg);                                       \
-    VReg *Vk = &(env->fpr[vk].vreg);                                       \
-                                                                           \
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                    \
-        Vd->E1(i) = do_ssrlrnu_ ## E1(Vj->E2(i), (T)Vk->E2(i)%BIT, BIT/2); \
-    }                                                                      \
-    Vd->D(1) = 0;                                                          \
+#define VSSRLRNU(NAME, BIT, E1, E2, E3)                                     \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,                   \
+                  uint32_t vd, uint32_t vj, uint32_t vk)                    \
+{                                                                           \
+    int i, max;                                                             \
+    VReg *Vd = &(env->fpr[vd].vreg);                                        \
+    VReg *Vj = &(env->fpr[vj].vreg);                                        \
+    VReg *Vk = &(env->fpr[vk].vreg);                                        \
+                                                                            \
+    max = LSX_LEN / BIT;                                                    \
+    for (i = 0; i < max; i++) {                                             \
+        Vd->E1(i) = do_ssrlrnu_ ## E1(Vj->E2(i), Vk->E3(i) % BIT, BIT / 2); \
+        if (oprsz == 32) {                                                  \
+            Vd->E1(i + max * 2) = do_ssrlrnu_ ## E1(Vj->E2(i + max),        \
+                                                    Vk->E3(i + max) % BIT,  \
+                                                    BIT / 2);               \
+        }                                                                   \
+    }                                                                       \
+    Vd->D(1) = 0;                                                           \
+    if (oprsz == 32) {                                                      \
+        Vd->D(3) = 0;                                                       \
+    }                                                                       \
 }
 
-VSSRLRNU(vssrlrn_bu_h, 16, uint16_t, B, H)
-VSSRLRNU(vssrlrn_hu_w, 32, uint32_t, H, W)
-VSSRLRNU(vssrlrn_wu_d, 64, uint64_t, W, D)
+VSSRLRNU(vssrlrn_bu_h, 16, B, H, UH)
+VSSRLRNU(vssrlrn_hu_w, 32, H, W, UW)
+VSSRLRNU(vssrlrn_wu_d, 64, W, D, UD)
 
 #define SSRARNU(E1, E2, T1, T2, T3)                \
 static T1 do_ssrarnu_ ## E1(T3 e2, int sa, int sh) \
@@ -1996,7 +2024,7 @@ static T1 do_ssrarnu_ ## E1(T3 e2, int sa, int sh) \
         shft_res = do_vsrar_ ## E2(e2, sa);        \
     }                                              \
     T2 mask;                                       \
-    mask = (1ull << sh) -1;                        \
+    mask = (1ull << sh) - 1;                       \
     if (shft_res > mask) {                         \
         return mask;                               \
     } else {                                       \
@@ -2008,131 +2036,156 @@ SSRARNU(B, H, uint16_t, uint8_t, int16_t)
 SSRARNU(H, W, uint32_t, uint16_t, int32_t)
 SSRARNU(W, D, uint64_t, uint32_t, int64_t)
 
-#define VSSRARNU(NAME, BIT, T, E1, E2)                                     \
-void HELPER(NAME)(CPULoongArchState *env,                                  \
-                  uint32_t vd, uint32_t vj, uint32_t vk)                   \
+#define VSSRARNU(NAME, BIT, E1, E2, E3)                                     \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,                   \
+                  uint32_t vd, uint32_t vj, uint32_t vk)                    \
+{                                                                           \
+    int i, max;                                                             \
+    VReg *Vd = &(env->fpr[vd].vreg);                                        \
+    VReg *Vj = &(env->fpr[vj].vreg);                                        \
+    VReg *Vk = &(env->fpr[vk].vreg);                                        \
+                                                                            \
+    max = LSX_LEN / BIT;                                                    \
+    for (i = 0; i < max; i++) {                                             \
+        Vd->E1(i) = do_ssrarnu_ ## E1(Vj->E2(i), Vk->E3(i) % BIT, BIT / 2); \
+        if (oprsz == 32) {                                                  \
+            Vd->E1(i + max * 2) = do_ssrarnu_ ## E1(Vj->E2(i + max),        \
+                                                    Vk->E3(i + max) % BIT,  \
+                                                    BIT / 2);               \
+        }                                                                   \
+    }                                                                       \
+    Vd->D(1) = 0;                                                           \
+    if (oprsz == 32) {                                                      \
+        Vd->D(3) = 0;                                                       \
+    }                                                                       \
+}
+
+VSSRARNU(vssrarn_bu_h, 16, B, H, UH)
+VSSRARNU(vssrarn_hu_w, 32, H, W, UW)
+VSSRARNU(vssrarn_wu_d, 64, W, D, UD)
+
+#define VSSRLRNI(NAME, BIT, E1, E2)                                        \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,                  \
+                  uint32_t vd, uint32_t vj, uint32_t imm)                  \
 {                                                                          \
-    int i;                                                                 \
+    int i, max;                                                            \
+    VReg temp;                                                             \
     VReg *Vd = &(env->fpr[vd].vreg);                                       \
     VReg *Vj = &(env->fpr[vj].vreg);                                       \
-    VReg *Vk = &(env->fpr[vk].vreg);                                       \
                                                                            \
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                    \
-        Vd->E1(i) = do_ssrarnu_ ## E1(Vj->E2(i), (T)Vk->E2(i)%BIT, BIT/2); \
+    max = LSX_LEN / BIT;                                                   \
+    for (i = 0; i < max; i++) {                                            \
+        temp.E1(i) = do_ssrlrns_ ## E1(Vj->E2(i), imm, BIT / 2 - 1);       \
+        temp.E1(i + max) = do_ssrlrns_ ## E1(Vd->E2(i), imm, BIT / 2 - 1); \
+        if (oprsz == 32) {                                                 \
+            temp.E1(i + max * 2) = do_ssrlrns_ ## E1(Vj->E2(i + max),      \
+                                                     imm, BIT / 2 - 1);    \
+            temp.E1(i + max * 3) = do_ssrlrns_ ## E1(Vd->E2(i + max),      \
+                                                     imm, BIT / 2 - 1);    \
+        }                                                                  \
     }                                                                      \
-    Vd->D(1) = 0;                                                          \
+    *Vd = temp;                                                            \
 }
 
-VSSRARNU(vssrarn_bu_h, 16, uint16_t, B, H)
-VSSRARNU(vssrarn_hu_w, 32, uint32_t, H, W)
-VSSRARNU(vssrarn_wu_d, 64, uint64_t, W, D)
-
-#define VSSRLRNI(NAME, BIT, E1, E2)                                            
\
-void HELPER(NAME)(CPULoongArchState *env,                                      
\
-                  uint32_t vd, uint32_t vj, uint32_t imm)                      
\
-{                                                                              
\
-    int i;                                                                     
\
-    VReg temp;                                                                 
\
-    VReg *Vd = &(env->fpr[vd].vreg);                                           
\
-    VReg *Vj = &(env->fpr[vj].vreg);                                           
\
-                                                                               
\
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                        
\
-        temp.E1(i) = do_ssrlrns_ ## E1(Vj->E2(i), imm, BIT/2 -1);              
\
-        temp.E1(i + LSX_LEN/BIT) = do_ssrlrns_ ## E1(Vd->E2(i), imm, BIT/2 
-1);\
-    }                                                                          
\
-    *Vd = temp;                                                                
\
+#define VSSRLRNI_Q(NAME, sh)                                                \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,                   \
+                          uint32_t vd, uint32_t vj, uint32_t imm)           \
+{                                                                           \
+    int i, j, max;                                                          \
+    Int128 shft_res[4], mask, r[4];                                         \
+    VReg *Vd = &(env->fpr[vd].vreg);                                        \
+    VReg *Vj = &(env->fpr[vj].vreg);                                        \
+                                                                            \
+    mask = int128_sub(int128_lshift(int128_one(), sh), int128_one());       \
+    max = (oprsz == 16) ? 1 : 2;                                            \
+                                                                            \
+    for (i = 0; i < max; i++) {                                             \
+        if (imm == 0) {                                                     \
+            shft_res[2 * i] = Vj->Q(i);                                     \
+            shft_res[2 * i + 1] = Vd->Q(i);                                 \
+        } else {                                                            \
+            r[2 * i] = int128_and(int128_urshift(Vj->Q(i),  (imm - 1)),     \
+                                  int128_one());                            \
+            r[2 * i + 1] = int128_and(int128_urshift(Vd->Q(i), (imm - 1)),  \
+                                      int128_one());                        \
+            shft_res[2 * i] = int128_add(int128_urshift(Vj->Q(i), imm),     \
+                                         r[2 * i]);                         \
+            shft_res[2 * i + 1] = int128_add(int128_urshift(Vd->Q(i), imm), \
+                                             r[2 * i + 1]);                 \
+        }                                                                   \
+        for (j = 2 * i; j <= 2 * i + 1; j++) {                              \
+            if (int128_ult(mask, shft_res[j])) {                            \
+                Vd->D(j) = int128_getlo(mask);                              \
+            }else {                                                         \
+                Vd->D(j) = int128_getlo(shft_res[j]);                       \
+            }                                                               \
+        }                                                                   \
+    }                                                                       \
 }
 
-#define VSSRLRNI_Q(NAME, sh)                                               \
-void HELPER(NAME)(CPULoongArchState *env,                                  \
-                          uint32_t vd, uint32_t vj, uint32_t imm)          \
+VSSRLRNI(vssrlrni_b_h, 16, B, H)
+VSSRLRNI(vssrlrni_h_w, 32, H, W)
+VSSRLRNI(vssrlrni_w_d, 64, W, D)
+VSSRLRNI_Q(vssrlrni_d_q, 63)
+
+#define VSSRARNI(NAME, BIT, E1, E2)                                        \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,                  \
+                  uint32_t vd, uint32_t vj, uint32_t imm)                  \
 {                                                                          \
-    Int128 shft_res1, shft_res2, mask, r1, r2;                             \
+    int i, max;                                                            \
+    VReg temp;                                                             \
     VReg *Vd = &(env->fpr[vd].vreg);                                       \
     VReg *Vj = &(env->fpr[vj].vreg);                                       \
                                                                            \
-    if (imm == 0) {                                                        \
-        shft_res1 = Vj->Q(0);                                              \
-        shft_res2 = Vd->Q(0);                                              \
-    } else {                                                               \
-        r1 = int128_and(int128_urshift(Vj->Q(0), (imm -1)), int128_one()); \
-        r2 = int128_and(int128_urshift(Vd->Q(0), (imm -1)), int128_one()); \
-                                                                           \
-        shft_res1 = (int128_add(int128_urshift(Vj->Q(0), imm), r1));       \
-        shft_res2 = (int128_add(int128_urshift(Vd->Q(0), imm), r2));       \
-    }                                                                      \
-                                                                           \
-    mask = int128_sub(int128_lshift(int128_one(), sh), int128_one());      \
-                                                                           \
-    if (int128_ult(mask, shft_res1)) {                                     \
-        Vd->D(0) = int128_getlo(mask);                                     \
-    }else {                                                                \
-        Vd->D(0) = int128_getlo(shft_res1);                                \
-    }                                                                      \
-                                                                           \
-    if (int128_ult(mask, shft_res2)) {                                     \
-        Vd->D(1) = int128_getlo(mask);                                     \
-    }else {                                                                \
-        Vd->D(1) = int128_getlo(shft_res2);                                \
+    max = LSX_LEN / BIT;                                                   \
+    for (i = 0; i < max; i++) {                                            \
+        temp.E1(i) = do_ssrarns_ ## E1(Vj->E2(i), imm, BIT / 2 - 1);       \
+        temp.E1(i + max) = do_ssrarns_ ## E1(Vd->E2(i), imm, BIT / 2 - 1); \
+        if (oprsz == 32) {                                                 \
+            temp.E1(i + max * 2) = do_ssrarns_ ## E1(Vj->E2(i + max),      \
+                                                     imm, BIT / 2 - 1);    \
+            temp.E1(i + max * 3) = do_ssrarns_ ## E1(Vd->E2(i + max),      \
+                                                     imm, BIT / 2 - 1);    \
+        }                                                                  \
     }                                                                      \
+    *Vd = temp;                                                            \
 }
 
-VSSRLRNI(vssrlrni_b_h, 16, B, H)
-VSSRLRNI(vssrlrni_h_w, 32, H, W)
-VSSRLRNI(vssrlrni_w_d, 64, W, D)
-VSSRLRNI_Q(vssrlrni_d_q, 63)
-
-#define VSSRARNI(NAME, BIT, E1, E2)                                            
 \
-void HELPER(NAME)(CPULoongArchState *env,                                      
 \
-                  uint32_t vd, uint32_t vj, uint32_t imm)                      
 \
-{                                                                              
 \
-    int i;                                                                     
 \
-    VReg temp;                                                                 
 \
-    VReg *Vd = &(env->fpr[vd].vreg);                                           
 \
-    VReg *Vj = &(env->fpr[vj].vreg);                                           
 \
-                                                                               
 \
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                        
 \
-        temp.E1(i) = do_ssrarns_ ## E1(Vj->E2(i), imm, BIT/2 -1);              
 \
-        temp.E1(i + LSX_LEN/BIT) = do_ssrarns_ ## E1(Vd->E2(i), imm, BIT/2 
-1); \
-    }                                                                          
 \
-    *Vd = temp;                                                                
 \
-}
-
-void HELPER(vssrarni_d_q)(CPULoongArchState *env,
+void HELPER(vssrarni_d_q)(CPULoongArchState *env, uint32_t oprsz,
                           uint32_t vd, uint32_t vj, uint32_t imm)
 {
-    Int128 shft_res1, shft_res2, mask1, mask2, r1, r2;
+    int i, j, max;
+    Int128 shft_res[4], mask1, mask2, r[4];
     VReg *Vd = &(env->fpr[vd].vreg);
     VReg *Vj = &(env->fpr[vj].vreg);
 
-    if (imm == 0) {
-        shft_res1 = Vj->Q(0);
-        shft_res2 = Vd->Q(0);
-    } else {
-        r1 = int128_and(int128_rshift(Vj->Q(0), (imm -1)), int128_one());
-        r2 = int128_and(int128_rshift(Vd->Q(0), (imm -1)), int128_one());
-
-        shft_res1 = int128_add(int128_rshift(Vj->Q(0), imm), r1);
-        shft_res2 = int128_add(int128_rshift(Vd->Q(0), imm), r2);
-    }
-
     mask1 = int128_sub(int128_lshift(int128_one(), 63), int128_one());
     mask2  = int128_lshift(int128_one(), 63);
+    max = (oprsz == 16) ? 1 : 2;
 
-    if (int128_gt(shft_res1,  mask1)) {
-        Vd->D(0) = int128_getlo(mask1);
-    } else if (int128_lt(shft_res1, int128_neg(mask2))) {
-        Vd->D(0) = int128_getlo(mask2);
-    } else {
-        Vd->D(0) = int128_getlo(shft_res1);
-    }
-
-    if (int128_gt(shft_res2, mask1)) {
-        Vd->D(1) = int128_getlo(mask1);
-    } else if (int128_lt(shft_res2, int128_neg(mask2))) {
-        Vd->D(1) = int128_getlo(mask2);
-    } else {
-        Vd->D(1) = int128_getlo(shft_res2);
+    for (i = 0; i < max; i++) {
+        if (imm == 0) {
+            shft_res[2 * i] = Vj->Q(i);
+            shft_res[2 * i + 1] = Vd->Q(i);
+        } else {
+            r[2 * i] = int128_and(int128_rshift(Vj->Q(i), (imm - 1)),
+                                  int128_one());
+            r[2 * i + 1] = int128_and(int128_rshift(Vd->Q(i), (imm - 1)),
+                                      int128_one());
+            shft_res[2 * i] = int128_add(int128_rshift(Vj->Q(i), imm),
+                                         r[2 * i]);
+            shft_res[2 * i + 1] = int128_add(int128_rshift(Vd->Q(i), imm),
+                                             r[2 * i + 1]);
+        }
+        for (j = 2 * i; j <= 2 * i + 1; j++) {
+            if (int128_gt(shft_res[j], mask1)) {
+                Vd->D(j) = int128_getlo(mask1);
+            } else if (int128_lt(shft_res[j], int128_neg(mask2))) {
+                Vd->D(j) = int128_getlo(mask2);
+            } else {
+                Vd->D(j) = int128_getlo(shft_res[j]);
+            }
+        }
     }
 }
 
@@ -2140,20 +2193,27 @@ VSSRARNI(vssrarni_b_h, 16, B, H)
 VSSRARNI(vssrarni_h_w, 32, H, W)
 VSSRARNI(vssrarni_w_d, 64, W, D)
 
-#define VSSRLRNUI(NAME, BIT, E1, E2)                                         \
-void HELPER(NAME)(CPULoongArchState *env,                                    \
-                  uint32_t vd, uint32_t vj, uint32_t imm)                    \
-{                                                                            \
-    int i;                                                                   \
-    VReg temp;                                                               \
-    VReg *Vd = &(env->fpr[vd].vreg);                                         \
-    VReg *Vj = &(env->fpr[vj].vreg);                                         \
-                                                                             \
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                      \
-        temp.E1(i) = do_ssrlrnu_ ## E1(Vj->E2(i), imm, BIT/2);               \
-        temp.E1(i + LSX_LEN/BIT) = do_ssrlrnu_ ## E1(Vd->E2(i), imm, BIT/2); \
-    }                                                                        \
-    *Vd = temp;                                                              \
+#define VSSRLRNUI(NAME, BIT, E1, E2)                                   \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,              \
+                  uint32_t vd, uint32_t vj, uint32_t imm)              \
+{                                                                      \
+    int i, max;                                                        \
+    VReg temp;                                                         \
+    VReg *Vd = &(env->fpr[vd].vreg);                                   \
+    VReg *Vj = &(env->fpr[vj].vreg);                                   \
+                                                                       \
+    max = LSX_LEN / BIT;                                               \
+    for (i = 0; i < max; i++) {                                        \
+        temp.E1(i) = do_ssrlrnu_ ## E1(Vj->E2(i), imm, BIT / 2);       \
+        temp.E1(i + max) = do_ssrlrnu_ ## E1(Vd->E2(i), imm, BIT / 2); \
+        if (oprsz == 32) {                                             \
+            temp.E1(i + max * 2) = do_ssrlrnu_ ## E1(Vj->E2(i + max),  \
+                                                     imm, BIT / 2);    \
+            temp.E1(i + max * 3) = do_ssrlrnu_ ## E1(Vd->E2(i + max),  \
+                                                     imm, BIT / 2);    \
+        }                                                              \
+    }                                                                  \
+    *Vd = temp;                                                        \
 }
 
 VSSRLRNUI(vssrlrni_bu_h, 16, B, H)
@@ -2161,64 +2221,70 @@ VSSRLRNUI(vssrlrni_hu_w, 32, H, W)
 VSSRLRNUI(vssrlrni_wu_d, 64, W, D)
 VSSRLRNI_Q(vssrlrni_du_q, 64)
 
-#define VSSRARNUI(NAME, BIT, E1, E2)                                         \
-void HELPER(NAME)(CPULoongArchState *env,                                    \
-                  uint32_t vd, uint32_t vj, uint32_t imm)                    \
-{                                                                            \
-    int i;                                                                   \
-    VReg temp;                                                               \
-    VReg *Vd = &(env->fpr[vd].vreg);                                         \
-    VReg *Vj = &(env->fpr[vj].vreg);                                         \
-                                                                             \
-    for (i = 0; i < LSX_LEN/BIT; i++) {                                      \
-        temp.E1(i) = do_ssrarnu_ ## E1(Vj->E2(i), imm, BIT/2);               \
-        temp.E1(i + LSX_LEN/BIT) = do_ssrarnu_ ## E1(Vd->E2(i), imm, BIT/2); \
-    }                                                                        \
-    *Vd = temp;                                                              \
+#define VSSRARNUI(NAME, BIT, E1, E2)                                   \
+void HELPER(NAME)(CPULoongArchState *env, uint32_t oprsz,              \
+                  uint32_t vd, uint32_t vj, uint32_t imm)              \
+{                                                                      \
+    int i, max;                                                        \
+    VReg temp;                                                         \
+    VReg *Vd = &(env->fpr[vd].vreg);                                   \
+    VReg *Vj = &(env->fpr[vj].vreg);                                   \
+                                                                       \
+    max = LSX_LEN / BIT;                                               \
+    for (i = 0; i < max; i++) {                                        \
+        temp.E1(i) = do_ssrarnu_ ## E1(Vj->E2(i), imm, BIT / 2);       \
+        temp.E1(i + max) = do_ssrarnu_ ## E1(Vd->E2(i), imm, BIT / 2); \
+        if (oprsz == 32) {                                             \
+            temp.E1(i + max * 2) = do_ssrarnu_ ## E1(Vj->E2(i + max),  \
+                                                     imm, BIT / 2);    \
+            temp.E1(i + max * 3) = do_ssrarnu_ ## E1(Vd->E2(i + max),  \
+                                                     imm, BIT / 2);    \
+        }                                                              \
+    }                                                                  \
+    *Vd = temp;                                                        \
 }
 
-void HELPER(vssrarni_du_q)(CPULoongArchState *env,
+void HELPER(vssrarni_du_q)(CPULoongArchState *env, uint32_t oprsz,
                            uint32_t vd, uint32_t vj, uint32_t imm)
 {
-    Int128 shft_res1, shft_res2, mask1, mask2, r1, r2;
+    int i, j, max;
+    Int128 shft_res[4], mask1, mask2, r[4];
     VReg *Vd = &(env->fpr[vd].vreg);
     VReg *Vj = &(env->fpr[vj].vreg);
 
-    if (imm == 0) {
-        shft_res1 = Vj->Q(0);
-        shft_res2 = Vd->Q(0);
-    } else {
-        r1 = int128_and(int128_rshift(Vj->Q(0), (imm -1)), int128_one());
-        r2 = int128_and(int128_rshift(Vd->Q(0), (imm -1)), int128_one());
-
-        shft_res1 = int128_add(int128_rshift(Vj->Q(0), imm), r1);
-        shft_res2 = int128_add(int128_rshift(Vd->Q(0), imm), r2);
-    }
-
-    if (int128_lt(Vj->Q(0), int128_zero())) {
-        shft_res1 = int128_zero();
-    }
-    if (int128_lt(Vd->Q(0), int128_zero())) {
-        shft_res2 = int128_zero();
-    }
-
     mask1 = int128_sub(int128_lshift(int128_one(), 64), int128_one());
     mask2  = int128_lshift(int128_one(), 64);
+    max = (oprsz == 16) ? 1 : 2;
 
-    if (int128_gt(shft_res1,  mask1)) {
-        Vd->D(0) = int128_getlo(mask1);
-    } else if (int128_lt(shft_res1, int128_neg(mask2))) {
-        Vd->D(0) = int128_getlo(mask2);
-    } else {
-        Vd->D(0) = int128_getlo(shft_res1);
-    }
-
-    if (int128_gt(shft_res2, mask1)) {
-        Vd->D(1) = int128_getlo(mask1);
-    } else if (int128_lt(shft_res2, int128_neg(mask2))) {
-        Vd->D(1) = int128_getlo(mask2);
-    } else {
-        Vd->D(1) = int128_getlo(shft_res2);
+    for (i = 0; i < max; i++) {
+        if (imm == 0) {
+            shft_res[2 * i] = Vj->Q(i);
+            shft_res[2 * i + 1] = Vd->Q(i);
+        } else {
+            r[2 * i] = int128_and(int128_rshift(Vj->Q(i), (imm - 1)),
+                                  int128_one());
+            r[2 * i + 1] = int128_and(int128_rshift(Vd->Q(i), (imm - 1)),
+                                      int128_one());
+            shft_res[2 * i] = int128_add(int128_rshift(Vj->Q(i), imm),
+                                          r[2 * i]);
+            shft_res[2 * i + 1] = int128_add(int128_rshift(Vd->Q(i), imm),
+                                             r[2 * i + 1]);
+        }
+        if (int128_lt(Vj->Q(i), int128_zero())) {
+            shft_res[2 * i] = int128_zero();
+        }
+        if (int128_lt(Vd->Q(i), int128_zero())) {
+            shft_res[2 * i + 1] = int128_zero();
+        }
+        for (j = 2 * i; j <= 2 * i + 1; j++) {
+            if (int128_gt(shft_res[j], mask1)) {
+                Vd->D(j) = int128_getlo(mask1);
+            } else if (int128_lt(shft_res[j], int128_neg(mask2))) {
+                Vd->D(j) = int128_getlo(mask2);
+            } else {
+                Vd->D(j) = int128_getlo(shft_res[j]);
+            }
+        }
     }
 }
 
-- 
2.39.1




reply via email to

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