Skip to contentSkip to conversation

target/arm: Implement FEAT_CMPBR

PATCH Superseded Richard Henderson 2 participants 10 messages May 18 – May 28

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v2 cover target/arm: Implement FEAT_CMPBR

v1: https://lore.kernel.org/qemu-devel/[email protected]/

Changes for v2:
- v9.6 to be included in Arm ARM.
- Reorg CB_cond to avoid argument ordering error (paolo).

r~

Richard Henderson (4):
target/arm: Add feature predicate for FEAT_CMPBR target/arm: Implement CB, CBB, CBH target/arm: Implement CB (immediate) target/arm: Enable FEAT_CMPBR for -cpu max

 target/arm/cpu-features.h      |  5 ++
 linux-user/aarch64/elfload.c   |  1 +
 target/arm/tcg/cpu64.c         |  2 +-
 target/arm/tcg/translate-a64.c | 83 ++++++++++++++++++++++++++++++++++
 docs/system/arm/emulation.rst  |  1 +
 target/arm/tcg/a64.decode      | 11 +++++
 6 files changed, 102 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/4 target/arm: Add feature predicate for FEAT_CMPBR

---
 target/arm/cpu-features.h | 5 +++++
 1 file changed, 5 insertions(+)
target/arm/cpu-features.h +5 -0
index 4e44245a8b..217ab29bb4 100644
@@ -1043,6 +1043,11 @@ static inline bool isar_feature_aa64_cssc(const ARMISARegisters *id)
     return FIELD_EX64_IDREG(id, ID_AA64ISAR2, CSSC) != 0;
 }
 
+static inline bool isar_feature_aa64_cmpbr(const ARMISARegisters *id)
+{
+    return FIELD_EX64_IDREG(id, ID_AA64ISAR2, CSSC) >= 2;
+}
+
 static inline bool isar_feature_aa64_lut(const ARMISARegisters *id)
 {
     return FIELD_EX64_IDREG(id, ID_AA64ISAR2, LUT);
Signature · 1 line
2.43.0
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] target/arm: Add feature predicate for FEAT_CMPBR

Quoted 11 lines · Richard Henderson
---
 target/arm/cpu-features.h | 5 +++++
 1 file changed, 5 insertions(+)
target/arm/cpu-features.h +0 -0
index 4e44245a8b..217ab29bb4 100644

target/arm/cpu-features.h static inline bool isar_feature_aa64_cssc(const ARMISARegisters *id) · line 1050

Quoted 8 lines
target/arm/cpu-features.h +5 -0
@@ -1043,6 +1043,11 @@ static inline bool isar_feature_aa64_cssc(const ARMISARegisters *id)
     return FIELD_EX64_IDREG(id, ID_AA64ISAR2, CSSC) != 0;
 }
 
+static inline bool isar_feature_aa64_cmpbr(const ARMISARegisters *id)
+{
+    return FIELD_EX64_IDREG(id, ID_AA64ISAR2, CSSC) >= 2;
+}
+

thanks
-- PMM

#3 lore raw

PATCH v2 2/4 target/arm: Implement CB, CBB, CBH

In reply to Richard Henderson

Compare and branch instructions, with various operand widths.

---
 target/arm/tcg/translate-a64.c | 42 ++++++++++++++++++++++++++++++++++
 target/arm/tcg/a64.decode      |  9 ++++++++
 2 files changed, 51 insertions(+)
target/arm/tcg/translate-a64.c +42 -0
index 9a27c4c6ec..293aa43cc9 100644
@@ -1774,6 +1774,48 @@ static bool trans_B_cond(DisasContext *s, arg_B_cond *a)
     return true;
 }
 
