target/arm: Start conversion of A64 decoder to decodetree
cover target/arm: Start conversion of A64 decoder to decodetree
The A64 decoder is still an old-school hand-written one. It's not too badly structured as these things go, but it's still been noticeably harder to both add new instructions to and to review patches for than a decodetree decoder. (This is particularly clear when you have to review a patch that adds an insn both to A32 and A64 -- one half of the patch is a lot easier to understand than the other.)
I was looking at FEAT_MOPS, which is in the A64 load/store area of the instruction set, and I really didn't fancy trying to fit it into the old decoder. The instruction set is not standing still, so we're going to have to keep adding instructions for the foreseeable future. We should make our lives easier by biting the bullet and converting this to decodetree.
Past experience is that a decodetree conversion works out to a lot of patches, so this series is just the first part, which converts data-processing-immediate and branch insns. Most of the first half is some older work from Richard Henderson, which I rebased and tweaked a little. I definitely want to convert the whole of the integer decode, but I might leave the FP/SIMD insns for later.
thanks
-- PMM
Peter Maydell (11):
target/arm: Create decodetree skeleton for A64 target/arm: Pull calls to disas_sve() and disas_sme() out of legacy
decoder
target/arm: Convert Extract instructions to decodetree target/arm: Convert unconditional branch immediate to decodetree target/arm: Convert CBZ, CBNZ to decodetree
target/arm: Convert TBZ, TBNZ to decodetree
target/arm: Convert conditional branch insns to decodetree target/arm: Convert BR, BLR, RET to decodetree target/arm: Convert BRA[AB]Z, BLR[AB]Z, RETA[AB] to decodetree target/arm: Convert BRAA, BRAB, BLRAA, BLRAB to decodetree target/arm: Convert ERET, ERETAA, ERETAB to decodetree
Richard Henderson (9):
target/arm: Split out disas_a64_legacy
target/arm: Convert PC-rel addressing to decodetree target/arm: Split gen_add_CC and gen_sub_CC
target/arm: Convert Add/subtract (immediate) to decodetree target/arm: Convert Add/subtract (immediate with tags) to decodetree target/arm: Replace bitmask64 with MAKE_64BIT_MASK target/arm: Convert Logical (immediate) to decodetree target/arm: Convert Move wide (immediate) to decodetree target/arm: Convert Bitfield to decodetree
target/arm/tcg/translate.h | 5 + target/arm/tcg/a64.decode | 156 ++++ target/arm/tcg/translate-a64.c | 1318 ++++++++++++++------------------ target/arm/tcg/meson.build | 1 + 4 files changed, 729 insertions(+), 751 deletions(-) create mode 100644 target/arm/tcg/a64.decode
Signature · 1 line
2.34.1
PATCH 1/20 target/arm: Split out disas_a64_legacy
From: Richard Henderson <[email protected]>
Split out all of the decode stuff from aarch64_tr_translate_insn. Call it disas_a64_legacy to indicate it will be replaced.
--- target/arm/tcg/translate-a64.c | 82 ++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 38 deletions(-)
target/arm/tcg/translate-a64.c +44 -38
@@ -14200,6 +14200,49 @@ static bool btype_destination_ok(uint32_t insn, bool bt, int btype)return false; } +/* C3.1 A64 instruction index by encoding */ +static void disas_a64_legacy (DisasContext *s,uint32_t insn) +{ +switch (extract32 (insn,25 ,4 )) { +case 0x0 : +if (!extract32 (insn,31 ,1 ) || !disas_sme (s, insn)) { +unallocated_encoding (s); + } +break ; +case 0x1 :case 0x3 :/* UNALLOCATED */ +unallocated_encoding (s); +break ; +case 0x2 : +if (!disas_sve (s, insn)) { +unallocated_encoding (s); + } +break ; +case 0x8 :case 0x9 :/* Data processing - immediate */ +disas_data_proc_imm (s, insn); +break ; +case 0xa :case 0xb :/* Branch, exception generation and system insns */ +disas_b_exc_sys (s, insn); +break ; +case 0x4 : +case 0x6 : +case 0xc : +case 0xe :/* Loads and stores */ +disas_ldst (s, insn); +break ; +case 0x5 : +case 0xd :/* Data processing - register */ +disas_data_proc_reg (s, insn); +break ; +case 0x7 : +case 0xf :/* Data processing - SIMD and floating point */ +disas_data_proc_simd_fp (s, insn); +break ; +default : +assert (FALSE);/* all 15 cases should be handled above */ +break ; + } +} +static void aarch64_tr_init_disas_context (DisasContextBase *dcbase,CPUState *cpu) {
@@ -14401,44 +14444,7 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)disas_sme_fa64 (s, insn); } -switch (extract32 (insn,25 ,4 )) { -case 0x0 : -if (!extract32 (insn,31 ,1 ) || !disas_sme (s, insn)) { -unallocated_encoding (s); - } -break ; -case 0x1 :case 0x3 :/* UNALLOCATED */ -unallocated_encoding (s); -break ; -case 0x2 : -if (!disas_sve (s, insn)) { -unallocated_encoding (s); - } -break ; -case 0x8 :case 0x9 :/* Data processing - immediate */ -disas_data_proc_imm (s, insn); -break ; -case 0xa :case 0xb :/* Branch, exception generation and system insns */ -disas_b_exc_sys (s, insn); -break ; -case 0x4 : -case 0x6 : -case 0xc : -case 0xe :/* Loads and stores */ -disas_ldst (s, insn); -break ; -case 0x5 : -case 0xd :/* Data processing - register */ -disas_data_proc_reg (s, insn); -break ; -case 0x7 : -case 0xf :/* Data processing - SIMD and floating point */ -disas_data_proc_simd_fp (s, insn); -break ; -default : -assert (FALSE);/* all 15 cases should be handled above */ -break ; - } +disas_a64_legacy (s, insn);/* * After execution of most insns, btype is reset to 0.
Signature · 1 line
2.34.1
PATCH 2/20 target/arm: Create decodetree skeleton for A64
In reply to Peter MaydellThe A64 translator uses a hand-written decoder for everything except SVE or SME. It's fairly well structured, but it's becoming obvious that it's still more painful to add instructions to than the A32 translator, because putting a new instruction into the right place in a hand-written decoder is much harder than adding new instruction patterns to a decodetree file.
As the first step in conversion to decodetree, create the skeleton of the decodetree decoder; where it does not handle instructions we will fall back to the legacy decoder (which will be for everything at the moment, since there are no patterns in a64.decode).
--- target/arm/tcg/a64.decode | 20 ++++++++++++++++++++ target/arm/tcg/translate-a64.c | 18 +++++++++++------- target/arm/tcg/meson.build | 1 + 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 target/arm/tcg/a64.decode
target/arm/tcg/a64.decode new file +20 -0
@@ -0,0 +1,20 @@ +# AArch64 A64 allowed instruction decoding +# +# Copyright (c) 2023 Linaro, Ltd +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. + +# +# This file is processed by scripts/decodetree.py +#
target/arm/tcg/translate-a64.c +11 -7
@@ -56,6 +56,13 @@ enum a64_shift_type { A64_SHIFT_TYPE_ROR = 3 }; +/* +* Include the generated decoders. +*/ + +#include "decode-sme-fa64.c.inc" +#include "decode-a64.c.inc" +/* Table based decoder typedefs - used when the relevant bits for decode * are too awkwardly scattered across the instruction (eg SIMD). */
@@ -14100,12 +14107,6 @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn) } } -/* -* Include the generated SME FA64 decoder. -*/ - -#include "decode-sme-fa64.c.inc" -static bool trans_OK (DisasContext *s,arg_OK *a) {return true;
@@ -14444,7 +14445,10 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)disas_sme_fa64 (s, insn); } -disas_a64_legacy (s, insn); + +if (!disas_a64 (s, insn)) { +disas_a64_legacy (s, insn); + }/* * After execution of most insns, btype is reset to 0.
target/arm/tcg/meson.build +1 -0
@@ -13,6 +13,7 @@ gen = [ decodetree.process('a32-uncond.decode', extra_args: '--static-decode=disas_a32_uncond'), decodetree.process('t32.decode', extra_args: '--static-decode=disas_t32'), decodetree.process('t16.decode', extra_args: ['-w', '16', '--static-decode=disas_t16']), + decodetree.process('a64.decode', extra_args: ['--static-decode=disas_a64']), ] arm_ss.add(gen)
Signature · 1 line
2.34.1
Re: [PATCH 02/20] target/arm: Create decodetree skeleton for A64
Quoted 12 lines · Peter Maydell
The A64 translator uses a hand-written decoder for everything except SVE or SME. It's fairly well structured, but it's becoming obvious that it's still more painful to add instructions to than the A32 translator, because putting a new instruction into the right place in a hand-written decoder is much harder than adding new instruction patterns to a decodetree file.
As the first step in conversion to decodetree, create the skeleton of the decodetree decoder; where it does not handle instructions we will fall back to the legacy decoder (which will be for everything at the moment, since there are no patterns in a64.decode).
Quoted 7 lines
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/a64.decode | 20 ++++++++++++++++++++ target/arm/tcg/translate-a64.c | 18 +++++++++++------- target/arm/tcg/meson.build | 1 + 3 files changed, 32 insertions(+), 7 deletions(-)create mode 100644 target/arm/tcg/a64.decode
r~
PATCH 3/20 target/arm: Pull calls to disas_sve() and disas_sme() out of legacy decoder
In reply to Peter MaydellThe SVE and SME decode is already done by decodetree. Pull the calls to these decoders out of the legacy decoder. This doesn't change behaviour because all the patterns in sve.decode and sme.decode already require the bits that the legacy decoder is decoding to have the correct values.
--- target/arm/tcg/translate-a64.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-)
target/arm/tcg/translate-a64.c +4 -16
@@ -14205,19 +14205,6 @@ static bool btype_destination_ok(uint32_t insn, bool bt, int btype)static void disas_a64_legacy (DisasContext *s,uint32_t insn) {switch (extract32 (insn,25 ,4 )) { -case 0x0 : -if (!extract32 (insn,31 ,1 ) || !disas_sme (s, insn)) { -unallocated_encoding (s); - } -break ; -case 0x1 :case 0x3 :/* UNALLOCATED */ -unallocated_encoding (s); -break ; -case 0x2 : -if (!disas_sve (s, insn)) { -unallocated_encoding (s); - } -break ;case 0x8 :case 0x9 :/* Data processing - immediate */ disas_data_proc_imm (s, insn);break ;
@@ -14239,7 +14226,7 @@ static void disas_a64_legacy(DisasContext *s, uint32_t insn)disas_data_proc_simd_fp (s, insn);break ;default : -assert (FALSE);/* all 15 cases should be handled above */ +unallocated_encoding (s);break ; } }
@@ -14445,8 +14432,9 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)disas_sme_fa64 (s, insn); } - -if (!disas_a64 (s, insn)) { +if (!disas_a64 (s, insn) && + !disas_sme (s,insn) && + !disas_sve (s, insn)) {disas_a64_legacy (s, insn); }
Signature · 1 line
2.34.1
Re: [PATCH 03/20] target/arm: Pull calls to disas_sve() and disas_sme() out of legacy decoder
Quoted 1 line · Peter Maydell
+ !disas_sme(s,insn) &&
Space after comma. Otherwise,
r~
PATCH 4/20 target/arm: Convert PC-rel addressing to decodetree
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Convert the ADR and ADRP instructions.
--- target/arm/tcg/a64.decode | 13 ++++++++++++ target/arm/tcg/translate-a64.c | 38 +++++++++++++--------------------- 2 files changed, 27 insertions(+), 24 deletions(-)
target/arm/tcg/a64.decode +13 -0
@@ -18,3 +18,16 @@ # # This file is processed by scripts/decodetree.py # + +&ri rd imm + + +### Data Processing - Immediate + +# PC-rel addressing + +%imm_pcrel 5:s19 29:2 +@pcrel . .. ..... ................... rd:5 &ri imm=%imm_pcrel + +ADR 0 .. 10000 ................... ..... @pcrel +ADRP 1 .. 10000 ................... ..... @pcrel
target/arm/tcg/translate-a64.c +14 -24
@@ -4179,31 +4179,24 @@ static void disas_ldst(DisasContext *s, uint32_t insn) } } -/* PC-rel. addressing -* 31 30 29 28 24 23 5 4 0 -* +----+-------+-----------+-------------------+------+ -* | op | immlo | 1 0 0 0 0 | immhi | Rd | -* +----+-------+-----------+-------------------+------+ +/* +* PC-rel. addressing */ -static void disas_pc_rel_adr (DisasContext *s,uint32_t insn) + +static bool trans_ADR (DisasContext *s,arg_ri *a) { -unsigned int page, rd; -int64_t offset; +gen_pc_plus_diff (s,cpu_reg (s, a->rd), a->imm); +return true; +} - page =extract32 (insn,31 ,1 ); -/* SignExtend(immhi:immlo) -> offset */ - offset =sextract64 (insn,5 ,19 ); - offset = offset <<2 |extract32 (insn,29 ,2 ); - rd =extract32 (insn,0 ,5 ); +static bool trans_ADRP (DisasContext *s,arg_ri *a) +{ +int64_t offset = (int64_t )a->imm <<12 ; -if (page) { -/* ADRP (page based) */ - offset <<=12 ; -/* The page offset is ok for CF_PCREL. */ - offset -= s->pc_curr &0xfff ; - } - -gen_pc_plus_diff (s,cpu_reg (s, rd), offset); +/* The page offset is ok for CF_PCREL. */ + offset -= s->pc_curr &0xfff ; +gen_pc_plus_diff (s,cpu_reg (s, a->rd), offset); +return true; }/*
@@ -4656,9 +4649,6 @@ static void disas_extract(DisasContext *s, uint32_t insn)static void disas_data_proc_imm (DisasContext *s,uint32_t insn) {switch (extract32 (insn,23 ,6 )) { -case 0x20 :case 0x21 :/* PC-rel. addressing */ -disas_pc_rel_adr (s, insn); -break ;case 0x22 :/* Add/subtract (immediate) */ disas_add_sub_imm (s, insn);break ;
Signature · 1 line
2.34.1
PATCH 5/20 target/arm: Split gen_add_CC and gen_sub_CC
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Split out specific 32-bit and 64-bit functions. These carry the same signature as tcg_gen_add_i64, and so will be easier to pass as callbacks.
Retain gen_add_CC and gen_sub_CC during conversion.
--- target/arm/tcg/translate-a64.c | 149 +++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 65 deletions(-)
target/arm/tcg/translate-a64.c +84 -65
@@ -682,83 +682,102 @@ static inline void gen_logic_CC(int sf, TCGv_i64 result) }/* dest = T0 + T1; compute C, N, V and Z flags */ +static void gen_add64_CC (TCGv_i64 dest,TCGv_i64 t0,TCGv_i64 t1) +{ +TCGv_i64 result, flag, tmp; + result =tcg_temp_new_i64 (); + flag =tcg_temp_new_i64 (); + tmp =tcg_temp_new_i64 (); + +tcg_gen_movi_i64 (tmp,0 ); +tcg_gen_add2_i64 (result, flag, t0, tmp, t1, tmp); + +tcg_gen_extrl_i64_i32 (cpu_CF, flag); + +gen_set_NZ64 (result); + +tcg_gen_xor_i64 (flag, result, t0); +tcg_gen_xor_i64 (tmp, t0, t1); +tcg_gen_andc_i64 (flag, flag, tmp); +tcg_gen_extrh_i64_i32 (cpu_VF, flag); + +tcg_gen_mov_i64 (dest, result); +} + +static void gen_add32_CC (TCGv_i64 dest,TCGv_i64 t0,TCGv_i64 t1) +{ +TCGv_i32 t0_32 =tcg_temp_new_i32 (); +TCGv_i32 t1_32 =tcg_temp_new_i32 (); +TCGv_i32 tmp =tcg_temp_new_i32 (); + +tcg_gen_movi_i32 (tmp,0 ); +tcg_gen_extrl_i64_i32 (t0_32, t0); +tcg_gen_extrl_i64_i32 (t1_32, t1); +tcg_gen_add2_i32 (cpu_NF, cpu_CF, t0_32, tmp, t1_32, tmp); +tcg_gen_mov_i32 (cpu_ZF, cpu_NF); +tcg_gen_xor_i32 (cpu_VF, cpu_NF, t0_32); +tcg_gen_xor_i32 (tmp, t0_32, t1_32); +tcg_gen_andc_i32 (cpu_VF, cpu_VF, tmp); +tcg_gen_extu_i32_i64 (dest, cpu_NF); +} +static void gen_add_CC (int sf,TCGv_i64 dest,TCGv_i64 t0,TCGv_i64 t1) {if (sf) { -TCGv_i64 result, flag, tmp; - result =tcg_temp_new_i64 (); - flag =tcg_temp_new_i64 (); - tmp =tcg_temp_new_i64 (); - -tcg_gen_movi_i64 (tmp,0 ); -tcg_gen_add2_i64 (result, flag, t0, tmp, t1, tmp); - -tcg_gen_extrl_i64_i32 (cpu_CF, flag); - -gen_set_NZ64 (result); - -tcg_gen_xor_i64 (flag, result, t0); -tcg_gen_xor_i64 (tmp, t0, t1); -tcg_gen_andc_i64 (flag, flag, tmp); -tcg_gen_extrh_i64_i32 (cpu_VF, flag); - -tcg_gen_mov_i64 (dest, result); +gen_add64_CC (dest, t0, t1); }else { -/* 32 bit arithmetic */ -TCGv_i32 t0_32 =tcg_temp_new_i32 (); -TCGv_i32 t1_32 =tcg_temp_new_i32 (); -TCGv_i32 tmp =tcg_temp_new_i32 (); - -tcg_gen_movi_i32 (tmp,0 ); -tcg_gen_extrl_i64_i32 (t0_32, t0); -tcg_gen_extrl_i64_i32 (t1_32, t1); -tcg_gen_add2_i32 (cpu_NF, cpu_CF, t0_32, tmp, t1_32, tmp); -tcg_gen_mov_i32 (cpu_ZF, cpu_NF); -tcg_gen_xor_i32 (cpu_VF, cpu_NF, t0_32); -tcg_gen_xor_i32 (tmp, t0_32, t1_32); -tcg_gen_andc_i32 (cpu_VF, cpu_VF, tmp); -tcg_gen_extu_i32_i64 (dest, cpu_NF); +gen_add32_CC (dest, t0, t1); } }/* dest = T0 - T1; compute C, N, V and Z flags */ +static void gen_sub64_CC (TCGv_i64 dest,TCGv_i64 t0,TCGv_i64 t1) +{ +/* 64 bit arithmetic */ +TCGv_i64 result, flag, tmp; + + result =tcg_temp_new_i64 (); + flag =tcg_temp_new_i64 (); +tcg_gen_sub_i64 (result, t0, t1); + +gen_set_NZ64 (result); + +tcg_gen_setcond_i64 (TCG_COND_GEU , flag, t0, t1); +tcg_gen_extrl_i64_i32 (cpu_CF, flag); + +tcg_gen_xor_i64 (flag, result, t0); + tmp =tcg_temp_new_i64 (); +tcg_gen_xor_i64 (tmp, t0, t1); +tcg_gen_and_i64 (flag, flag, tmp); +tcg_gen_extrh_i64_i32 (cpu_VF, flag); +tcg_gen_mov_i64 (dest, result); +} + +static void gen_sub32_CC (TCGv_i64 dest,TCGv_i64 t0,TCGv_i64 t1) +{ +/* 32 bit arithmetic */ +TCGv_i32 t0_32 =tcg_temp_new_i32 (); +TCGv_i32 t1_32 =tcg_temp_new_i32 (); +TCGv_i32 tmp; + +tcg_gen_extrl_i64_i32 (t0_32, t0); +tcg_gen_extrl_i64_i32 (t1_32, t1); +tcg_gen_sub_i32 (cpu_NF, t0_32, t1_32); +tcg_gen_mov_i32 (cpu_ZF, cpu_NF); +tcg_gen_setcond_i32 (TCG_COND_GEU , cpu_CF, t0_32, t1_32); +tcg_gen_xor_i32 (cpu_VF, cpu_NF, t0_32); + tmp =tcg_temp_new_i32 (); +tcg_gen_xor_i32 (tmp, t0_32, t1_32); +tcg_gen_and_i32 (cpu_VF, cpu_VF, tmp); +tcg_gen_extu_i32_i64 (dest, cpu_NF); +} +static void gen_sub_CC (int sf,TCGv_i64 dest,TCGv_i64 t0,TCGv_i64 t1) {if (sf) { -/* 64 bit arithmetic */ -TCGv_i64 result, flag, tmp; - - result =tcg_temp_new_i64 (); - flag =tcg_temp_new_i64 (); -tcg_gen_sub_i64 (result, t0, t1); - -gen_set_NZ64 (result); - -tcg_gen_setcond_i64 (TCG_COND_GEU , flag, t0, t1); -tcg_gen_extrl_i64_i32 (cpu_CF, flag); - -tcg_gen_xor_i64 (flag, result, t0); - tmp =tcg_temp_new_i64 (); -tcg_gen_xor_i64 (tmp, t0, t1); -tcg_gen_and_i64 (flag, flag, tmp); -tcg_gen_extrh_i64_i32 (cpu_VF, flag); -tcg_gen_mov_i64 (dest, result); +gen_sub64_CC (dest, t0, t1); }else { -/* 32 bit arithmetic */ -TCGv_i32 t0_32 =tcg_temp_new_i32 (); -TCGv_i32 t1_32 =tcg_temp_new_i32 (); -TCGv_i32 tmp; - -tcg_gen_extrl_i64_i32 (t0_32, t0); -tcg_gen_extrl_i64_i32 (t1_32, t1); -tcg_gen_sub_i32 (cpu_NF, t0_32, t1_32); -tcg_gen_mov_i32 (cpu_ZF, cpu_NF); -tcg_gen_setcond_i32 (TCG_COND_GEU , cpu_CF, t0_32, t1_32); -tcg_gen_xor_i32 (cpu_VF, cpu_NF, t0_32); - tmp =tcg_temp_new_i32 (); -tcg_gen_xor_i32 (tmp, t0_32, t1_32); -tcg_gen_and_i32 (cpu_VF, cpu_VF, tmp); -tcg_gen_extu_i32_i64 (dest, cpu_NF); +gen_sub32_CC (dest, t0, t1); } }
Signature · 1 line
2.34.1
PATCH 6/20 target/arm: Convert Add/subtract (immediate) to decodetree
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Convert the ADD and SUB (immediate) instructions.
--- target/arm/tcg/translate.h | 5 +++ target/arm/tcg/a64.decode | 17 ++++++++ target/arm/tcg/translate-a64.c | 73 ++++++++++------------------------ 3 files changed, 42 insertions(+), 53 deletions(-)
target/arm/tcg/translate.h +5 -0
@@ -220,6 +220,11 @@ static inline int rsub_8(DisasContext *s, int x)return 8 - x; } +static inline int shl_12 (DisasContext *s,int x) +{ +return x <<12 ; +} +static inline int neon_3same_fp_size (DisasContext *s,int x) {/* Convert 0==fp32, 1==fp16 into a MO_* value */
target/arm/tcg/a64.decode +17 -0
@@ -20,6 +20,7 @@ # &ri rd imm +&rri_sf rd rn imm sf ### Data Processing - Immediate
@@ -31,3 +32,19 @@ ADR 0 .. 10000 ................... ..... @pcrel ADRP 1 .. 10000 ................... ..... @pcrel + +# Add/subtract (immediate) + +%imm12_sh12 10:12 !function=shl_12 +@addsub_imm sf:1 .. ...... . imm:12 rn:5 rd:5 +@addsub_imm12 sf:1 .. ...... . ............ rn:5 rd:5 imm=%imm12_sh12 + +ADD_i . 00 100010 0 ............ ..... ..... @addsub_imm +ADD_i . 00 100010 1 ............ ..... ..... @addsub_imm12 +ADDS_i . 01 100010 0 ............ ..... ..... @addsub_imm +ADDS_i . 01 100010 1 ............ ..... ..... @addsub_imm12 + +SUB_i . 10 100010 0 ............ ..... ..... @addsub_imm +SUB_i . 10 100010 1 ............ ..... ..... @addsub_imm12 +SUBS_i . 11 100010 0 ............ ..... ..... @addsub_imm +SUBS_i . 11 100010 1 ............ ..... ..... @addsub_imm12
target/arm/tcg/translate-a64.c +20 -53
92 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 7/20 target/arm: Convert Add/subtract (immediate with tags) to decodetree
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Convert the ADDG and SUBG (immediate) instructions.
--- target/arm/tcg/a64.decode | 8 +++++++ target/arm/tcg/translate-a64.c | 38 ++++++++++------------------------ 2 files changed, 19 insertions(+), 27 deletions(-)
target/arm/tcg/a64.decode +8 -0
@@ -48,3 +48,11 @@ SUB_i . 10 100010 0 ............ ..... ..... @addsub_imm SUB_i . 10 100010 1 ............ ..... ..... @addsub_imm12 SUBS_i . 11 100010 0 ............ ..... ..... @addsub_imm SUBS_i . 11 100010 1 ............ ..... ..... @addsub_imm12 + +# Add/subtract (immediate with tags) + +&rri_tag rd rn uimm6 uimm4 +@addsub_imm_tag . .. ...... . uimm6:6 .. uimm4:4 rn:5 rd:5 &rri_tag + +ADDG_i 1 00 100011 0 ...... 00 .... ..... ..... @addsub_imm_tag +SUBG_i 1 10 100011 0 ...... 00 .... ..... ..... @addsub_imm_tag
target/arm/tcg/translate-a64.c +11 -27
@@ -4244,49 +4244,36 @@ TRANS(SUBS_i, gen_rri, a, 0, 1, a->sf ? gen_sub64_CC : gen_sub32_CC)/* * Add/subtract (immediate, with tags) -* -* 31 30 29 28 23 22 21 16 14 10 9 5 4 0 -* +--+--+--+-------------+--+---------+--+-------+-----+-----+ -* |sf|op| S| 1 0 0 0 1 1 |o2| uimm6 |o3| uimm4 | Rn | Rd | -* +--+--+--+-------------+--+---------+--+-------+-----+-----+ -* -* op: 0 -> add, 1 -> sub */ -static void disas_add_sub_imm_with_tags (DisasContext *s,uint32_t insn) + +static bool gen_add_sub_imm_with_tags (DisasContext *s,arg_rri_tag *a, +bool sub_op) { -int rd =extract32 (insn,0 ,5 ); -int rn =extract32 (insn,5 ,5 ); -int uimm4 =extract32 (insn,10 ,4 ); -int uimm6 =extract32 (insn,16 ,6 ); -bool sub_op =extract32 (insn,30 ,1 );TCGv_i64 tcg_rn, tcg_rd;int imm; -/* Test all of sf=1, S=0, o2=0, o3=0. */ -if ((insn &0xa040c000u ) !=0x80000000u || - !dc_isar_feature (aa64_mte_insn_reg, s)) { -unallocated_encoding (s); -return ; - } - - imm = uimm6 <<LOG2_TAG_GRANULE ; + imm = a->uimm6 <<LOG2_TAG_GRANULE ;if (sub_op) { imm = -imm; } - tcg_rn =cpu_reg_sp (s, rn); - tcg_rd =cpu_reg_sp (s, rd); + tcg_rn =cpu_reg_sp (s, a->rn); + tcg_rd =cpu_reg_sp (s, a->rd);if (s->ata) {gen_helper_addsubg (tcg_rd, cpu_env, tcg_rn,tcg_constant_i32 (imm), -tcg_constant_i32 (uimm4)); +tcg_constant_i32 (a->uimm4)); }else {tcg_gen_addi_i64 (tcg_rd, tcg_rn, imm);gen_address_with_allocation_tag0 (tcg_rd, tcg_rd); } +return true; } +TRANS_FEAT(ADDG_i, aa64_mte_insn_reg, gen_add_sub_imm_with_tags, a, false) +TRANS_FEAT (SUBG_i, aa64_mte_insn_reg, gen_add_sub_imm_with_tags, a, true) +/* The input should be a value in the bottom e bits (with higher * bits zero); returns that value replicated into every element * of size e in a 64 bit integer.
@@ -4638,9 +4625,6 @@ static void disas_extract(DisasContext *s, uint32_t insn)static void disas_data_proc_imm (DisasContext *s,uint32_t insn) {switch (extract32 (insn,23 ,6 )) { -case 0x23 :/* Add/subtract (immediate, with tags) */ -disas_add_sub_imm_with_tags (s, insn); -break ;case 0x24 :/* Logical (immediate) */ disas_logic_imm (s, insn);break ;
Signature · 1 line
2.34.1
PATCH 8/20 target/arm: Replace bitmask64 with MAKE_64BIT_MASK
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Use the bitops.h macro rather than rolling our own here.
--- target/arm/tcg/translate-a64.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
target/arm/tcg/translate-a64.c +2 -9
@@ -4288,13 +4288,6 @@ static uint64_t bitfield_replicate(uint64_t mask, unsigned int e)return mask; } -/* Return a value with the bottom len bits set (where 0 < len <= 64) */ -static inline uint64_t bitmask64 (unsigned int length) -{ -assert (length >0 && length <=64 ); -return ~0ULL >> (64 - length); -} -/* Simplified variant of pseudocode DecodeBitMasks() for the case where we * only require the wmask. Returns false if the imms/immr/immn are a reserved * value (ie should cause a guest UNDEF exception), and true if they are
@@ -4350,10 +4343,10 @@ bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn,/* Create the value of one element: s+1 set bits rotated * by r within the element (which is e bits wide)... */ - mask =bitmask64 (s +1 ); + mask =MAKE_64BIT_MASK (0 , s +1 );if (r) { mask = (mask >> r) | (mask << (e - r)); - mask &=bitmask64 (e); + mask &=MAKE_64BIT_MASK (0 , e); }/* ...then replicate the element over the whole 64 bit value */ mask =bitfield_replicate (mask, e);
Signature · 1 line
2.34.1
PATCH 9/20 target/arm: Convert Logical (immediate) to decodetree
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Convert the ADD, ORR, EOR, ANDS (immediate) instructions.
--- target/arm/tcg/a64.decode | 15 ++++++ target/arm/tcg/translate-a64.c | 94 +++++++++++----------------------- 2 files changed, 44 insertions(+), 65 deletions(-)
target/arm/tcg/a64.decode +15 -0
@@ -56,3 +56,18 @@ SUBS_i . 11 100010 1 ............ ..... ..... @addsub_imm12 ADDG_i 1 00 100011 0 ...... 00 .... ..... ..... @addsub_imm_tag SUBG_i 1 10 100011 0 ...... 00 .... ..... ..... @addsub_imm_tag + +# Logical (immediate) + +&rri_log rd rn sf dbm +@logic_imm_64 1 .. ...... dbm:13 rn:5 rd:5 &rri_log sf=1 +@logic_imm_32 0 .. ...... 0 dbm:12 rn:5 rd:5 &rri_log sf=0 + +AND_i . 00 100100 . ...... ...... ..... ..... @logic_imm_64 +AND_i . 00 100100 . ...... ...... ..... ..... @logic_imm_32 +ORR_i . 01 100100 . ...... ...... ..... ..... @logic_imm_64 +ORR_i . 01 100100 . ...... ...... ..... ..... @logic_imm_32 +EOR_i . 10 100100 . ...... ...... ..... ..... @logic_imm_64 +EOR_i . 10 100100 . ...... ...... ..... ..... @logic_imm_32 +ANDS_i . 11 100100 . ...... ...... ..... ..... @logic_imm_64 +ANDS_i . 11 100100 . ...... ...... ..... ..... @logic_imm_32
target/arm/tcg/translate-a64.c +29 -65
123 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 10/20 target/arm: Convert Move wide (immediate) to decodetree
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Convert the MON, MOVZ, MOVK instructions.
--- target/arm/tcg/a64.decode | 13 ++++++ target/arm/tcg/translate-a64.c | 73 ++++++++++++++-------------------- 2 files changed, 42 insertions(+), 44 deletions(-)
target/arm/tcg/a64.decode +13 -0
@@ -71,3 +71,16 @@ EOR_i . 10 100100 . ...... ...... ..... ..... @logic_imm_64 EOR_i . 10 100100 . ...... ...... ..... ..... @logic_imm_32 ANDS_i . 11 100100 . ...... ...... ..... ..... @logic_imm_64 ANDS_i . 11 100100 . ...... ...... ..... ..... @logic_imm_32 + +# Move wide (immediate) + +&movw rd sf imm hw +@movw_64 1 .. ...... hw:2 imm:16 rd:5 &movw sf=1 +@movw_32 0 .. ...... 0 hw:1 imm:16 rd:5 &movw sf=0 + +MOVN . 00 100101 .. ................ ..... @movw_64 +MOVN . 00 100101 .. ................ ..... @movw_32 +MOVZ . 10 100101 .. ................ ..... @movw_64 +MOVZ . 10 100101 .. ................ ..... @movw_32 +MOVK . 11 100101 .. ................ ..... @movw_64 +MOVK . 11 100101 .. ................ ..... @movw_32
target/arm/tcg/translate-a64.c +29 -44
90 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 11/20 target/arm: Convert Bitfield to decodetree
In reply to Peter MaydellFrom: Richard Henderson <[email protected]>
Convert the BFM, SBFM, UBFM instructions.
--- target/arm/tcg/a64.decode | 13 +++ target/arm/tcg/translate-a64.c | 144 ++++++++++++++++++--------------- 2 files changed, 94 insertions(+), 63 deletions(-)
target/arm/tcg/a64.decode +13 -0
@@ -84,3 +84,16 @@ MOVZ . 10 100101 .. ................ ..... @movw_64 MOVZ . 10 100101 .. ................ ..... @movw_32 MOVK . 11 100101 .. ................ ..... @movw_64 MOVK . 11 100101 .. ................ ..... @movw_32 + +# Bitfield + +&bitfield rd rn sf immr imms +@bitfield_64 1 .. ...... 1 immr:6 imms:6 rn:5 rd:5 &bitfield sf=1 +@bitfield_32 0 .. ...... 0 0 immr:5 0 imms:5 rn:5 rd:5 &bitfield sf=0 + +SBFM . 00 100110 . ...... ...... ..... ..... @bitfield_64 +SBFM . 00 100110 . ...... ...... ..... ..... @bitfield_32 +BFM . 01 100110 . ...... ...... ..... ..... @bitfield_64 +BFM . 01 100110 . ...... ...... ..... ..... @bitfield_32 +UBFM . 10 100110 . ...... ...... ..... ..... @bitfield_64 +UBFM . 10 100110 . ...... ...... ..... ..... @bitfield_32
target/arm/tcg/translate-a64.c +81 -63
172 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 12/20 target/arm: Convert Extract instructions to decodetree
In reply to Peter MaydellConvert the EXTR instruction to decodetree (this is the only one in the 'Extract" class). This is the last of the dp-immediate insns in the legacy decoder, so we can now remove disas_data_proc_imm().
--- target/arm/tcg/a64.decode | 9 ++++ target/arm/tcg/translate-a64.c | 94 +++++++++++----------------------- 2 files changed, 38 insertions(+), 65 deletions(-)
target/arm/tcg/a64.decode +9 -0
@@ -97,3 +97,12 @@ BFM . 01 100110 . ...... ...... ..... ..... @bitfield_64 BFM . 01 100110 . ...... ...... ..... ..... @bitfield_32 UBFM . 10 100110 . ...... ...... ..... ..... @bitfield_64 UBFM . 10 100110 . ...... ...... ..... ..... @bitfield_32 + +# Extract + +&extract rd rn rm imm sf +@extract_64 1 .. ...... 1 . rm:5 imm:6 rn:5 rd:5 &extract sf=1 +@extract_32 0 .. ...... 0 . rm:5 0 imm:5 rn:5 rd:5 &extract sf=0 + +EXTR . 00 100111 . 0 ..... ...... ..... ..... @extract_64 +EXTR . 00 100111 . 0 ..... ...... ..... ..... @extract_32
target/arm/tcg/translate-a64.c +29 -65
115 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 12/20] target/arm: Convert Extract instructions to decodetree
target/arm/tcg/a64.decode BFM . 01 100110 . ...... ...... ..... ..... @bitfield_64 · line 108
Quoted 8 lines · Peter Maydell
target/arm/tcg/a64.decode +8
-0+# Extract + +&extract rd rn rm imm sf +@extract_64 1 .. ...... 1 . rm:5 imm:6 rn:5 rd:5 &extract sf=1 +@extract_32 0 .. ...... 0 . rm:5 0 imm:5 rn:5 rd:5 &extract sf=0 + +EXTR . 00 100111 . 0 ..... ...... ..... ..... @extract_64 +EXTR . 00 100111 . 0 ..... ...... ..... ..... @extract_32
When there's exactly one use of the @format, it might be clearer to just merge the two
EXTR 1 00 100111 1 0 rm:5 imm:6 rn:5 rd:5 &extract sf=1
Either way,
r~
PATCH 13/20 target/arm: Convert unconditional branch immediate to decodetree
In reply to Peter MaydellConvert the unconditional branch immediate insns B and BL to decodetree.
--- target/arm/tcg/a64.decode | 9 +++++++++ target/arm/tcg/translate-a64.c | 31 +++++++++++-------------------- 2 files changed, 20 insertions(+), 20 deletions(-)
target/arm/tcg/a64.decode +9 -0
@@ -21,6 +21,7 @@ &ri rd imm &rri_sf rd rn imm sf +&i imm ### Data Processing - Immediate
@@ -106,3 +107,11 @@ UBFM . 10 100110 . ...... ...... ..... ..... @bitfield_32 EXTR . 00 100111 . 0 ..... ...... ..... ..... @extract_64 EXTR . 00 100111 . 0 ..... ...... ..... ..... @extract_32 + +# Branches + +%imm26 0:s26 !function=times_4 +@branch . ..... .......................... &i imm=%imm26 + +B 0 00101 .......................... @branch +BL 1 00101 .......................... @branch
target/arm/tcg/translate-a64.c +11 -20
@@ -1319,24 +1319,19 @@ static inline AArch64DecodeFn *lookup_disas_fn(const AArch64DecodeTable *table,* match up with those in the manual. */ -/* Unconditional branch (immediate) -* 31 30 26 25 0 -* +----+-----------+-------------------------------------+ -* | op | 0 0 1 0 1 | imm26 | -* +----+-----------+-------------------------------------+ -*/ -static void disas_uncond_b_imm (DisasContext *s,uint32_t insn) +static bool trans_B (DisasContext *s,arg_i *a) { -int64_t diff =sextract32 (insn,0 ,26 ) *4 ; - -if (insn & (1U <<31 )) { -/* BL Branch with link */ -gen_pc_plus_diff (s,cpu_reg (s,30 ),curr_insn_len (s)); - } - -/* B Branch / BL Branch with link */ reset_btype (s); -gen_goto_tb (s,0 , diff); +gen_goto_tb (s,0 , a->imm); +return true; +} + +static bool trans_BL (DisasContext *s,arg_i *a) +{ +gen_pc_plus_diff (s,cpu_reg (s,30 ),curr_insn_len (s)); +reset_btype (s); +gen_goto_tb (s,0 , a->imm); +return true; }/* Compare and branch (immediate)
@@ -2413,10 +2408,6 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)static void disas_b_exc_sys (DisasContext *s,uint32_t insn) {switch (extract32 (insn,25 ,7 )) { -case 0x0a :case 0x0b : -case 0x4a :case 0x4b :/* Unconditional branch (immediate) */ -disas_uncond_b_imm (s, insn); -break ;case 0x1a :case 0x5a :/* Compare & branch (immediate) */ disas_comp_b_imm (s, insn);break ;
Signature · 1 line
2.34.1
Re: [PATCH 13/20] target/arm: Convert unconditional branch immediate to decodetree
Quoted 8 lines · Peter Maydell
Convert the unconditional branch immediate insns B and BL to decodetree.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/a64.decode | 9 +++++++++ target/arm/tcg/translate-a64.c | 31 +++++++++++-------------------- 2 files changed, 20 insertions(+), 20 deletions(-)
r~
PATCH 14/20 target/arm: Convert CBZ, CBNZ to decodetree
In reply to Peter MaydellConvert the compare-and-branch-immediate insns CBZ and CBNZ to decodetree.
--- target/arm/tcg/a64.decode | 6 ++++++ target/arm/tcg/translate-a64.c | 26 ++++++-------------------- 2 files changed, 12 insertions(+), 20 deletions(-)
target/arm/tcg/a64.decode +6 -0
@@ -115,3 +115,9 @@ EXTR . 00 100111 . 0 ..... ...... ..... ..... @extract_32 B 0 00101 .......................... @branch BL 1 00101 .......................... @branch + +%imm19 5:s19 !function=times_4 +&cbz rt imm sf nz +@cbz sf:1 ...... nz:1 ................... rt:5 &cbz imm=%imm19 + +CBZ . 011010 . ................... ..... @cbz
target/arm/tcg/translate-a64.c +6 -20
@@ -1334,33 +1334,22 @@ static bool trans_BL(DisasContext *s, arg_i *a)return true; } -/* Compare and branch (immediate) -* 31 30 25 24 23 5 4 0 -* +----+-------------+----+---------------------+--------+ -* | sf | 0 1 1 0 1 0 | op | imm19 | Rt | -* +----+-------------+----+---------------------+--------+ -*/ -static void disas_comp_b_imm (DisasContext *s,uint32_t insn) + +static bool trans_CBZ (DisasContext *s,arg_cbz *a) { -unsigned int sf, op, rt; -int64_t diff;DisasLabel match;TCGv_i64 tcg_cmp; - sf =extract32 (insn,31 ,1 ); - op =extract32 (insn,24 ,1 );/* 0: CBZ; 1: CBNZ */ - rt =extract32 (insn,0 ,5 ); - diff =sextract32 (insn,5 ,19 ) *4 ; - - tcg_cmp =read_cpu_reg (s, rt, sf); + tcg_cmp =read_cpu_reg (s, a->rt, a->sf);reset_btype (s); match =gen_disas_label (s); -tcg_gen_brcondi_i64 (op ?TCG_COND_NE :TCG_COND_EQ , +tcg_gen_brcondi_i64 (a->nz ?TCG_COND_NE :TCG_COND_EQ , tcg_cmp,0 , match.label);gen_goto_tb (s,0 ,4 );set_disas_label (s, match); -gen_goto_tb (s,1 , diff); +gen_goto_tb (s,1 , a->imm); +return true; }/* Test and branch (immediate)
@@ -2408,9 +2397,6 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)static void disas_b_exc_sys (DisasContext *s,uint32_t insn) {switch (extract32 (insn,25 ,7 )) { -case 0x1a :case 0x5a :/* Compare & branch (immediate) */ -disas_comp_b_imm (s, insn); -break ;case 0x1b :case 0x5b :/* Test & branch (immediate) */ disas_test_b_imm (s, insn);break ;
Signature · 1 line
2.34.1
Re: [PATCH 14/20] target/arm: Convert CBZ, CBNZ to decodetree
Review
Quoted 3 lines · Peter Maydell
+@cbz sf:1 ...... nz:1 ................... rt:5 &cbz imm=%imm19
(quoted diff) +2
-0+ +CBZ . 011010 . ................... ..... @cbz
Similarly re the single-use @format.
Either way,
r~
PATCH 15/20 target/arm: Convert TBZ, TBNZ to decodetree
In reply to Peter MaydellConvert the test-and-branch-immediate insns TBZ and TBNZ to decodetree.
--- target/arm/tcg/a64.decode | 7 +++++++ target/arm/tcg/translate-a64.c | 25 +++++-------------------- 2 files changed, 12 insertions(+), 20 deletions(-)
target/arm/tcg/a64.decode +7 -0
@@ -121,3 +121,10 @@ BL 1 00101 .......................... @branch @cbz sf:1 ...... nz:1 ................... rt:5 &cbz imm=%imm19 CBZ . 011010 . ................... ..... @cbz + +%imm14 5:s14 !function=times_4 +%imm31_19 31:1 19:5 +&tbz rt imm nz bitpos +@tbz . ...... nz:1 ..... .............. rt:5 &tbz imm=%imm14 bitpos=%imm31_19 + +TBZ . 011011 . ..... .............. ..... @tbz
target/arm/tcg/translate-a64.c +5 -20
@@ -1352,35 +1352,23 @@ static bool trans_CBZ(DisasContext *s, arg_cbz *a)return true; } -/* Test and branch (immediate) -* 31 30 25 24 23 19 18 5 4 0 -* +----+-------------+----+-------+-------------+------+ -* | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt | -* +----+-------------+----+-------+-------------+------+ -*/ -static void disas_test_b_imm (DisasContext *s,uint32_t insn) +static bool trans_TBZ (DisasContext *s,arg_tbz *a) { -unsigned int bit_pos, op, rt; -int64_t diff;DisasLabel match;TCGv_i64 tcg_cmp; - bit_pos = (extract32 (insn,31 ,1 ) <<5 ) |extract32 (insn,19 ,5 ); - op =extract32 (insn,24 ,1 );/* 0: TBZ; 1: TBNZ */ - diff =sextract32 (insn,5 ,14 ) *4 ; - rt =extract32 (insn,0 ,5 ); - tcg_cmp =tcg_temp_new_i64 (); -tcg_gen_andi_i64 (tcg_cmp,cpu_reg (s, rt), (1ULL << bit_pos)); +tcg_gen_andi_i64 (tcg_cmp,cpu_reg (s, a->rt), (1ULL << a->bitpos));reset_btype (s); match =gen_disas_label (s); -tcg_gen_brcondi_i64 (op ?TCG_COND_NE :TCG_COND_EQ , +tcg_gen_brcondi_i64 (a->nz ?TCG_COND_NE :TCG_COND_EQ , tcg_cmp,0 , match.label);gen_goto_tb (s,0 ,4 );set_disas_label (s, match); -gen_goto_tb (s,1 , diff); +gen_goto_tb (s,1 , a->imm); +return true; }/* Conditional branch (immediate)
@@ -2397,9 +2385,6 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)static void disas_b_exc_sys (DisasContext *s,uint32_t insn) {switch (extract32 (insn,25 ,7 )) { -case 0x1b :case 0x5b :/* Test & branch (immediate) */ -disas_test_b_imm (s, insn); -break ;case 0x2a :/* Conditional branch (immediate) */ disas_cond_b_imm (s, insn);break ;
Signature · 1 line
2.34.1
Re: [PATCH 15/20] target/arm: Convert TBZ, TBNZ to decodetree
Quoted 14 lines · Peter Maydell
Convert the test-and-branch-immediate insns TBZ and TBNZ to decodetree.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/tcg/a64.decode | 7 +++++++ target/arm/tcg/translate-a64.c | 25 +++++-------------------- 2 files changed, 12 insertions(+), 20 deletions(-)target/arm/tcg/a64.decode +0
-0
target/arm/tcg/a64.decode BL 1 00101 .......................... @branch · line 130
Quoted 10 lines
target/arm/tcg/a64.decode +7
-0@@ -121,3 +121,10 @@ BL 1 00101 .......................... @branch @cbz sf:1 ...... nz:1 ................... rt:5 &cbz imm=%imm19 CBZ . 011010 . ................... ..... @cbz + +%imm14 5:s14 !function=times_4 +%imm31_19 31:1 19:5 +&tbz rt imm nz bitpos +@tbz . ...... nz:1 ..... .............. rt:5 &tbz imm=%imm14 bitpos=%imm31_19 + +TBZ . 011011 . ..... .............. ..... @tbz
Similarly with the single-use @format.
target/arm/tcg/a64.decode
Quoted 2 lines
target/arm/tcg/a64.decode +1
-1- tcg_gen_andi_i64(tcg_cmp, cpu_reg(s, rt), (1ULL << bit_pos)); + tcg_gen_andi_i64(tcg_cmp, cpu_reg(s, a->rt), (1ULL << a->bitpos));
Can we drop the () around the bit, or use BIT()?.
Otherwise,
r~
PATCH 16/20 target/arm: Convert conditional branch insns to decodetree
In reply to Peter MaydellConvert the immediate conditional branch insn B.cond to decodetree.
--- target/arm/tcg/a64.decode | 2 ++ target/arm/tcg/translate-a64.c | 30 ++++++------------------------ 2 files changed, 8 insertions(+), 24 deletions(-)
target/arm/tcg/a64.decode +2 -0
@@ -128,3 +128,5 @@ CBZ . 011010 . ................... ..... @cbz @tbz . ...... nz:1 ..... .............. rt:5 &tbz imm=%imm14 bitpos=%imm31_19 TBZ . 011011 . ..... .............. ..... @tbz + +B_cond 0101010 0 ................... 0 cond:4 imm=%imm19
target/arm/tcg/translate-a64.c +6 -24
@@ -1371,36 +1371,21 @@ static bool trans_TBZ(DisasContext *s, arg_tbz *a)return true; } -/* Conditional branch (immediate) -* 31 25 24 23 5 4 3 0 -* +---------------+----+---------------------+----+------+ -* | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond | -* +---------------+----+---------------------+----+------+ -*/ -static void disas_cond_b_imm (DisasContext *s,uint32_t insn) +static bool trans_B_cond (DisasContext *s,arg_B_cond *a) { -unsigned int cond; -int64_t diff; - -if ((insn & (1 <<4 )) || (insn & (1 <<24 ))) { -unallocated_encoding (s); -return ; - } - diff =sextract32 (insn,5 ,19 ) *4 ; - cond =extract32 (insn,0 ,4 ); -reset_btype (s); -if (cond <0x0e ) { +if (a->cond <0x0e ) {/* genuinely conditional branches */ DisasLabel match =gen_disas_label (s); -arm_gen_test_cc (cond, match.label); +arm_gen_test_cc (a->cond, match.label);gen_goto_tb (s,0 ,4 );set_disas_label (s, match); -gen_goto_tb (s,1 , diff); +gen_goto_tb (s,1 , a->imm); }else {/* 0xe and 0xf are both "always" conditions */ -gen_goto_tb (s,0 , diff); +gen_goto_tb (s,0 , a->imm); } +return true; }/* HINT instruction group, including various allocated HINTs */
@@ -2385,9 +2370,6 @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)static void disas_b_exc_sys (DisasContext *s,uint32_t insn) {switch (extract32 (insn,25 ,7 )) { -case 0x2a :/* Conditional branch (immediate) */ -disas_cond_b_imm (s, insn); -break ;case 0x6a :/* Exception generation / System */ if (insn & (1 <<24 )) {if (extract32 (insn,22 ,2 ) ==0 ) {
Signature · 1 line
2.34.1
Re: [PATCH 16/20] target/arm: Convert conditional branch insns to decodetree
Quoted 8 lines · Peter Maydell
Convert the immediate conditional branch insn B.cond to decodetree.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/a64.decode | 2 ++ target/arm/tcg/translate-a64.c | 30 ++++++------------------------ 2 files changed, 8 insertions(+), 24 deletions(-)
r~
PATCH 17/20 target/arm: Convert BR, BLR, RET to decodetree
In reply to Peter MaydellConvert the simple (non-pointer-auth) BR, BLR and RET insns to decodetree.
--- target/arm/tcg/a64.decode | 5 ++++ target/arm/tcg/translate-a64.c | 55 ++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 6 deletions(-)
target/arm/tcg/a64.decode +5 -0
@@ -19,6 +19,7 @@ # This file is processed by scripts/decodetree.py # +&r rn &ri rd imm &rri_sf rd rn imm sf &i imm
@@ -130,3 +131,7 @@ CBZ . 011010 . ................... ..... @cbz TBZ . 011011 . ..... .............. ..... @tbz B_cond 0101010 0 ................... 0 cond:4 imm=%imm19 + +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
target/arm/tcg/translate-a64.c +49 -6
67 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 17/20] target/arm: Convert BR, BLR, RET to decodetree
Quoted 8 lines · Peter Maydell
Convert the simple (non-pointer-auth) BR, BLR and RET insns to decodetree.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/a64.decode | 5 ++++ target/arm/tcg/translate-a64.c | 55 ++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 6 deletions(-)
r~
PATCH 18/20 target/arm: Convert BRA[AB]Z, BLR[AB]Z, RETA[AB] to decodetree
In reply to Peter MaydellConvert the single-register pointer-authentication variants of BR, BLR, RET to decodetree. (BRAA/BLRAA are in a different branch of the legacy decoder and will be dealt with in the next commit.)
--- target/arm/tcg/a64.decode | 7 ++ target/arm/tcg/translate-a64.c | 132 +++++++++++++++++++-------------- 2 files changed, 84 insertions(+), 55 deletions(-)
target/arm/tcg/a64.decode +7 -0
@@ -135,3 +135,10 @@ B_cond 0101010 0 ................... 0 cond:4 imm=%imm19 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 + +&braz rn m +BRAZ 1101011 0000 11111 00001 m:1 rn:5 11111 &braz # BRAAZ, BRABZ +BLRAZ 1101011 0001 11111 00001 m:1 rn:5 11111 &braz # BLRAAZ, BLRABZ + +&reta m +RETA 1101011 0010 11111 00001 m:1 11111 11111 &reta # RETAA, RETAB
target/arm/tcg/translate-a64.c +77 -55
144 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 18/20] target/arm: Convert BRA[AB]Z, BLR[AB]Z, RETA[AB] to decodetree
Quoted 9 lines · Peter Maydell
Convert the single-register pointer-authentication variants of BR, BLR, RET to decodetree. (BRAA/BLRAA are in a different branch of the legacy decoder and will be dealt with in the next commit.)
Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/a64.decode | 7 ++ target/arm/tcg/translate-a64.c | 132 +++++++++++++++++++-------------- 2 files changed, 84 insertions(+), 55 deletions(-)
r~
PATCH 19/20 target/arm: Convert BRAA, BRAB, BLRAA, BLRAB to decodetree
In reply to Peter MaydellConvert the last four BR-with-pointer-auth insns to decodetree. The remaining cases in the outer switch in disas_uncond_b_reg() all return early rather than leaving the case statement, so we can delete the now-unused code at the end of that function.
--- target/arm/tcg/a64.decode | 4 ++ target/arm/tcg/translate-a64.c | 97 ++++++++++++++-------------------- 2 files changed, 43 insertions(+), 58 deletions(-)
target/arm/tcg/a64.decode +4 -0
@@ -142,3 +142,7 @@ BLRAZ 1101011 0001 11111 00001 m:1 rn:5 11111 &braz # BLRAAZ, BLRABZ &reta m RETA 1101011 0010 11111 00001 m:1 11111 11111 &reta # RETAA, RETAB + +&bra rn rm m +BRA 1101011 1000 11111 00001 m:1 rn:5 rm:5 &bra # BRAA, BRAB +BLRA 1101011 1001 11111 00001 m:1 rn:5 rm:5 &bra # BLRAA, BLRAB
target/arm/tcg/translate-a64.c +39 -58
125 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 19/20] target/arm: Convert BRAA, BRAB, BLRAA, BLRAB to decodetree
Quoted 10 lines · Peter Maydell
Convert the last four BR-with-pointer-auth insns to decodetree. The remaining cases in the outer switch in
disas_uncond_b_reg()all return early rather than leaving the case statement, so we can delete the now-unused code at the end of that function.Signed-off-by Peter Maydell<[email protected]>--- target/arm/tcg/a64.decode | 4 ++ target/arm/tcg/translate-a64.c | 97 ++++++++++++++-------------------- 2 files changed, 43 insertions(+), 58 deletions(-)
r~
PATCH 20/20 target/arm: Convert ERET, ERETAA, ERETAB to decodetree
In reply to Peter MaydellConvert the exception-return insns ERET, ERETA and ERETB to decodetree. These were the last insns left in the legacy decoder function disas_uncond_reg_b(), which allows us to remove it.
The old decoder explicitly decoded the DRPS instruction, only in order to call unallocated_encoding() on it, exactly as would have happened if it hadn't decoded it. This is because this insn always UNDEFs unless the CPU is in halting-debug state, which we don't emulate. So we list the pattern in a comment in a64.decode, but don't actively decode it.
--- target/arm/tcg/a64.decode | 8 ++ target/arm/tcg/translate-a64.c | 160 +++++++++++---------------------- 2 files changed, 60 insertions(+), 108 deletions(-)
target/arm/tcg/a64.decode +8 -0
@@ -146,3 +146,11 @@ RETA 1101011 0010 11111 00001 m:1 11111 11111 &reta # RETAA, RETAB &bra rn rm m BRA 1101011 1000 11111 00001 m:1 rn:5 rm:5 &bra # BRAA, BRAB BLRA 1101011 1001 11111 00001 m:1 rn:5 rm:5 &bra # BLRAA, BLRAB + +ERET 1101011 0100 11111 000000 11111 00000 +ERETA 1101011 0100 11111 00001 m:1 11111 11111 &reta # ERETAA, ERETAB + +# We don't need to decode DRPS because it always UNDEFs except when +# the processor is in halting debug state (which we don't implement). +# The pattern is listed here as documentation. +# DRPS 1101011 0101 11111 000000 11111 00000
target/arm/tcg/translate-a64.c +52 -108
178 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 20/20] target/arm: Convert ERET, ERETAA, ERETAB to decodetree
target/arm/tcg/translate-a64.c static bool trans_BLRA(DisasContext *s, arg_bra *a) · line 1578
Quoted 12 lines · Peter Maydell
target/arm/tcg/translate-a64.c +12
-0+static bool trans_ERETA (DisasContext *s,arg_reta *a) +{ +TCGv_i64 dst; + +if (!dc_isar_feature (aa64_pauth, s)) { +return false; + } +/* The FGT trap takes precedence over an auth trap. */ +if (s->fgt_eret) { +gen_exception_insn_el (s,0 ,EXCP_UDEF , a->m ?3 :2 ,2 ); +return true; + }
Missing el0 exception, before fgt trap.
Otherwise,
r~