All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiaojuan Yang <yangxiaojuan@loongson.cn>
To: qemu-devel@nongnu.org
Cc: richard.henderson@linaro.org, gaosong@loongson.cn,
	mark.cave-ayland@ilande.co.uk, mst@redhat.com,
	imammedo@redhat.com, ani@anisinha.ca
Subject: [PATCH v5 09/43] target/loongarch: Add fixed point extra instruction translation
Date: Tue, 24 May 2022 16:17:30 +0800	[thread overview]
Message-ID: <20220524081804.3608101-10-yangxiaojuan@loongson.cn> (raw)
In-Reply-To: <20220524081804.3608101-1-yangxiaojuan@loongson.cn>

From: Song Gao <gaosong@loongson.cn>

This includes:
- CRC[C].W.{B/H/W/D}.W
- SYSCALL
- BREAK
- ASRT{LE/GT}.D
- RDTIME{L/H}.W, RDTIME.D
- CPUCFG

Signed-off-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/loongarch/helper.h                     |  4 ++
 target/loongarch/insn_trans/trans_extra.c.inc | 68 +++++++++++++++++++
 target/loongarch/insns.decode                 | 19 ++++++
 target/loongarch/op_helper.c                  | 26 +++++++
 target/loongarch/translate.c                  |  1 +
 5 files changed, 118 insertions(+)
 create mode 100644 target/loongarch/insn_trans/trans_extra.c.inc

diff --git a/target/loongarch/helper.h b/target/loongarch/helper.h
index 100622bfc2..638c2efc51 100644
--- a/target/loongarch/helper.h
+++ b/target/loongarch/helper.h
@@ -11,3 +11,7 @@ DEF_HELPER_FLAGS_1(bitswap, TCG_CALL_NO_RWG_SE, tl, tl)
 
 DEF_HELPER_FLAGS_3(asrtle_d, TCG_CALL_NO_WG, void, env, tl, tl)
 DEF_HELPER_FLAGS_3(asrtgt_d, TCG_CALL_NO_WG, void, env, tl, tl)
+
+DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl)
+DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl)
+DEF_HELPER_FLAGS_2(cpucfg, TCG_CALL_NO_RWG_SE, tl, env, tl)
diff --git a/target/loongarch/insn_trans/trans_extra.c.inc b/target/loongarch/insn_trans/trans_extra.c.inc
new file mode 100644
index 0000000000..549f75a867
--- /dev/null
+++ b/target/loongarch/insn_trans/trans_extra.c.inc
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ */
+
+static bool trans_break(DisasContext *ctx, arg_break *a)
+{
+    generate_exception(ctx, EXCCODE_BRK);
+    return true;
+}
+
+static bool trans_syscall(DisasContext *ctx, arg_syscall *a)
+{
+    generate_exception(ctx, EXCCODE_SYS);
+    return true;
+}
+
+static bool trans_asrtle_d(DisasContext *ctx, arg_asrtle_d * a)
+{
+    TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
+    TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
+
+    gen_helper_asrtle_d(cpu_env, src1, src2);
+    return true;
+}
+
+static bool trans_asrtgt_d(DisasContext *ctx, arg_asrtgt_d * a)
+{
+    TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
+    TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
+
+    gen_helper_asrtgt_d(cpu_env, src1, src2);
+    return true;
+}
+
+static bool trans_cpucfg(DisasContext *ctx, arg_cpucfg *a)
+{
+    TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
+    TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
+
+    gen_helper_cpucfg(dest, cpu_env, src1);
+    gen_set_gpr(a->rd, dest, EXT_NONE);
+
+    return true;
+}
+
+static bool gen_crc(DisasContext *ctx, arg_rrr *a,
+                    void (*func)(TCGv, TCGv, TCGv, TCGv),
+                    TCGv tsz)
+{
+    TCGv dest = gpr_dst(ctx, a->rd, EXT_SIGN);
+    TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
+    TCGv src2 = gpr_src(ctx, a->rk, EXT_NONE);
+
+    func(dest, src2, src1, tsz);
+    gen_set_gpr(a->rd, dest, EXT_SIGN);
+
+    return true;
+}
+
+TRANS(crc_w_b_w, gen_crc, gen_helper_crc32, tcg_constant_tl(1))
+TRANS(crc_w_h_w, gen_crc, gen_helper_crc32, tcg_constant_tl(2))
+TRANS(crc_w_w_w, gen_crc, gen_helper_crc32, tcg_constant_tl(4))
+TRANS(crc_w_d_w, gen_crc, gen_helper_crc32, tcg_constant_tl(8))
+TRANS(crcc_w_b_w, gen_crc, gen_helper_crc32c, tcg_constant_tl(1))
+TRANS(crcc_w_h_w, gen_crc, gen_helper_crc32c, tcg_constant_tl(2))
+TRANS(crcc_w_w_w, gen_crc, gen_helper_crc32c, tcg_constant_tl(4))
+TRANS(crcc_w_d_w, gen_crc, gen_helper_crc32c, tcg_constant_tl(8))
diff --git a/target/loongarch/insns.decode b/target/loongarch/insns.decode
index 8d247aa68c..98774dbddb 100644
--- a/target/loongarch/insns.decode
+++ b/target/loongarch/insns.decode
@@ -17,6 +17,7 @@
 &i            imm
 &r_i          rd imm
 &rr           rd rj