+static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a)
+{
+    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[a->cc];
+    TCGv_i64 t, m;
+
+    if (!dc_isar_feature(aa64_cmpbr, s) || cond == TCG_COND_NEVER) {
+        return false;
+    }
+
+    t = cpu_reg(s, a->rt);
+    m = cpu_reg(s, a->rm);
+    if (a->esz != MO_64) {
+        MemOp mop = a->esz | (is_signed_cond(cond) ? MO_SIGN : 0);
+        TCGv_i64 tt = tcg_temp_new_i64();
+        TCGv_i64 tm = tcg_temp_new_i64();
+
+        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, a->imm);
+    return true;
+}
+
 static void set_btype_for_br(DisasContext *s, int rn)
 {
     if (dc_isar_feature(aa64_bti, s)) {
target/arm/tcg/a64.decode +9 -0
index 01b1b3e38b..8fb1314bfc 100644
@@ -208,6 +208,15 @@ 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
 
+# CB, CBB, CBH
+%imm9           5:s9   !function=times_4
+&cb             cc rt rm imm esz
+@cb             . ....... cc:3 rm:5 .. ......... rt:5       &cb imm=%imm9
+CB_cond         0 1110100 ... ..... 00 ......... .....      @cb esz=2
+CB_cond         1 1110100 ... ..... 00 ......... .....      @cb esz=3
+CB_cond         0 1110100 ... ..... 10 ......... .....      @cb esz=0  # CBB
+CB_cond         0 1110100 ... ..... 11 ......... .....      @cb esz=1  # CBH
+
 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
Signature · 1 line
2.43.0
Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] target/arm: Implement CB, CBB, CBH

Quoted 41 lines · Richard Henderson

Compare and branch instructions, with various operand widths.

---
 target/arm/tcg/translate-a64.c | 42 ++++++++++++++++++++++++++++++++++
 target/arm/tcg/a64.decode      |  9 ++++++++
 2 files changed, 51 insertions(+)
target/arm/tcg/translate-a64.c +24 -0
index 9a27c4c6ec..293aa43cc9 100644
@@ -1774,6 +1774,48 @@ static bool trans_B_cond(DisasContext *s, arg_B_cond *a)
     return true;
 }
 
+static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a)
+{
+    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[a->cc];
+    TCGv_i64 t, m;
+
+    if (!dc_isar_feature(aa64_cmpbr, s) || cond == TCG_COND_NEVER) {
+        return false;
+    }
+
+    t = cpu_reg(s, a->rt);
+    m = cpu_reg(s, a->rm);
+    if (a->esz != MO_64) {
+        MemOp mop = a->esz | (is_signed_cond(cond) ? MO_SIGN : 0);
+        TCGv_i64 tt = tcg_temp_new_i64();

target/arm/tcg/translate-a64.c static bool trans_B_cond(DisasContext *s, arg_B_cond *a) · line 1810

Quoted 10 lines
target/arm/tcg/translate-a64.c +10 -0
+        TCGv_i64 tm = tcg_temp_new_i64();
+
+        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);

Variable declaration needs to go at top of function.

Otherwise

thanks
-- PMM

#5 lore raw

PATCH v2 3/4 target/arm: Implement CB (immediate)

In reply to Richard Henderson
---
 target/arm/tcg/translate-a64.c | 41 ++++++++++++++++++++++++++++++++++
 target/arm/tcg/a64.decode      |  2 ++
 2 files changed, 43 insertions(+)
target/arm/tcg/translate-a64.c +41 -0
index 293aa43cc9..c4a016f36c 100644
@@ -1816,6 +1816,47 @@ static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a)
     return true;
 }
 
