qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
To: qemu-devel@nongnu.org
Cc: kbastian@mail.uni-paderborn.de
Subject: [PATCH 6/6] target/tricore: Add shuffle insn
Date: Sat, 10 Jun 2023 12:55:47 +0200	[thread overview]
Message-ID: <20230610105547.159148-7-kbastian@mail.uni-paderborn.de> (raw)
In-Reply-To: <20230610105547.159148-1-kbastian@mail.uni-paderborn.de>

this is mostly authored by volumit (https://github.com/volumit/qemu/)

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
---
 target/tricore/helper.h          |  1 +
 target/tricore/op_helper.c       | 48 ++++++++++++++++++++++++++++++++
 target/tricore/translate.c       |  8 ++++++
 target/tricore/tricore-opcodes.h |  1 +
 4 files changed, 58 insertions(+)

diff --git a/target/tricore/helper.h b/target/tricore/helper.h
index a10576e09e..31d71eac7a 100644
--- a/target/tricore/helper.h
+++ b/target/tricore/helper.h
@@ -134,6 +134,7 @@ DEF_HELPER_FLAGS_5(mulr_h, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32, i32, i32)
 DEF_HELPER_FLAGS_2(crc32b, TCG_CALL_NO_RWG_SE, i32, i32, i32)
 DEF_HELPER_FLAGS_2(crc32_be, TCG_CALL_NO_RWG_SE, i32, i32, i32)
 DEF_HELPER_FLAGS_2(crc32_le, TCG_CALL_NO_RWG_SE, i32, i32, i32)
+DEF_HELPER_FLAGS_2(shuffle, TCG_CALL_NO_RWG_SE, i32, i32, i32)
 /* CSA */
 DEF_HELPER_2(call, void, env, i32)
 DEF_HELPER_1(ret, void, env)
diff --git a/target/tricore/op_helper.c b/target/tricore/op_helper.c
index b6ef1462e4..bd770a2341 100644
--- a/target/tricore/op_helper.c
+++ b/target/tricore/op_helper.c
@@ -2308,6 +2308,54 @@ uint32_t helper_crc32_le(uint32_t arg0, uint32_t arg1)
     return crc32(arg1, buf, 4);
 }
 
+/*
+ * table from
+ * https://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
+ */
+static const unsigned char BitReverseTable256[256] = {
+#   define R2(n) n, n + 2 * 64, n + 1 * 64, n + 3 * 64
+#   define R4(n) R2(n), R2(n + 2 * 16), R2(n + 1 * 16), R2(n + 3 * 16)
+#   define R6(n) R4(n), R4(n + 2 * 4 ), R4(n + 1 * 4 ), R4(n + 3 * 4 )
+    R6(0), R6(2), R6(1), R6(3)
+};
+
+uint32_t helper_shuffle(uint32_t arg0, uint32_t arg1)
+{
+    uint8_t buf[4];
+    uint8_t resbuf[4];
+    uint32_t byte_select;
+    uint32_t res = 0;
+
+    stl_le_p(buf, arg0);
+
+    byte_select = arg1 & 0x3;
+    resbuf[0] = buf[byte_select];
+    if (arg1 & 0x100) {
+        resbuf[0] = BitReverseTable256[resbuf[0]];
+    }
+
+    byte_select = (arg1 >> 2) & 0x3;
+    resbuf[1] = buf[byte_select];
+    if (arg1 & 0x100) {
+        resbuf[1] = BitReverseTable256[resbuf[1]];
+    }
+
+    byte_select = (arg1 >> 4) & 0x3;
+    resbuf[2] = buf[byte_select];
+    if (arg1 & 0x100) {
+        resbuf[2] = BitReverseTable256[resbuf[2]];
+    }
+
+    byte_select = (arg1 >> 6) & 0x3;
+    resbuf[3] = buf[byte_select];
+    if (arg1 & 0x100) {
+        resbuf[3] = BitReverseTable256[resbuf[3]];
+    }
+
+    res = ldl_le_p(resbuf);
+    return res;
+}
+
 /* context save area (CSA) related helpers */
 
 static int cdc_increment(target_ulong *psw)
diff --git a/target/tricore/translate.c b/target/tricore/translate.c
index 85526ef4db..a4c60e8ae2 100644
--- a/target/tricore/translate.c
+++ b/target/tricore/translate.c
@@ -5011,6 +5011,14 @@ static void decode_rc_logical_shift(DisasContext *ctx)
     case OPC2_32_RC_XOR:
         tcg_gen_xori_tl(cpu_gpr_d[r2], cpu_gpr_d[r1], const9);
         break;
+    case OPC2_32_RC_SHUFFLE:
+        if (has_feature(ctx, TRICORE_FEATURE_162)) {
+            TCGv temp = tcg_constant_i32(const9);
+            gen_helper_shuffle(cpu_gpr_d[r2], cpu_gpr_d[r1], temp);
+        } else {
+            generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
+        }
+        break;
     default:
         generate_trap(ctx, TRAPC_INSN_ERR, TIN2_IOPC);
     }
diff --git a/target/tricore/tricore-opcodes.h b/target/tricore/tricore-opcodes.h
index 27f80e1702..af63926731 100644
--- a/target/tricore/tricore-opcodes.h
+++ b/target/tricore/tricore-opcodes.h
@@ -885,6 +885,7 @@ enum {
     OPC2_32_RC_SHAS                              = 0x02,
     OPC2_32_RC_XNOR                              = 0x0d,
     OPC2_32_RC_XOR                               = 0x0c,
+    OPC2_32_RC_SHUFFLE                           = 0x07, /* v1.6.2 only */
 };
 /* OPCM_32_RC_ACCUMULATOR                           */
 enum {
-- 
2.40.1



  parent reply	other threads:[~2023-06-10 10:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-10 10:55 [PATCH 0/6] TriCore 1.6.2 Instructions Bastian Koppelmann
2023-06-10 10:55 ` [PATCH 1/6] target/tricore: Introduce ISA 1.6.2 feature Bastian Koppelmann
2023-06-10 14:57   ` Richard Henderson
2023-06-10 10:55 ` [PATCH 2/6] target/tricore: Add popcnt.w insn Bastian Koppelmann
2023-06-10 14:58   ` Richard Henderson
2023-06-10 10:55 ` [PATCH 3/6] target/tricore: Add LHA insn Bastian Koppelmann
2023-06-10 15:14   ` Richard Henderson
2023-06-10 10:55 ` [PATCH 4/6] target/tricore: Add crc32l.w insn Bastian Koppelmann
2023-06-10 15:18   ` Richard Henderson
2023-06-10 10:55 ` [PATCH 5/6] target/tricore: Add crc32.b insn Bastian Koppelmann
2023-06-10 15:19   ` Richard Henderson
2023-06-10 10:55 ` Bastian Koppelmann [this message]
2023-06-10 15:41   ` [PATCH 6/6] target/tricore: Add shuffle insn Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230610105547.159148-7-kbastian@mail.uni-paderborn.de \
    --to=kbastian@mail.uni-paderborn.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).