All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
To: mjc@sifive.com, sagark@eecs.berkeley.edu, palmer@sifive.com,
	kbastian@mail.uni-paderborn.de
Cc: peer.adelt@hni.uni-paderborn.de, Alistair.Francis@wdc.com,
	richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 09/29] target/riscv: Convert RV32A insns to decodetree
Date: Sat, 20 Oct 2018 09:14:31 +0200	[thread overview]
Message-ID: <20181020071451.27808-10-kbastian@mail.uni-paderborn.de> (raw)
In-Reply-To: <20181020071451.27808-1-kbastian@mail.uni-paderborn.de>

Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Signed-off-by: Peer Adelt <peer.adelt@hni.uni-paderborn.de>
---
v1 -> v2:
    - simplified gen_amo() with function pointers
    - rs2 @atom_ld is now decimal

 target/riscv/insn32.decode              |  17 +++
 target/riscv/insn_trans/trans_rva.inc.c | 145 ++++++++++++++++++++++++
 target/riscv/translate.c                |   1 +
 3 files changed, 163 insertions(+)
 create mode 100644 target/riscv/insn_trans/trans_rva.inc.c

diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
index a484844f34..687eadcaa5 100644
--- a/target/riscv/insn32.decode
+++ b/target/riscv/insn32.decode
@@ -38,6 +38,7 @@
 # Argument sets:
 &branch    imm rs2 rs1
 &shift     shamt rs1 rd
+&atomic    aq rl rs2 rs1 rd
 
 # Formats 32:
 
@@ -52,6 +53,9 @@
 @sh5     .......  ..... .....  ... ..... ....... &shift  shamt=%sh5      %rs1 %rd
 @csr     ............   .....  ... ..... .......               %csr     %rs1 %rd
 
+@atom_ld ..... aq:1 rl:1 ..... ........ ..... ....... &atomic rs2=0     %rs1 %rd
+@atom_st ..... aq:1 rl:1 ..... ........ ..... ....... &atomic %rs2      %rs1 %rd
+
 # *** RV32I Base Instruction Set ***
 lui      ....................       ..... 0110111 @u
 auipc    ....................       ..... 0010111 @u
@@ -130,3 +134,16 @@ divw     0000001 .....  ..... 100 ..... 0111011 @r
 divuw    0000001 .....  ..... 101 ..... 0111011 @r
 remw     0000001 .....  ..... 110 ..... 0111011 @r
 remuw    0000001 .....  ..... 111 ..... 0111011 @r