+&rr_jk        rj rk
 &rrr          rd rj rk
 &rr_i         rd rj imm
 &hint_r_i     hint rj imm
@@ -28,6 +29,7 @@
 #
 @i15                       .... ........ ..... imm:15    &i
 @rr               .... ........ ..... ..... rj:5 rd:5    &rr
+@rr_jk            .... ........ ..... rk:5 rj:5 .....    &rr_jk
 @rrr               .... ........ ..... rk:5 rj:5 rd:5    &rrr
 @r_i20                          .... ... imm:s20 rd:5    &r_i
 @rr_ui5           .... ........ ..... imm:5 rj:5 rd:5    &rr_i
@@ -237,3 +239,20 @@ ammax_db_wu     0011 10000111 00000 ..... ..... .....    @rrr
 ammax_db_du     0011 10000111 00001 ..... ..... .....    @rrr
 ammin_db_wu     0011 10000111 00010 ..... ..... .....    @rrr
 ammin_db_du     0011 10000111 00011 ..... ..... .....    @rrr
+
+#
+# Fixed point extra instruction
+#
+crc_w_b_w       0000 00000010 01000 ..... ..... .....    @rrr
+crc_w_h_w       0000 00000010 01001 ..... ..... .....    @rrr
+crc_w_w_w       0000 00000010 01010 ..... ..... .....    @rrr
+crc_w_d_w       0000 00000010 01011 ..... ..... .....    @rrr
+crcc_w_b_w      0000 00000010 01100 ..... ..... .....    @rrr
+crcc_w_h_w      0000 00000010 01101 ..... ..... .....    @rrr
+crcc_w_w_w      0000 00000010 01110 ..... ..... .....    @rrr
+crcc_w_d_w      0000 00000010 01111 ..... ..... .....    @rrr
+break           0000 00000010 10100 ...............      @i15
+syscall         0000 00000010 10110 ...............      @i15
+asrtle_d        0000 00000000 00010 ..... ..... 00000    @rr_jk
+asrtgt_d        0000 00000000 00011 ..... ..... 00000    @rr_jk
+cpucfg          0000 00000000 00000 11011 ..... .....    @rr
diff --git a/target/loongarch/op_helper.c b/target/loongarch/op_helper.c
index bd2db783c9..18e565ce7f 100644
--- a/target/loongarch/op_helper.c
+++ b/target/loongarch/op_helper.c
@@ -13,6 +13,8 @@
 #include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
 #include "internals.h"
+#include "qemu/crc32c.h"
+#include <zlib.h>
 
 /* Exceptions helpers */
 void helper_raise_exception(CPULoongArchState *env, uint32_t exception)
@@ -55,3 +57,27 @@ void helper_asrtgt_d(CPULoongArchState *env, target_ulong rj, target_ulong rk)
         do_raise_exception(env, EXCCODE_ADEM, GETPC());
     }
 }
+
+target_ulong helper_crc32(target_ulong val, target_ulong m, uint64_t sz)
+{
+    uint8_t buf[8];
+    target_ulong mask = ((sz * 8) == 64) ? -1ULL : ((1ULL << (sz * 8)) - 1);
+
+    m &= mask;
+    stq_le_p(buf, m);
+    return (int32_t) (crc32(val ^ 0xffffffff, buf, sz) ^ 0xffffffff);
+}
+
+target_ulong helper_crc32c(target_ulong val, target_ulong m, uint64_t sz)
+{
+    uint8_t buf[8];
+    target_ulong mask = ((sz * 8) == 64) ? -1ULL : ((1ULL << (sz * 8)) - 1);
+    m &= mask;
+    stq_le_p(buf, m);
+    return (int32_t) (crc32c(val, buf, sz) ^ 0xffffffff);
+}
+
+target_ulong helper_cpucfg(CPULoongArchState *env, target_ulong rj)
+{
+    return rj > 21 ? 0 : env->cpucfg[rj];
+}
diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c
index 7118e6c17d..5baeb74afa 100644
--- a/target/loongarch/translate.c
+++ b/target/loongarch/translate.c
@@ -155,6 +155,7 @@ static void gen_set_gpr(int reg_num, TCGv t, DisasExtend dst_ext)
 #include "insn_trans/trans_bit.c.inc"
 #include "insn_trans/trans_memory.c.inc"
 #include "insn_trans/trans_atomic.c.inc"
