target/arm: Implement FEAT_CMPBR
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
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
@@ -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
Re: [PATCH v2 1/4] target/arm: Add feature predicate for FEAT_CMPBR
Quoted 11 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- target/arm/cpu-features.h | 5 +++++ 1 file changed, 5 insertions(+)target/arm/cpu-features.h +0
-0
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
PATCH v2 2/4 target/arm: Implement CB, CBB, CBH
In reply to Richard HendersonCompare 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
@@ -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
@@ -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
Re: [PATCH v2 2/4] target/arm: Implement CB, CBB, CBH
Quoted 41 lines · Richard Henderson
Compare and branch instructions, with various operand widths.
Signed-off-by Richard Henderson <[email protected]>--- 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@@ -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
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
@@ -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
@@ -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
Re: [PATCH v2 3/4] target/arm: Implement CB (immediate)
Quoted 17 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- 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@@ -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
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
@@ -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
@@ -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
@@ -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
Re: [PATCH v2 4/4] target/arm: Enable FEAT_CMPBR for -cpu max
Quoted 7 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- 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(-)
thanks
-- PMM
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.
- ReorgCB_condto avoid argument ordering error (paolo).
Quoted 8 lines
r~
Richard Henderson (4):
target/arm: Add feature predicate forFEAT_CMPBRtarget/arm: Implement CB, CBB, CBH target/arm: Implement CB (immediate) target/arm: EnableFEAT_CMPBRfor -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