+
+# *** RV32A Standard Extension ***
+lr_w       00010 . . 00000 ..... 010 ..... 0101111 @atom_ld
+sc_w       00011 . . ..... ..... 010 ..... 0101111 @atom_st
+amoswap_w  00001 . . ..... ..... 010 ..... 0101111 @atom_st
+amoadd_w   00000 . . ..... ..... 010 ..... 0101111 @atom_st
+amoxor_w   00100 . . ..... ..... 010 ..... 0101111 @atom_st
+amoand_w   01100 . . ..... ..... 010 ..... 0101111 @atom_st
+amoor_w    01000 . . ..... ..... 010 ..... 0101111 @atom_st
+amomin_w   10000 . . ..... ..... 010 ..... 0101111 @atom_st
+amomax_w   10100 . . ..... ..... 010 ..... 0101111 @atom_st
+amominu_w  11000 . . ..... ..... 010 ..... 0101111 @atom_st
+amomaxu_w  11100 . . ..... ..... 010 ..... 0101111 @atom_st
diff --git a/target/riscv/insn_trans/trans_rva.inc.c b/target/riscv/insn_trans/trans_rva.inc.c
new file mode 100644
index 0000000000..dd0fb02b23
--- /dev/null
+++ b/target/riscv/insn_trans/trans_rva.inc.c
@@ -0,0 +1,145 @@
+/*
+ * RISC-V translation routines for the RV64A Standard Extension.
+ *
+ * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
+ * Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
+ *                    Bastian Koppelmann, kbastian@mail.uni-paderborn.de
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+static inline bool gen_lr(DisasContext *ctx, arg_atomic *a, TCGMemOp mop)
+{
+    TCGv src1 = tcg_temp_new();
+    /* Put addr in load_res, data in load_val.  */
+    gen_get_gpr(src1, a->rs1);
+    if (a->rl) {
+        tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
+    }
+    tcg_gen_qemu_ld_tl(load_val, src1, ctx->mem_idx, mop);
+    if (a->aq) {
+        tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
+    }
+    tcg_gen_mov_tl(load_res, src1);
+    gen_set_gpr(a->rd, load_val);
+
+    tcg_temp_free(src1);
+    return true;
+}
+
+static inline bool gen_sc(DisasContext *ctx, arg_atomic *a, TCGMemOp mop)
+{
+    TCGv src1 = tcg_temp_new();
+    TCGv src2 = tcg_temp_new();
+    TCGv dat = tcg_temp_new();
+    TCGLabel *l1 = gen_new_label();
+    TCGLabel *l2 = gen_new_label();
+
+    gen_get_gpr(src1, a->rs1);
+    tcg_gen_brcond_tl(TCG_COND_NE, load_res, src1, l1);
+
+    gen_get_gpr(src2, a->rs2);
+    /* Note that the TCG atomic primitives are SC,
+       so we can ignore AQ/RL along this path.  */
+    tcg_gen_atomic_cmpxchg_tl(src1, load_res, load_val, src2,
+                              ctx->mem_idx, mop);
+    tcg_gen_setcond_tl(TCG_COND_NE, dat, src1, load_val);
+    gen_set_gpr(a->rd, dat);
+    tcg_gen_br(l2);
+
+    gen_set_label(l1);
+    /* Address comparion failure.  However, we still need to
+       provide the memory barrier implied by AQ/RL.  */
+    tcg_gen_mb(TCG_MO_ALL + a->aq * TCG_BAR_LDAQ + a->rl * TCG_BAR_STRL);
+    tcg_gen_movi_tl(dat, 1);
+    gen_set_gpr(a->rd, dat);
+
+    gen_set_label(l2);
+    tcg_temp_free(dat);
+    tcg_temp_free(src1);
+    tcg_temp_free(src2);
+    return true;
+}
+
+static bool gen_amo(DisasContext *ctx, arg_atomic *a,
+                    void(*func)(TCGv, TCGv, TCGv, TCGArg, TCGMemOp),
+                    TCGMemOp mop)
+{
+    TCGv src1 = tcg_temp_new();
+    TCGv src2 = tcg_temp_new();
+
+    gen_get_gpr(src1, a->rs1);
+    gen_get_gpr(src2, a->rs2);
+
+    (*func)(src2, src1, src2, ctx->mem_idx, mop);
+
+    gen_set_gpr(a->rd, src2);
+    tcg_temp_free(src1);
+    tcg_temp_free(src2);
+    return true;
+}
+
+static bool trans_lr_w(DisasContext *ctx, arg_lr_w *a, uint32_t insn)
+{
+    return gen_lr(ctx, a, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_sc_w(DisasContext *ctx, arg_sc_w *a, uint32_t insn)
+{
+    return gen_sc(ctx, a, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amoswap_w(DisasContext *ctx, arg_amoswap_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amoadd_w(DisasContext *ctx, arg_amoadd_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amoxor_w(DisasContext *ctx, arg_amoxor_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amoand_w(DisasContext *ctx, arg_amoand_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amoor_w(DisasContext *ctx, arg_amoor_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amomin_w(DisasContext *ctx, arg_amomin_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amomax_w(DisasContext *ctx, arg_amomax_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amominu_w(DisasContext *ctx, arg_amominu_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, (MO_ALIGN | MO_TESL));
+}
+
+static bool trans_amomaxu_w(DisasContext *ctx, arg_amomaxu_w *a, uint32_t insn)
+{
+    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TESL));
+}
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index 17c4d79b18..d6e8d9700f 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -1640,6 +1640,7 @@ bool decode_insn32(DisasContext *ctx, uint32_t insn);
 /* Include insn module translation function */
 #include "insn_trans/trans_rvi.inc.c"
 #include "insn_trans/trans_rvm.inc.c"
+#include "insn_trans/trans_rva.inc.c"
 
 static void decode_RV32_64G(CPURISCVState *env, DisasContext *ctx)
 {
-- 
2.19.1

  parent reply	other threads:[~2018-10-20  7:15 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-20  7:14 [Qemu-devel] [PATCH v2 00/29] target/riscv: Convert to decodetree Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 01/29] target/riscv: Move CPURISCVState pointer to DisasContext Bastian Koppelmann
2018-10-25 16:38   ` Palmer Dabbelt
2018-10-25 16:54     ` Peter Maydell
2018-10-25 17:05       ` Palmer Dabbelt
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 02/29] targer/riscv: Activate decodetree and implemnt LUI & AUIPC Bastian Koppelmann
2018-10-20 19:32   ` Richard Henderson
2018-10-25 16:58   ` Palmer Dabbelt
2018-10-26 10:49     ` Bastian Koppelmann
2018-10-26 13:58       ` Richard Henderson
2018-10-26 14:53         ` Bastian Koppelmann
2018-10-26 15:42           ` Palmer Dabbelt
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 03/29] target/riscv: Convert RVXI branch insns to decodetree Bastian Koppelmann
2018-10-20 19:34   ` Richard Henderson
2018-10-25 20:24   ` Palmer Dabbelt
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 04/29] target/riscv: Convert RVXI load/store " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 05/29] target/riscv: Convert RVXI arithmetic " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 06/29] target/riscv: Convert RVXI fence " Bastian Koppelmann
2018-10-21 14:05   ` Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 07/29] target/riscv: Convert RVXI csr " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 08/29] target/riscv: Convert RVXM " Bastian Koppelmann
2018-10-20  7:14 ` Bastian Koppelmann [this message]
2018-10-23  8:19   ` [Qemu-devel] [PATCH v2 09/29] target/riscv: Convert RV32A " Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 10/29] target/riscv: Convert RV64A " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 11/29] target/riscv: Convert RV32F " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 12/29] target/riscv: Convert RV64F " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 13/29] target/riscv: Convert RV32D " Bastian Koppelmann
2018-10-23  8:21   ` Richard Henderson
2018-10-31 10:44   ` Bastian Koppelmann
2018-10-31 10:47     ` Bastian Koppelmann
2018-10-31 17:21     ` Palmer Dabbelt
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 14/29] target/riscv: Convert RV64D " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 15/29] target/riscv: Convert RV priv " Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 16/29] target/riscv: Convert quadrant 0 of RVXC " Bastian Koppelmann
2018-10-23  8:31   ` Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 17/29] target/riscv: Convert quadrant 1 " Bastian Koppelmann
2018-10-23  8:35   ` Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 18/29] target/riscv: Convert quadrant 2 " Bastian Koppelmann
2018-10-23  8:39   ` Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 19/29] target/riscv: Remove gen_jalr() Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 20/29] target/riscv: Remove manual decoding from gen_branch() Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 21/29] target/riscv: Remove manual decoding from gen_load() Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 22/29] target/riscv: Remove manual decoding from gen_store() Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 23/29] target/riscv: Move gen_arith_imm() decoding into trans_* functions Bastian Koppelmann
2018-10-23  8:46   ` Richard Henderson
2018-10-24  9:07   ` Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 24/29] target/riscv: make ADD/SUB/OR/XOR/AND insn use arg lists Bastian Koppelmann
2018-10-23  8:53   ` Richard Henderson
2018-10-23  8:55     ` Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 25/29] target/riscv: Remove shift and slt insn manual decoding Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 26/29] target/riscv: Remove manual decoding of RV32/64M insn Bastian Koppelmann
2018-10-23  9:02   ` Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 27/29] target/riscv: Remove gen_system() Bastian Koppelmann
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 28/29] target/riscv: Remove decode_RV32_64G() Bastian Koppelmann
2018-10-23  9:04   ` Richard Henderson
2018-10-20  7:14 ` [Qemu-devel] [PATCH v2 29/29] target/riscv: Rename trans_arith to gen_arith Bastian Koppelmann
2018-10-23  9:04   ` Richard Henderson
2018-10-24 22:21 ` [Qemu-devel] [PATCH v2 00/29] target/riscv: Convert to decodetree Palmer Dabbelt
2018-10-26 10:53   ` Bastian Koppelmann
2018-10-27  6:20     ` Palmer Dabbelt

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=20181020071451.27808-10-kbastian@mail.uni-paderborn.de \
    --to=kbastian@mail.uni-paderborn.de \
    --cc=Alistair.Francis@wdc.com \
    --cc=mjc@sifive.com \
    --cc=palmer@sifive.com \
    --cc=peer.adelt@hni.uni-paderborn.de \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=sagark@eecs.berkeley.edu \
    /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.