qemu-devel
[Top][All Lists]
Advanced

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

[RFC PATCH 13/43] target/loongarch: Implement vadda


From: Song Gao
Subject: [RFC PATCH 13/43] target/loongarch: Implement vadda
Date: Sat, 24 Dec 2022 16:16:03 +0800

This patch includes:
- VADDA.{B/H/W/D}.

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 target/loongarch/disas.c                    |  5 ++++
 target/loongarch/helper.h                   |  5 ++++
 target/loongarch/insn_trans/trans_lsx.c.inc |  5 ++++
 target/loongarch/insns.decode               |  5 ++++
 target/loongarch/lsx_helper.c               | 32 +++++++++++++++++++++
 5 files changed, 52 insertions(+)

diff --git a/target/loongarch/disas.c b/target/loongarch/disas.c
index 8ec612446c..ff5d9e0e5b 100644
--- a/target/loongarch/disas.c
+++ b/target/loongarch/disas.c
@@ -905,3 +905,8 @@ INSN_LSX(vabsd_bu,         vvv)
 INSN_LSX(vabsd_hu,         vvv)
 INSN_LSX(vabsd_wu,         vvv)
 INSN_LSX(vabsd_du,         vvv)
+
+INSN_LSX(vadda_b,          vvv)
+INSN_LSX(vadda_h,          vvv)
+INSN_LSX(vadda_w,          vvv)
+INSN_LSX(vadda_d,          vvv)
diff --git a/target/loongarch/helper.h b/target/loongarch/helper.h
index 8298af2d40..85321c8874 100644
--- a/target/loongarch/helper.h
+++ b/target/loongarch/helper.h
@@ -259,3 +259,8 @@ DEF_HELPER_4(vabsd_bu, void, env, i32, i32, i32)
 DEF_HELPER_4(vabsd_hu, void, env, i32, i32, i32)
 DEF_HELPER_4(vabsd_wu, void, env, i32, i32, i32)
 DEF_HELPER_4(vabsd_du, void, env, i32, i32, i32)
+
+DEF_HELPER_4(vadda_b, void, env, i32, i32, i32)
+DEF_HELPER_4(vadda_h, void, env, i32, i32, i32)
+DEF_HELPER_4(vadda_w, void, env, i32, i32, i32)
+DEF_HELPER_4(vadda_d, void, env, i32, i32, i32)
diff --git a/target/loongarch/insn_trans/trans_lsx.c.inc 
b/target/loongarch/insn_trans/trans_lsx.c.inc
index 00a921a935..a90fc44ba7 100644
--- a/target/loongarch/insn_trans/trans_lsx.c.inc
+++ b/target/loongarch/insn_trans/trans_lsx.c.inc
@@ -177,3 +177,8 @@ TRANS(vabsd_bu, gen_vvv, gen_helper_vabsd_bu)
 TRANS(vabsd_hu, gen_vvv, gen_helper_vabsd_hu)
 TRANS(vabsd_wu, gen_vvv, gen_helper_vabsd_wu)
 TRANS(vabsd_du, gen_vvv, gen_helper_vabsd_du)
+
+TRANS(vadda_b, gen_vvv, gen_helper_vadda_b)
+TRANS(vadda_h, gen_vvv, gen_helper_vadda_h)
+TRANS(vadda_w, gen_vvv, gen_helper_vadda_w)
+TRANS(vadda_d, gen_vvv, gen_helper_vadda_d)
diff --git a/target/loongarch/insns.decode b/target/loongarch/insns.decode
index a770f37b99..9529ffe970 100644
--- a/target/loongarch/insns.decode
+++ b/target/loongarch/insns.decode
@@ -627,3 +627,8 @@ vabsd_bu         0111 00000110 00100 ..... ..... .....    
@vvv
 vabsd_hu         0111 00000110 00101 ..... ..... .....    @vvv
 vabsd_wu         0111 00000110 00110 ..... ..... .....    @vvv
 vabsd_du         0111 00000110 00111 ..... ..... .....    @vvv
+
+vadda_b          0111 00000101 11000 ..... ..... .....    @vvv
+vadda_h          0111 00000101 11001 ..... ..... .....    @vvv
+vadda_w          0111 00000101 11010 ..... ..... .....    @vvv
+vadda_d          0111 00000101 11011 ..... ..... .....    @vvv
diff --git a/target/loongarch/lsx_helper.c b/target/loongarch/lsx_helper.c
index 61dc92059e..a9a0b01fd7 100644
--- a/target/loongarch/lsx_helper.c
+++ b/target/loongarch/lsx_helper.c
@@ -904,3 +904,35 @@ DO_HELPER_VVV(vabsd_bu, 8, helper_vvv, do_vabsd_u)
 DO_HELPER_VVV(vabsd_hu, 16, helper_vvv, do_vabsd_u)
 DO_HELPER_VVV(vabsd_wu, 32, helper_vvv, do_vabsd_u)
 DO_HELPER_VVV(vabsd_du, 64, helper_vvv, do_vabsd_u)
+
+static int64_t vadda_s(int64_t s1, int64_t s2)
+{
+    int64_t abs_s1 = s1 >= 0 ? s1 : -s1;
+    int64_t abs_s2 = s2 >= 0 ? s2 : -s2;
+    return abs_s1 + abs_s2;
+}
+
+static void do_vadda_s(vec_t *Vd, vec_t *Vj, vec_t *Vk, int bit, int n)
+{
+    switch (bit) {
+    case 8:
+        Vd->B[n] = vadda_s(Vj->B[n], Vk->B[n]);
+        break;
+    case 16:
+        Vd->H[n] = vadda_s(Vj->H[n], Vk->H[n]);
+        break;
+    case 32:
+        Vd->W[n] = vadda_s(Vj->W[n], Vk->W[n]);
+        break;
+    case 64:
+        Vd->D[n] = vadda_s(Vj->D[n], Vk->D[n]);
+        break;
+    default:
+        g_assert_not_reached();
+    }
+}
+
+DO_HELPER_VVV(vadda_b, 8, helper_vvv, do_vadda_s)
+DO_HELPER_VVV(vadda_h, 16, helper_vvv, do_vadda_s)
+DO_HELPER_VVV(vadda_w, 32, helper_vvv, do_vadda_s)
+DO_HELPER_VVV(vadda_d, 64, helper_vvv, do_vadda_s)
-- 
2.31.1




reply via email to

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