+#include "insn_trans/trans_extra.c.inc"
 
 static void loongarch_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
 {
-- 
2.31.1



  parent reply	other threads:[~2022-05-24  9:31 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24  8:17 [PATCH v5 00/43] Add LoongArch softmmu support Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 01/43] target/loongarch: Add README Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 02/43] target/loongarch: Add core definition Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 03/43] target/loongarch: Add main translation routines Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 04/43] target/loongarch: Add fixed point arithmetic instruction translation Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 05/43] target/loongarch: Add fixed point shift " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 06/43] target/loongarch: Add fixed point bit " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 07/43] target/loongarch: Add fixed point load/store " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 08/43] target/loongarch: Add fixed point atomic " Xiaojuan Yang
2022-05-24  8:17 ` Xiaojuan Yang [this message]
2022-05-24  8:17 ` [PATCH v5 10/43] target/loongarch: Add floating point arithmetic " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 11/43] target/loongarch: Add floating point comparison " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 12/43] target/loongarch: Add floating point conversion " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 13/43] target/loongarch: Add floating point move " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 14/43] target/loongarch: Add floating point load/store " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 15/43] target/loongarch: Add branch " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 16/43] target/loongarch: Add disassembler Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 17/43] target/loongarch: Add target build suport Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 18/43] target/loongarch: Add system emulation introduction Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 19/43] target/loongarch: Add CSRs definition Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 20/43] target/loongarch: Add basic vmstate description of CPU Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 21/43] target/loongarch: Implement qmp_query_cpu_definitions() Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 22/43] target/loongarch: Add MMU support for LoongArch CPU Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 23/43] target/loongarch: Add LoongArch interrupt and exception handle Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 24/43] target/loongarch: Add constant timer support Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 25/43] target/loongarch: Add LoongArch CSR instruction Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 26/43] target/loongarch: Add LoongArch IOCSR instruction Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 27/43] target/loongarch: Add TLB instruction support Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 28/43] target/loongarch: Add other core instructions support Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 29/43] target/loongarch: Add timer related " Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 30/43] hw/loongarch: Add support loongson3 virt machine type Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 31/43] hw/loongarch: Add LoongArch ipi interrupt support(IPI) Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 32/43] hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC) Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 33/43] hw/intc: Add LoongArch ls7a msi interrupt controller support(PCH-MSI) Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 34/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC) Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 35/43] hw/loongarch: Add irq hierarchy for the system Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 36/43] Enable common virtio pci support for LoongArch Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 37/43] hw/loongarch: Add some devices support for 3A5000 Xiaojuan Yang
2022-05-24  8:17 ` [PATCH v5 38/43] hw/loongarch: Add LoongArch ls7a rtc device support Xiaojuan Yang
2022-05-24  8:18 ` [PATCH v5 39/43] hw/loongarch: Add LoongArch load elf function Xiaojuan Yang
2022-05-24  8:18 ` [PATCH v5 40/43] hw/loongarch: Add LoongArch ls7a acpi device support Xiaojuan Yang
2022-05-26  8:42   ` Igor Mammedov
2022-05-26 22:18     ` maobibo
2022-05-30 10:21       ` Igor Mammedov
2022-05-31  3:43         ` maobibo
2022-05-24  8:18 ` [PATCH v5 41/43] target/loongarch: Add gdb support Xiaojuan Yang
2022-05-24  8:18 ` [PATCH v5 42/43] tests/tcg/loongarch64: Add hello/memory test in loongarch64 system Xiaojuan Yang
2022-05-24  8:18 ` [PATCH v5 43/43] target/loongarch: 'make check-tcg' support Xiaojuan Yang
2022-05-24 22:32 ` [PATCH v5 00/43] Add LoongArch softmmu support Richard Henderson
2022-05-24 22:41   ` Richard Henderson
2022-05-25  0:44     ` yangxiaojuan
2022-05-25  3:31       ` Richard Henderson
2022-05-25  0:27   ` yangxiaojuan

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=20220524081804.3608101-10-yangxiaojuan@loongson.cn \
    --to=yangxiaojuan@loongson.cn \
    --cc=ani@anisinha.ca \
    --cc=gaosong@loongson.cn \
    --cc=imammedo@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.