+static bool trans_CB_cond_imm(DisasContext *s, arg_CB_cond_imm *a)
+{
+    static const TCGCond cb_cond[8] = {
+        [0] = TCG_COND_GT,
+        [1] = TCG_COND_LT,
+        [2] = TCG_COND_GTU,
+        [3] = TCG_COND_LTU,
+        [4] = TCG_COND_NEVER,  /* reserved */
+        [5] = TCG_COND_NEVER,  /* reserved */
+        [6] = TCG_COND_EQ,
+        [7] = TCG_COND_NE,
+    };
+    TCGCond cond = cb_cond[a->cc];
+    TCGv_i64 t;
+
+    if (!dc_isar_feature(aa64_cmpbr, s) || cond == TCG_COND_NEVER) {
+        return false;
+    }
+
+    t = cpu_reg(s, a->rt);
+    if (!a->sf) {
+        TCGv_i64 tt = tcg_temp_new_i64();
+
+        if (is_signed_cond(cond)) {
+            tcg_gen_ext32s_i64(tt, t);
+        } else {
+            tcg_gen_ext32u_i64(tt, t);
+        }
+        t = tt;
+    }
+
+    reset_btype(s);
+    DisasLabel match = gen_disas_label(s);
+
+    tcg_gen_brcondi_i64(cond, t, a->imm6, match.label);
+    gen_goto_tb(s, 0, 4);
+    set_disas_label(s, match);
+    gen_goto_tb(s, 1, a->imm9);
+    return true;
+}
+
 static void set_btype_for_br(DisasContext *s, int rn)
 {
     if (dc_isar_feature(aa64_bti, s)) {
target/arm/tcg/a64.decode +2 -0
index 8fb1314bfc..1f114443c4 100644
@@ -217,6 +217,8 @@ CB_cond         1 1110100 ... ..... 00 ......... .....      @cb esz=3
 CB_cond         0 1110100 ... ..... 10 ......... .....      @cb esz=0  # CBB
 CB_cond         0 1110100 ... ..... 11 ......... .....      @cb esz=1  # CBH
 
+CB_cond_imm     sf:1 1110101 cc:3 imm6:6 0 ......... rt:5   %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
Signature · 1 line
2.43.0
Reviewed-by on v2 3/4
#6 lore raw

Re: [PATCH v2 3/4] target/arm: Implement CB (immediate)

Quoted 17 lines · Richard Henderson
---
 target/arm/tcg/translate-a64.c | 41 ++++++++++++++++++++++++++++++++++
 target/arm/tcg/a64.decode      |  2 ++
 2 files changed, 43 insertions(+)
target/arm/tcg/translate-a64.c +2 -0
index 293aa43cc9..c4a016f36c 100644
@@ -1816,6 +1816,47 @@ static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a)
     return true;
 }
 
+static bool trans_CB_cond_imm(DisasContext *s, arg_CB_cond_imm *a)
+{

target/arm/tcg/translate-a64.c static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a) · line 1830

Quoted 10 lines
target/arm/tcg/translate-a64.c +10 -0
+    static const TCGCond cb_cond[8] = {
+        [0] = TCG_COND_GT,
+        [1] = TCG_COND_LT,
+        [2] = TCG_COND_GTU,
+        [3] = TCG_COND_LTU,
+        [4] = TCG_COND_NEVER,  /* reserved */
+        [5] = TCG_COND_NEVER,  /* reserved */
+        [6] = TCG_COND_EQ,
+        [7] = TCG_COND_NE,
+    };

Maybe worth a brief comment
/* Note that CB imm and CB encode the condition differently */

?

Quoted 11 lines
target/arm/tcg/translate-a64.c +11 -0
+    TCGCond cond = cb_cond[a->cc];
+    TCGv_i64 t;
+
+    if (!dc_isar_feature(aa64_cmpbr, s) || cond == TCG_COND_NEVER) {
+        return false;
+    }
+
+    t = cpu_reg(s, a->rt);
+    if (!a->sf) {
+        TCGv_i64 tt = tcg_temp_new_i64();
+

target/arm/tcg/translate-a64.c static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a) · line 1851

Quoted 10 lines
target/arm/tcg/translate-a64.c +10 -0
+        if (is_signed_cond(cond)) {
+            tcg_gen_ext32s_i64(tt, t);
+        } else {
+            tcg_gen_ext32u_i64(tt, t);
+        }
+        t = tt;
+    }
+
+    reset_btype(s);
+    DisasLabel match = gen_disas_label(s);

