qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chen Gang <xili_gchen_5257@hotmail.com>
To: "Peter Maydell" <peter.maydell@linaro.org>,
	"rth@twiddle.net" <rth@twiddle.net>,
	"Chris Metcalf" <cmetcalf@ezchip.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"walt@tilera.com" <walt@tilera.com>,
	"Riku Voipio" <riku.voipio@iki.fi>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] [PATCH 08/16 v1] target-tilegx: Add several helpers for instructions translation
Date: Fri, 21 Aug 2015 05:41:51 +0800	[thread overview]
Message-ID: <BLU436-SMTP83F96FD8422BE49AFDC9DFB9660@phx.gbl> (raw)
In-Reply-To: <BLU436-SMTP1272239F6C920D8BF101ACAB9660@phx.gbl>

The related instructions are exception, cntlz, cnttz, shufflebytes, and
add_saturate.

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 target-tilegx/helper.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++
 target-tilegx/helper.h |  5 +++
 2 files changed, 88 insertions(+)
 create mode 100644 target-tilegx/helper.c
 create mode 100644 target-tilegx/helper.h

diff --git a/target-tilegx/helper.c b/target-tilegx/helper.c
new file mode 100644
index 0000000..5ab41cd
--- /dev/null
+++ b/target-tilegx/helper.c
@@ -0,0 +1,83 @@
+/*
+ * QEMU TILE-Gx helpers
+ *
+ *  Copyright (c) 2015 Chen Gang
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+#include "cpu.h"
+#include "qemu-common.h"
+#include "exec/helper-proto.h"
+
+#define SIGNBIT32 0x80000000
+
+int64_t helper_add_saturate(CPUTLGState *env, uint64_t rsrc, uint64_t rsrcb)
+{
+    uint32_t rdst = rsrc + rsrcb;
+
+    if (((rdst ^ rsrc) & SIGNBIT32) && !((rsrc ^ rsrcb) & SIGNBIT32)) {
+        rdst = ~(((int32_t)rsrc >> 31) ^ SIGNBIT32);
+    }
+
+    return (int64_t)rdst;
+}
+
+void helper_exception(CPUTLGState *env, uint32_t excp)
+{
+    CPUState *cs = CPU(tilegx_env_get_cpu(env));
+
+    cs->exception_index = excp;
+    cpu_loop_exit(cs);
+}
+
+uint64_t helper_cntlz(uint64_t arg)
+{
+    return clz64(arg);
+}
+
+uint64_t helper_cnttz(uint64_t arg)
+{
+    return ctz64(arg);
+}
+
+/*
+ * Functional Description
+ *     uint64_t a = rf[SrcA];
+ *     uint64_t b = rf[SrcB];
+ *     uint64_t d = rf[Dest];
+ *     uint64_t output = 0;
+ *     unsigned int counter;
+ *     for (counter = 0; counter < (WORD_SIZE / BYTE_SIZE); counter++)
+ *     {
+ *         int sel = getByte (b, counter) & 0xf;
+ *         uint8_t byte = (sel < 8) ? getByte (d, sel) : getByte (a, (sel - 8));
+ *         output = setByte (output, counter, byte);
+ *     }
+ *     rf[Dest] = output;
+ */
+uint64_t helper_shufflebytes(uint64_t rdst, uint64_t rsrc, uint64_t rsrcb)
+{
+    uint64_t vdst = 0;
+    int count;
+
+    for (count = 0; count < 64; count += 8) {
+        uint64_t sel = rsrcb >> count;
+        uint64_t src = (sel & 8) ? rsrc : rdst;
+        vdst |= ((src >> ((sel & 7) * 8)) & 0xff) << count;
+    }
+
+    return vdst;
+}
diff --git a/target-tilegx/helper.h b/target-tilegx/helper.h
new file mode 100644
index 0000000..1411c19
--- /dev/null
+++ b/target-tilegx/helper.h
@@ -0,0 +1,5 @@
+DEF_HELPER_2(exception, noreturn, env, i32)
+DEF_HELPER_FLAGS_1(cntlz, TCG_CALL_NO_RWG_SE, i64, i64)
+DEF_HELPER_FLAGS_1(cnttz, TCG_CALL_NO_RWG_SE, i64, i64)
+DEF_HELPER_FLAGS_3(shufflebytes, TCG_CALL_NO_RWG_SE, i64, i64, i64, i64)
+DEF_HELPER_3(add_saturate, s64, env, i64, i64)
-- 
1.9.3

  parent reply	other threads:[~2015-08-20 21:40 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <55D608BF.4050806@hotmail.com>
2015-08-20 17:04 ` [Qemu-devel] [PATCH 00/16] tilegx: Firstly add tilegx target for linux-user gchen gchen
     [not found]   ` <55D609D2.9050309@hotmail.com>
2015-08-20 17:09     ` [Qemu-devel] Subject: [PATCH 01/16] linux-user: tilegx: Firstly add architecture related features gchen gchen
2015-08-21  6:30       ` Eric Blake
2015-08-21  6:38         ` Eric Blake
     [not found]           ` <55D79D6C.9020001@hotmail.com>
2015-08-21 21:51             ` gchen gchen
     [not found]   ` <55D60A0A.5010802@hotmail.com>
2015-08-20 17:12     ` [Qemu-devel] [PATCH 02/16] linux-user: Support tilegx architecture in linux-user gchen gchen
     [not found]   ` <55D60B31.6010001@hotmail.com>
2015-08-20 17:14     ` [Qemu-devel] [PATCH 03/16] linux-user/syscall.c: conditionalize syscalls which are not defined in tilegx gchen gchen
     [not found]   ` <55D60BB3.6000005@hotmail.com>
2015-08-20 17:16     ` [Qemu-devel] [PATCH 04/16] target-tilegx: Add opcode basic implementation from Tilera Corporation gchen gchen
     [not found]   ` <55D60C1A.5030206@hotmail.com>
2015-08-20 17:18     ` [Qemu-devel] [PATCH 05/16] target-tilegx/opcode_tilegx.h: Modify it to fit QEMU usage gchen gchen
     [not found]   ` <55D60C72.1050003@hotmail.com>
2015-08-20 17:19     ` [Qemu-devel] [PATCH 06/16] target-tilegx: Add special register information from Tilera Corporation gchen gchen
     [not found]   ` <55D60CD0.3070605@hotmail.com>
2015-08-20 17:21     ` [Qemu-devel] [PATCH 07/16] target-tilegx: Add cpu basic features for linux-user gchen gchen
     [not found]   ` <55D60D32.2030705@hotmail.com>
2015-08-20 17:22     ` [Qemu-devel] [PATCH 08/16] target-tilegx: Add several helpers for instructions translation gchen gchen
     [not found]   ` <55D60DB2.3070605@hotmail.com>
2015-08-20 17:25     ` [Qemu-devel] [PATCH 09/16] target-tilegx: Generate tcg instructions to finish "Hello world" gchen gchen
     [not found]   ` <55D60F06.30008@hotmail.com>
2015-08-20 17:30     ` [Qemu-devel] [PATCH 00/16] tilegx: Firstly add tilegx target for linux-user gchen gchen
2015-08-20 21:32   ` [Qemu-devel] [PATCH 00/16 v1] " Chen Gang
2015-08-20 21:35     ` [Qemu-devel] [PATCH 01/16 v1] linux-user: tilegx: Firstly add architecture related features Chen Gang
2015-08-20 21:36     ` [Qemu-devel] [PATCH 02/16 v1] linux-user: Support tilegx architecture in linux-user Chen Gang
2015-08-20 21:37     ` [Qemu-devel] [PATCH 03/16 v1] linux-user/syscall.c: conditionalize syscalls which are not defined in tilegx Chen Gang
2015-08-20 21:38     ` [Qemu-devel] [PATCH 04/16 v1] target-tilegx: Add opcode basic implementation from Tilera Corporation Chen Gang
2015-08-20 21:39     ` [Qemu-devel] [PATCH 05/16 v1] target-tilegx/opcode_tilegx.h: Modify it to fit QEMU usage Chen Gang
2015-08-20 21:40     ` [Qemu-devel] [PATCH 06/16 v1] target-tilegx: Add special register information from Tilera Corporation Chen Gang
2015-08-20 21:41     ` [Qemu-devel] [PATCH 07/16 v1] target-tilegx: Add cpu basic features for linux-user Chen Gang
2015-08-20 21:41     ` Chen Gang [this message]
2015-08-20 21:42     ` [Qemu-devel] [PATCH 09/16 v1] target-tilegx: Generate tcg instructions to finish "Hello world" Chen Gang
2015-08-20 21:44     ` [Qemu-devel] [PATCH 11/16 v1] target-tilegx: Add related feature to support iret instruction Chen Gang
2015-08-20 21:47     ` [Qemu-devel] [PATCH 14/16 v1] linux-user: main: Use negative qemu errno for syscall return errno Chen Gang
2015-08-20 21:47     ` [Qemu-devel] [PATCH 15/16 v1] tilegx: Match with the latest qemu master tree Chen Gang
2015-08-20 21:48     ` [Qemu-devel] [PATCH 16/16 v1] target-tilegx: Implement additional instructions in normal working flow Chen Gang
2015-08-21  5:15     ` [Qemu-devel] [PATCH 00/16 v1] tilegx: Firstly add tilegx target for linux-user Richard Henderson
     [not found]       ` <55D79810.2040902@hotmail.com>
2015-08-21 21:27         ` gchen gchen

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=BLU436-SMTP83F96FD8422BE49AFDC9DFB9660@phx.gbl \
    --to=xili_gchen_5257@hotmail.com \
    --cc=afaerber@suse.de \
    --cc=cmetcalf@ezchip.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    --cc=rth@twiddle.net \
    --cc=walt@tilera.com \
    /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).