qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org
Subject: [PATCH 08/11] target/arm: Implement CB, CBB, CBH
Date: Sun,  3 Aug 2025 11:40:16 +1000	[thread overview]
Message-ID: <20250803014019.416797-9-richard.henderson@linaro.org> (raw)
In-Reply-To: <20250803014019.416797-1-richard.henderson@linaro.org>

Compare and branch instructions, with various operand widths.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/tcg/translate-a64.c | 60 ++++++++++++++++++++++++++++++++++
 target/arm/tcg/a64.decode      |  5 +++
 2 files changed, 65 insertions(+)

diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
index 0c78d4bb79..f3970ac599 100644
--- a/target/arm/tcg/translate-a64.c
+++ b/target/arm/tcg/translate-a64.c
@@ -1706,6 +1706,66 @@ static bool trans_B_cond(DisasContext *s, arg_B_cond *a)
     return true;
 }
 
+static bool do_cb_cond(DisasContext *s, int cc, int imm,
+                       int rt, int rm, MemOp mop)
+{
+    static const TCGCond cb_cond[8] = {
+        [0] = TCG_COND_GT,
+        [1] = TCG_COND_GE,
+        [2] = TCG_COND_GTU,
+        [3] = TCG_COND_GEU,
+        [4] = TCG_COND_NEVER,  /* reserved */
+        [5] = TCG_COND_NEVER,  /* reserved */
+        [6] = TCG_COND_EQ,
+        [7] = TCG_COND_NE,
+    };
+    TCGCond cond = cb_cond[cc];
+    TCGv_i64 t, m;
+
+    if (!dc_isar_feature(aa64_cmpbr, s) || cond == TCG_COND_NEVER) {
+        return false;
+    }
+
+    t = cpu_reg(s, rt);
+    m = cpu_reg(s, rm);
+    if (mop != MO_64) {
+        TCGv_i64 tt = tcg_temp_new_i64();
+        TCGv_i64 tm = tcg_temp_new_i64();
+
+        if (is_signed_cond(cond)) {
+            mop |= MO_SIGN;
+        }
+        tcg_gen_ext_i64(tt, t, mop);
+        tcg_gen_ext_i64(tm, m, mop);
+        t = tt;
+        m = tm;
+    }
+
+    reset_btype(s);
+    DisasLabel match = gen_disas_label(s);
+
+    tcg_gen_brcond_i64(cond, t, m, match.label);
+    gen_goto_tb(s, 0, 4);
+    set_disas_label(s, match);
+    gen_goto_tb(s, 1, imm);
+    return true;
+}
+
+static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a)
+{
+    return do_cb_cond(s, a->cc, a->imm, a->rt, a->rm, a->sf ? 64 : 32);
+}
+
+static bool trans_CBB_cond(DisasContext *s, arg_CBB_cond *a)
+{
+    return do_cb_cond(s, a->cc, a->imm, a->rt, a->rm, 8);
+}
+
+static bool trans_CBH_cond(DisasContext *s, arg_CBH_cond *a)
+{
+    return do_cb_cond(s, a->cc, a->imm, 16, a->rt, a->rm);
+}
+
 static void set_btype_for_br(DisasContext *s, int rn)
 {
     if (dc_isar_feature(aa64_bti, s)) {
diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode
index 766c610c01..fa94631123 100644
--- a/target/arm/tcg/a64.decode
+++ b/target/arm/tcg/a64.decode
@@ -208,6 +208,11 @@ TBZ             . 011011 nz:1 ..... .............. rt:5 &tbz  imm=%imm14 bitpos=
 # B.cond and BC.cond
 B_cond          0101010 0 ................... c:1 cond:4 imm=%imm19
 
+%imm9           5:s9   !function=times_4
+CB_cond         sf:1 1110100 cc:3 rm:5 00 ......... rt:5    imm=%imm9
+CBB_cond        0    1110100 cc:3 rm:5 10 ......... rt:5    imm=%imm9
+CBH_cond        0    1110100 cc:3 rm:5 11 ......... rt:5    imm=%imm9
+
 BR              1101011 0000 11111 000000 rn:5 00000 &r
 BLR             1101011 0001 11111 000000 rn:5 00000 &r
 RET             1101011 0010 11111 000000 rn:5 00000 &r
-- 
2.43.0



  parent reply	other threads:[~2025-08-03  1:42 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-03  1:40 [PATCH 00/11] target/arm: Implement FEAT_CSSC, FEAT_CMPBR Richard Henderson
2025-08-03  1:40 ` [PATCH 01/11] target/arm: Add feature predicate for FEAT_CSSC Richard Henderson
2025-08-15 13:06   ` Peter Maydell
2025-08-03  1:40 ` [PATCH 02/11] target/arm: Implement MIN/MAX (immediate) Richard Henderson
2025-08-15 13:18   ` Peter Maydell
2025-08-15 13:33     ` Richard Henderson
2025-08-03  1:40 ` [PATCH 03/11] target/arm: Implement MIN/MAX (register) Richard Henderson
2025-08-15 13:20   ` Peter Maydell
2025-08-03  1:40 ` [PATCH 04/11] target/arm: Split out gen_wrap2_i32 helper Richard Henderson
2025-08-15 13:09   ` Peter Maydell
2025-08-15 16:05   ` Peter Maydell
2025-08-03  1:40 ` [PATCH 05/11] target/arm: Implement CTZ, CNT, ABS Richard Henderson
2025-08-15 13:26   ` Peter Maydell
2025-08-26 16:11   ` Peter Maydell
2025-08-03  1:40 ` [PATCH 06/11] target/arm: Enable FEAT_CSSC for -cpu max Richard Henderson
2025-08-15 13:10   ` Peter Maydell
2025-08-03  1:40 ` [PATCH 07/11] target/arm: Add feature predicate for FEAT_CMPBR Richard Henderson
2025-08-03  1:40 ` Richard Henderson [this message]
2025-08-03 12:31   ` [PATCH 08/11] target/arm: Implement CB, CBB, CBH Paolo Bonzini
2025-08-03 20:28     ` Richard Henderson
2025-08-03  1:40 ` [PATCH 09/11] target/arm: Implement CB (immediate) Richard Henderson
2025-08-03  1:40 ` [PATCH 10/11] linux-user: Change exported get_elf_hwcap to abi_ulong Richard Henderson
2025-08-15 13:28   ` Peter Maydell
2025-08-03  1:40 ` [PATCH 11/11] target/arm: Enable FEAT_CMPBR for -cpu max Richard Henderson
2025-08-15 14:10 ` [PATCH 00/11] target/arm: Implement FEAT_CSSC, FEAT_CMPBR Peter Maydell

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=20250803014019.416797-9-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --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).