Var decl at top of function.

target/arm/tcg/translate-a64.c static bool trans_CB_cond(DisasContext *s, arg_CB_cond *a) · line 1858

Quoted 7 lines
target/arm/tcg/translate-a64.c +7 -0
+
+    tcg_gen_brcondi_i64(cond, t, a->imm6, match.label);
+    gen_goto_tb(s, 0, 4);
+    set_disas_label(s, match);
+    gen_goto_tb(s, 1, a->imm9);
+    return true;
+}

Otherwise

thanks
-- PMM

#7 lore raw

PATCH v2 4/4 target/arm: Enable FEAT_CMPBR for -cpu max

In reply to Richard Henderson
---
 linux-user/aarch64/elfload.c  | 1 +
 target/arm/tcg/cpu64.c        | 2 +-
 docs/system/arm/emulation.rst | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
linux-user/aarch64/elfload.c +1 -0
index 3af5a37776..cebcf7cea4 100644
@@ -170,6 +170,7 @@ abi_ulong get_elf_hwcap(CPUState *cs)
     GET_FEATURE_ID(aa64_rcpc_8_3, ARM_HWCAP_A64_LRCPC);
     GET_FEATURE_ID(aa64_rcpc_8_4, ARM_HWCAP_A64_ILRCPC);
     GET_FEATURE_ID(aa64_gcs, ARM_HWCAP_A64_GCS);
+    GET_FEATURE_ID(aa64_cmpbr, ARM_HWCAP_A64_CMPBR);
 
     return hwcaps;
 }
target/arm/tcg/cpu64.c +1 -1
index 649d854a65..0c00074c4f 100644
@@ -1262,7 +1262,7 @@ void aarch64_max_tcg_initfn(Object *obj)
     t = FIELD_DP64(t, ID_AA64ISAR2, MOPS, 1);     /* FEAT_MOPS */
     t = FIELD_DP64(t, ID_AA64ISAR2, BC, 1);       /* FEAT_HBC */
     t = FIELD_DP64(t, ID_AA64ISAR2, WFXT, 2);     /* FEAT_WFxT */
-    t = FIELD_DP64(t, ID_AA64ISAR2, CSSC, 1);     /* FEAT_CSSC */
+    t = FIELD_DP64(t, ID_AA64ISAR2, CSSC, 2);     /* FEAT_CSSC, FEAT_CMPBR */
     t = FIELD_DP64(t, ID_AA64ISAR2, ATS1A, 1);    /* FEAT_ATS1A */
     SET_IDREG(isar, ID_AA64ISAR2, t);
 
docs/system/arm/emulation.rst +1 -0
index 8cd7fe7b00..300ccec7ea 100644
@@ -35,6 +35,7 @@ the following architecture extensions:
 - FEAT_CCIDX (Extended cache index)
 - FEAT_CHK (Check Feature Status)
 - FEAT_CMOW (Control for cache maintenance permission)
+- FEAT_CMPBR (Compare and Branch instructions)
 - FEAT_CRC32 (CRC32 instructions)
 - FEAT_Crypto (Cryptographic Extension)
 - FEAT_CSSC (Common Short Sequence Compression instructions)
Signature · 1 line
2.43.0
#9 lore raw
In reply to Richard Henderson
Quoted 8 lines · Richard Henderson

v1: https://lore.kernel.org/qemu-devel/[email protected]/

Changes for v2:
- v9.6 to be included in Arm ARM.
- Reorg CB_cond to avoid argument ordering error (paolo).

Quoted 8 lines

r~

Richard Henderson (4):
target/arm: Add feature predicate for FEAT_CMPBR target/arm: Implement CB, CBB, CBH target/arm: Implement CB (immediate) target/arm: Enable FEAT_CMPBR for -cpu max

Since my review comments were trivial, I've applied this series to target-arm.next and made the minor tweaks to them there.

thanks
-- PMM