target/hexagon: introduce idef-parser
v4 cover target/hexagon: introduce idef-parser
From: Alessandro Di Federico <[email protected]>
This patchset introduces the idef-parser for target/hexagon.
It's the fourth iteration of the patchset and includes fixes suggested in previous iterations.
idef-parser is a build-time tool built using flex and bison. Its aim is to generate a large part of the tiny code generator frontend for Hexagon. The prototype of idef-parser has been presented at KVM Forum 2019 ("QEMU-Hexagon: Automatic Translation of the ISA Manual Pseudcode to Tiny Code Instructions"):
https://www.youtube.com/watch?v=3EpnTYBOXCI
target/hexagon/idef-parser/README.rst provides an overview of the parser and its inner working.
A couple of notes:
* idef-parser also supports certain things that are not used in the most recently submitted version of the "Hexagon patch series". However, they will be needed and stripping them out of the parser is quite a bit of work.
* The build on the CI fails for the cross-i386-* jobs. This seems to be due to the fact that, despite we specified glib as a native dependency, meson still chooses the i386 bit version of the library, as opposed to the x86-64.
Help on this matter is appreciated.
The clang-user build fails too, but seems to be due reasons not concerning this patchset.
* Unlike the last iteration of this patchset, we no longer use local temps, which were detrimental for performance. Now, in order to handle side effects in ternary operators, the parser keeps track of nested ternary operators and their conditions. We then exploit that information to turn the side effect itself into a movcond. This is done by emitting a series of and instructions on the nested ternary operator conditions.
Alessandro Di Federico (5):
tcg: expose TCGCond manipulation routines target/hexagon: update MAINTAINERS for idef-parser target/hexagon: import README for idef-parser target/hexagon: prepare input for the idef-parser target/hexagon: call idef-parser functions
Niccolò Izzo (2):
target/hexagon: introduce new helper functions
target/hexagon: import additional tests
Paolo Montesel (5):
target/hexagon: make slot number an unsigned target/hexagon: make helper functions non-static target/hexagon: expose next PC in DisasContext target/hexagon: import lexer for idef-parser target/hexagon: import parser for idef-parser
MAINTAINERS | 8 + include/tcg/tcg-cond.h | 101 + include/tcg/tcg.h | 70 +- target/hexagon/README | 5 + target/hexagon/gen_idef_parser_funcs.py | 114 + target/hexagon/gen_tcg_funcs.py | 28 +- target/hexagon/genptr.c | 201 +- target/hexagon/genptr.h | 28 + target/hexagon/hex_common.py | 10 + target/hexagon/idef-parser/README.rst | 447 ++++ target/hexagon/idef-parser/idef-parser.h | 254 ++ target/hexagon/idef-parser/idef-parser.lex | 611 +++++ target/hexagon/idef-parser/idef-parser.y | 947 +++++++ target/hexagon/idef-parser/macros.inc | 150 ++ target/hexagon/idef-parser/parser-helpers.c | 2374 +++++++++++++++++ target/hexagon/idef-parser/parser-helpers.h | 347 +++ target/hexagon/idef-parser/prepare | 24 + target/hexagon/macros.h | 11 +- target/hexagon/meson.build | 67 +- target/hexagon/translate.c | 3 +- target/hexagon/translate.h | 1 + tests/docker/dockerfiles/alpine.docker | 2 + tests/docker/dockerfiles/centos7.docker | 2 + tests/docker/dockerfiles/centos8.docker | 2 + tests/docker/dockerfiles/debian10.docker | 3 + .../dockerfiles/fedora-i386-cross.docker | 3 + .../dockerfiles/fedora-win32-cross.docker | 3 + .../dockerfiles/fedora-win64-cross.docker | 3 + tests/docker/dockerfiles/fedora.docker | 2 + tests/docker/dockerfiles/opensuse-leap.docker | 2 + tests/docker/dockerfiles/ubuntu.docker | 3 + tests/docker/dockerfiles/ubuntu1804.docker | 3 + tests/docker/dockerfiles/ubuntu2004.docker | 5 +- tests/tcg/hexagon/Makefile.target | 36 +- tests/tcg/hexagon/crt.S | 28 + tests/tcg/hexagon/test_abs.S | 20 + tests/tcg/hexagon/test_add.S | 20 + tests/tcg/hexagon/test_andp.S | 23 + tests/tcg/hexagon/test_bitcnt.S | 42 + tests/tcg/hexagon/test_bitsplit.S | 25 + tests/tcg/hexagon/test_call.S | 63 + tests/tcg/hexagon/test_clobber.S | 35 + tests/tcg/hexagon/test_cmp.S | 34 + tests/tcg/hexagon/test_cmpy.S | 31 + tests/tcg/hexagon/test_djump.S | 24 + tests/tcg/hexagon/test_dotnew.S | 39 + tests/tcg/hexagon/test_dstore.S | 29 + tests/tcg/hexagon/test_ext.S | 18 + tests/tcg/hexagon/test_fibonacci.S | 33 + tests/tcg/hexagon/test_hello.S | 21 + tests/tcg/hexagon/test_hl.S | 19 + tests/tcg/hexagon/test_hwloops.S | 25 + tests/tcg/hexagon/test_jmp.S | 25 + tests/tcg/hexagon/test_lsr.S | 39 + tests/tcg/hexagon/test_mpyi.S | 20 + tests/tcg/hexagon/test_overflow.S | 63 + tests/tcg/hexagon/test_packet.S | 26 + tests/tcg/hexagon/test_reorder.S | 31 + tests/tcg/hexagon/test_round.S | 31 + tests/tcg/hexagon/test_vavgw.S | 33 + tests/tcg/hexagon/test_vcmpb.S | 32 + tests/tcg/hexagon/test_vcmpw.S | 29 + tests/tcg/hexagon/test_vcmpy.S | 50 + tests/tcg/hexagon/test_vlsrw.S | 23 + tests/tcg/hexagon/test_vmaxh.S | 37 + tests/tcg/hexagon/test_vminh.S | 37 + tests/tcg/hexagon/test_vpmpyh.S | 30 + tests/tcg/hexagon/test_vspliceb.S | 33 + 68 files changed, 6849 insertions(+), 89 deletions(-) create mode 100644 include/tcg/tcg-cond.h create mode 100644 target/hexagon/gen_idef_parser_funcs.py create mode 100644 target/hexagon/idef-parser/README.rst create mode 100644 target/hexagon/idef-parser/idef-parser.h create mode 100644 target/hexagon/idef-parser/idef-parser.lex create mode 100644 target/hexagon/idef-parser/idef-parser.y create mode 100644 target/hexagon/idef-parser/macros.inc create mode 100644 target/hexagon/idef-parser/parser-helpers.c create mode 100644 target/hexagon/idef-parser/parser-helpers.h create mode 100755 target/hexagon/idef-parser/prepare create mode 100644 tests/tcg/hexagon/crt.S create mode 100644 tests/tcg/hexagon/test_abs.S create mode 100644 tests/tcg/hexagon/test_add.S create mode 100644 tests/tcg/hexagon/test_andp.S create mode 100644 tests/tcg/hexagon/test_bitcnt.S create mode 100644 tests/tcg/hexagon/test_bitsplit.S create mode 100644 tests/tcg/hexagon/test_call.S create mode 100644 tests/tcg/hexagon/test_clobber.S create mode 100644 tests/tcg/hexagon/test_cmp.S create mode 100644 tests/tcg/hexagon/test_cmpy.S create mode 100644 tests/tcg/hexagon/test_djump.S create mode 100644 tests/tcg/hexagon/test_dotnew.S create mode 100644 tests/tcg/hexagon/test_dstore.S create mode 100644 tests/tcg/hexagon/test_ext.S create mode 100644 tests/tcg/hexagon/test_fibonacci.S create mode 100644 tests/tcg/hexagon/test_hello.S create mode 100644 tests/tcg/hexagon/test_hl.S create mode 100644 tests/tcg/hexagon/test_hwloops.S create mode 100644 tests/tcg/hexagon/test_jmp.S create mode 100644 tests/tcg/hexagon/test_lsr.S create mode 100644 tests/tcg/hexagon/test_mpyi.S create mode 100644 tests/tcg/hexagon/test_overflow.S create mode 100644 tests/tcg/hexagon/test_packet.S create mode 100644 tests/tcg/hexagon/test_reorder.S create mode 100644 tests/tcg/hexagon/test_round.S create mode 100644 tests/tcg/hexagon/test_vavgw.S create mode 100644 tests/tcg/hexagon/test_vcmpb.S create mode 100644 tests/tcg/hexagon/test_vcmpw.S create mode 100644 tests/tcg/hexagon/test_vcmpy.S create mode 100644 tests/tcg/hexagon/test_vlsrw.S create mode 100644 tests/tcg/hexagon/test_vmaxh.S create mode 100644 tests/tcg/hexagon/test_vminh.S create mode 100644 tests/tcg/hexagon/test_vpmpyh.S create mode 100644 tests/tcg/hexagon/test_vspliceb.S
Signature · 1 line
2.31.1
PATCH v4 1/12 tcg: expose TCGCond manipulation routines
From: Alessandro Di Federico <[email protected]>
This commit moves into a separate file routines used to manipulate TCGCond. These will be employed by the idef-parser.
--- include/tcg/tcg-cond.h | 101 +++++++++++++++++++++++++++++++++++++++++ include/tcg/tcg.h | 70 +--------------------------- 2 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 include/tcg/tcg-cond.h
include/tcg/tcg-cond.h new file +101 -0
@@ -0,0 +1,101 @@ +/* +* Tiny Code Generator for QEMU +* +* Copyright (c) 2008 Fabrice Bellard +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#ifndef TCG_COND_H +#define TCG_COND_H + +/* +* Conditions. Note that these are laid out for easy manipulation by +* the functions below: +* bit 0 is used for inverting; +* bit 1 is signed, +* bit 2 is unsigned, +* bit 3 is used with bit 0 for swapping signed/unsigned. +*/ +typedef enum { +/* non-signed */ +TCG_COND_NEVER =0 |0 |0 |0 , +TCG_COND_ALWAYS =0 |0 |0 |1 , +TCG_COND_EQ =8 |0 |0 |0 , +TCG_COND_NE =8 |0 |0 |1 , +/* signed */ +TCG_COND_LT =0 |0 |2 |0 , +TCG_COND_GE =0 |0 |2 |1 , +TCG_COND_LE =8 |0 |2 |0 , +TCG_COND_GT =8 |0 |2 |1 , +/* unsigned */ +TCG_COND_LTU =0 |4 |0 |0 , +TCG_COND_GEU =0 |4 |0 |1 , +TCG_COND_LEU =8 |4 |0 |0 , +TCG_COND_GTU =8 |4 |0 |1 , +}TCGCond ; + +/* Invert the sense of the comparison. */ +static inline TCGCond tcg_invert_cond (TCGCond c) +{ +return (TCGCond)(c ^1 ); +} + +/* Swap the operands in a comparison. */ +static inline TCGCond tcg_swap_cond (TCGCond c) +{ +return c &6 ? (TCGCond)(c ^9 ) : c; +} + +/* Create an "unsigned" version of a "signed" comparison. */ +static inline TCGCond tcg_unsigned_cond (TCGCond c) +{ +return c &2 ? (TCGCond)(c ^6 ) : c; +} + +/* Create a "signed" version of an "unsigned" comparison. */ +static inline TCGCond tcg_signed_cond (TCGCond c) +{ +return c &4 ? (TCGCond)(c ^6 ) : c; +} + +/* Must a comparison be considered unsigned? */ +static inline bool is_unsigned_cond (TCGCond c) +{ +return (c &4 ) !=0 ; +} + +/* +* Create a "high" version of a double-word comparison. +* This removes equality from a LTE or GTE comparison. +*/ +static inline TCGCond tcg_high_cond (TCGCond c) +{ +switch (c) { +case TCG_COND_GE : +case TCG_COND_LE : +case TCG_COND_GEU : +case TCG_COND_LEU : +return (TCGCond)(c ^8 ); +default : +return c; + } +} + +#endif /* TCG_COND_H */
include/tcg/tcg.h +1 -69
82 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v4 01/12] tcg: expose TCGCond manipulation routines
Quoted 5 lines · Alessandro Di Federico
From: Alessandro Di Federico<[email protected]>
This commit moves into a separate file routines used to manipulate TCGCond. These will be employed by the idef-parser.
Quoted 7 lines
Signed-off-by Alessandro Di Federico<[email protected]>Signed-off-by Paolo Montesel<[email protected]>--- include/tcg/tcg-cond.h | 101 +++++++++++++++++++++++++++++++++++++++++ include/tcg/tcg.h | 70 +--------------------------- 2 files changed, 102 insertions(+), 69 deletions(-)create mode 100644
include/tcg/tcg-cond.h
r~
PATCH v4 2/12 target/hexagon: update MAINTAINERS for idef-parser
In reply to Alessandro Di Federico viaFrom: Alessandro Di Federico <[email protected]>
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -193,11 +193,19 @@ Hexagon TCG CPUs M: Taylor Simpson <[email protected]> S: Supported F: target/hexagon/ +X: target/hexagon/idef-parser/ +X: target/hexagon/gen_idef_parser_funcs.py F: linux-user/hexagon/ F: tests/tcg/hexagon/ F: disas/hexagon.c F: default-configs/targets/hexagon-linux-user.mak +Hexagon idef-parser +M: Alessandro Di Federico <[email protected]> +S: Supported +F: target/hexagon/idef-parser/ +F: target/hexagon/gen_idef_parser_funcs.py + HPPA (PA-RISC) TCG CPUs M: Richard Henderson <[email protected]> S: Maintained
Signature · 1 line
2.31.1
Re: [PATCH v4 02/12] target/hexagon: update MAINTAINERS for idef-parser
Quoted 6 lines · Alessandro Di Federico
From: Alessandro Di Federico<[email protected]>
Signed-off-by Alessandro Di Federico<[email protected]>--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
r~
PATCH v4 3/12 target/hexagon: import README for idef-parser
In reply to Alessandro Di Federico viaFrom: Alessandro Di Federico <[email protected]>
--- target/hexagon/README | 5 + target/hexagon/idef-parser/README.rst | 447 ++++++++++++++++++++++++++ 2 files changed, 452 insertions(+) create mode 100644 target/hexagon/idef-parser/README.rst
target/hexagon/README +5 -0
@@ -23,6 +23,10 @@ Hexagon-specific code are encode*.def Encoding patterns for each instruction iclass.def Instruction class definitions used to determine legal VLIW slots for each instruction + qemu/target/hexagon/idef-parser + Parser that, given the high-level definitions of an instruction, + produces a C function generating equivalent tiny code instructions. + See README.rst. qemu/linux-user/hexagon Helpers for loading the ELF file and making Linux system calls, signals, etc
@@ -43,6 +47,7 @@ header files in <BUILD_DIR>/target/hexagon gen_tcg_funcs.py -> tcg_funcs_generated.c.inc gen_tcg_func_table.py -> tcg_func_table_generated.c.inc gen_helper_funcs.py -> helper_funcs_generated.c.inc + gen_idef_parser_funcs.py -> idef_parser_input.h Qemu helper functions have 3 parts DEF_HELPER declaration indicates the signature of the helper
target/hexagon/idef-parser/README.rst new file +447 -0
447 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v4 4/12 target/hexagon: make slot number an unsigned
In reply to Alessandro Di Federico viaFrom: Paolo Montesel <[email protected]>
--- target/hexagon/genptr.c | 6 ++++-- target/hexagon/macros.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
target/hexagon/genptr.c +4 -2
@@ -33,7 +33,8 @@ static inline TCGv gen_read_preg(TCGv pred, uint8_t num)return pred; } -static inline void gen_log_predicated_reg_write (int rnum,TCGv val,int slot) +static inline void gen_log_predicated_reg_write (int rnum,TCGv val, +unsigned slot) {TCGv one =tcg_const_tl (1 );TCGv zero =tcg_const_tl (0 );
@@ -62,7 +63,8 @@ static inline void gen_log_reg_write(int rnum, TCGv val)#endif } -static void gen_log_predicated_reg_write_pair (int rnum,TCGv_i64 val,int slot) +static void gen_log_predicated_reg_write_pair (int rnum,TCGv_i64 val, +unsigned slot) {TCGv val32 =tcg_temp_new ();TCGv one =tcg_const_tl (1 );
target/hexagon/macros.h +1 -1
@@ -154,7 +154,7 @@#define LOAD_CANCEL (EA ) do { CANCEL; } while (0)#ifdef QEMU_GENERATE -static inline void gen_pred_cancel (TCGv pred,int slot_num) +static inline void gen_pred_cancel (TCGv pred,unsigned slot_num) {TCGv slot_mask =tcg_const_tl (1 << slot_num);TCGv tmp =tcg_temp_new ();
Signature · 1 line
2.31.1
Re: [PATCH v4 04/12] target/hexagon: make slot number an unsigned
Quoted 8 lines · Alessandro Di Federico
From: Paolo Montesel<[email protected]>
Signed-off-by Alessandro Di Federico<[email protected]>Signed-off-by Paolo Montesel<[email protected]>--- target/hexagon/genptr.c | 6 ++++-- target/hexagon/macros.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
r~
PATCH v4 5/12 target/hexagon: make helper functions non-static
In reply to Alessandro Di Federico viaFrom: Paolo Montesel <[email protected]>
Make certain helper functions non-static, making them available outside genptr.c. These functions are required by code generated by the idef-parser.
--- target/hexagon/genptr.c | 7 ++++--- target/hexagon/genptr.h | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-)
target/hexagon/genptr.c +4 -3
@@ -26,8 +26,9 @@#include "translate.h" #include "macros.h" #include "gen_tcg.h" +#include "genptr.h" -static inline TCGv gen_read_preg (TCGv pred,uint8_t num) +TCGv gen_read_preg (TCGv pred,uint8_t num) {tcg_gen_mov_tl (pred, hex_pred[num]);return pred;
@@ -54,7 +55,7 @@ static inline void gen_log_predicated_reg_write(int rnum, TCGv val,tcg_temp_free (slot_mask); } -static inline void gen_log_reg_write (int rnum,TCGv val) +void gen_log_reg_write (int rnum,TCGv val) {tcg_gen_mov_tl (hex_new_value[rnum], val);#if HEX_DEBUG
@@ -118,7 +119,7 @@ static void gen_log_reg_write_pair(int rnum, TCGv_i64 val)#endif } -static inline void gen_log_pred_write (int pnum,TCGv val) +void gen_log_pred_write (int pnum,TCGv val) {TCGv zero =tcg_const_tl (0 );TCGv base_val =tcg_temp_new ();
target/hexagon/genptr.h +6 -0
@@ -19,7 +19,13 @@#define HEXAGON_GENPTR_H #include "insn.h" +#include "tcg/tcg.h" +#include "translate.h" extern const SemanticInsn opcode_genptr[]; +TCGv gen_read_preg (TCGv pred,uint8_t num); +void gen_log_reg_write (int rnum,TCGv val); +void gen_log_pred_write (int pnum,TCGv val); +#endif
Signature · 1 line
2.31.1
Re: [PATCH v4 05/12] target/hexagon: make helper functions non-static
Quoted 6 lines · Alessandro Di Federico
From: Paolo Montesel<[email protected]>
Make certain helper functions non-static, making them available outside
genptr.c. These functions are required by code generated by the idef-parser.
Quoted 6 lines
Signed-off-by Alessandro Di Federico<[email protected]>Signed-off-by Paolo Montesel<[email protected]>--- target/hexagon/genptr.c | 7 ++++--- target/hexagon/genptr.h | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-)
r~
PATCH v4 6/12 target/hexagon: introduce new helper functions
In reply to Alessandro Di Federico viaFrom: Niccolò Izzo <[email protected]>
These helpers will be employed by the idef-parser generated code.
--- target/hexagon/genptr.c | 188 ++++++++++++++++++++++++++++++++++++++++ target/hexagon/genptr.h | 22 +++++ target/hexagon/macros.h | 9 ++ 3 files changed, 219 insertions(+)
target/hexagon/genptr.c +188 -0
@@ -28,6 +28,12 @@#include "gen_tcg.h" #include "genptr.h" +TCGv gen_read_reg (TCGv result,int num) +{ +tcg_gen_mov_tl (result, hex_gpr[num]); +return result; +} +TCGv gen_read_preg (TCGv pred,uint8_t num) {tcg_gen_mov_tl (pred, hex_pred[num]);
@@ -330,5 +336,187 @@ static inline void gen_store_conditional8(CPUHexagonState *env,tcg_gen_movi_tl (hex_llsc_addr, ~0 ); } +void gen_store32 (TCGv vaddr,TCGv src,tcg_target_long width,unsigned slot) +{ +tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_movi_tl (hex_store_width[slot], width); +tcg_gen_mov_tl (hex_store_val32[slot], src); +} + +void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +unsigned slot) +{ +gen_store32 (vaddr, src,1 , slot); + ctx->store_width[slot] =1 ; +} + +void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +unsigned slot) +{ +gen_store32 (vaddr, src,2 , slot); + ctx->store_width[slot] =2 ; +} + +void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +unsigned slot) +{ +gen_store32 (vaddr, src,4 , slot); + ctx->store_width[slot] =4 ; +} + + +void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,DisasContext *ctx, +unsigned slot) +{ +tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_movi_tl (hex_store_width[slot],8 ); +tcg_gen_mov_i64 (hex_store_val64[slot], src); + ctx->store_width[slot] =8 ; +} + +void gen_set_usr_field (int field,TCGv val) +{ +tcg_gen_deposit_tl (hex_gpr[HEX_REG_USR ], hex_gpr[HEX_REG_USR ], val, + reg_field_info[field].offset, + reg_field_info[field].width); +} + +void gen_set_usr_fieldi (int field,int x) +{ +TCGv val =tcg_const_tl (x); +gen_set_usr_field (field, val); +tcg_temp_free (val); +} + +void gen_write_new_pc (TCGv addr) +{ +/* If there are multiple branches in a packet, ignore the second one */ +TCGv zero =tcg_const_tl (0 ); +tcg_gen_movcond_tl (TCG_COND_NE , hex_next_PC, hex_branch_taken, zero, + hex_next_PC, addr); +tcg_gen_movi_tl (hex_branch_taken,1 ); +tcg_temp_free (zero); +} + +void gen_sat_i32 (TCGv dest,TCGv source,int width) +{ +TCGv max_val =tcg_const_i32 ((1 << (width -1 )) -1 ); +TCGv min_val =tcg_const_i32 (-(1 << (width -1 ))); +tcg_gen_smin_tl (dest, source, max_val); +tcg_gen_smax_tl (dest, dest, min_val); +tcg_temp_free_i32 (max_val); +tcg_temp_free_i32 (min_val); +} + +void gen_sat_i32_ext (TCGv ovfl,TCGv dest,TCGv source,int width) +{ +gen_sat_i32 (dest, source, width); +TCGv zero =tcg_const_i32 (0 ); +TCGv one =tcg_const_i32 (1 ); +tcg_gen_movcond_i32 (TCG_COND_NE , ovfl, source, dest, one, zero); +tcg_temp_free_i32 (zero); +tcg_temp_free_i32 (one); +} + +void gen_satu_i32 (TCGv dest,TCGv source,int width) +{ +TCGv max_val =tcg_const_i32 ((1 << width) -1 ); +tcg_gen_movcond_i32 (TCG_COND_GTU , dest, source, max_val, max_val, source); +TCGv_i32 zero =tcg_const_i32 (0 ); +tcg_gen_movcond_i32 (TCG_COND_LT , dest, source, zero, zero, dest); +tcg_temp_free_i32 (max_val); +tcg_temp_free_i32 (zero); +} + +void gen_satu_i32_ext (TCGv ovfl,TCGv dest,TCGv source,int width) +{ +gen_satu_i32 (dest, source, width); +TCGv zero =tcg_const_i32 (0 ); +TCGv one =tcg_const_i32 (1 ); +tcg_gen_movcond_i32 (TCG_COND_NE , ovfl, dest, source, one, zero); +tcg_temp_free_i32 (zero); +tcg_temp_free_i32 (one); +} + +void gen_sat_i64 (TCGv_i64 dest,TCGv_i64 source,int width) +{ +TCGv_i64 max_val =tcg_const_i64 ((1 << (width -1 )) -1 ); +TCGv_i64 min_val =tcg_const_i64 (-(1 << (width -1 ))); +tcg_gen_smin_i64 (dest, source, max_val); +tcg_gen_smax_i64 (dest, dest, min_val); +tcg_temp_free_i64 (max_val); +tcg_temp_free_i64 (min_val); +} + +void gen_sat_i64_ext (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width) +{ +gen_sat_i64 (dest, source, width); +TCGv_i64 ovfl_64 =tcg_temp_new_i64 (); +TCGv_i64 zero =tcg_const_i64 (0 ); +TCGv_i64 one =tcg_const_i64 (1 ); +tcg_gen_movcond_i64 (TCG_COND_NE , ovfl_64, dest, source, one, zero); +tcg_gen_trunc_i64_tl (ovfl, ovfl_64); +tcg_temp_free_i64 (ovfl_64); +tcg_temp_free_i64 (zero); +tcg_temp_free_i64 (one); +} + +void gen_satu_i64 (TCGv_i64 dest,TCGv_i64 source,int width) +{ +TCGv_i64 max_val =tcg_const_i64 ((1 << width) -1 ); +tcg_gen_movcond_i64 (TCG_COND_GTU , dest, source, max_val, max_val, source); +TCGv_i64 zero =tcg_const_i64 (0 ); +tcg_gen_movcond_i64 (TCG_COND_LT , dest, source, zero, zero, dest); +tcg_temp_free_i64 (max_val); +tcg_temp_free_i64 (zero); +} + +void gen_satu_i64_ext (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width) +{ +gen_sat_i64 (dest, source, width); +TCGv_i64 ovfl_64 =tcg_temp_new_i64 (); +TCGv_i64 zero =tcg_const_i64 (0 ); +TCGv_i64 one =tcg_const_i64 (1 ); +tcg_gen_movcond_i64 (TCG_COND_NE , ovfl_64, dest, source, one, zero); +tcg_gen_trunc_i64_tl (ovfl, ovfl_64); +tcg_temp_free_i64 (ovfl_64); +tcg_temp_free_i64 (zero); +tcg_temp_free_i64 (one); +} + +void gen_fbrev (TCGv result,TCGv src) +{ +TCGv lo =tcg_temp_new (); +TCGv tmp1 =tcg_temp_new (); +TCGv tmp2 =tcg_temp_new (); + +/* Bit reversal of low 16 bits */ +tcg_gen_extract_tl (lo, src,0 ,16 ); +tcg_gen_andi_tl (tmp1, lo,0xaaaa ); +tcg_gen_shri_tl (tmp1, tmp1,1 ); +tcg_gen_andi_tl (tmp2, lo,0x5555 ); +tcg_gen_shli_tl (tmp2, tmp2,1 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_andi_tl (tmp1, lo,0xcccc ); +tcg_gen_shri_tl (tmp1, tmp1,2 ); +tcg_gen_andi_tl (tmp2, lo,0x3333 ); +tcg_gen_shli_tl (tmp2, tmp2,2 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_andi_tl (tmp1, lo,0xf0f0 ); +tcg_gen_shri_tl (tmp1, tmp1,4 ); +tcg_gen_andi_tl (tmp2, lo,0x0f0f ); +tcg_gen_shli_tl (tmp2, tmp2,4 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_bswap16_tl (lo, lo); + +/* Final tweaks */ +tcg_gen_deposit_tl (result, src, lo,0 ,16 ); +tcg_gen_or_tl (result, result, lo); + +tcg_temp_free (lo); +tcg_temp_free (tmp1); +tcg_temp_free (tmp2); +} +#include "tcg_funcs_generated.c.inc" #include "tcg_func_table_generated.c.inc"
target/hexagon/genptr.h +22 -0
@@ -24,8 +24,30 @@extern const SemanticInsn opcode_genptr[]; +TCGv gen_read_reg (TCGv result,int num);TCGv gen_read_preg (TCGv pred,uint8_t num);void gen_log_reg_write (int rnum,TCGv val);void gen_log_pred_write (int pnum,TCGv val); +void gen_store32 (TCGv vaddr,TCGv src,tcg_target_long width,unsigned slot); +void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +unsigned slot); +void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +unsigned slot); +void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +unsigned slot); +void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,DisasContext *ctx, +unsigned slot); +void gen_write_new_pc (TCGv addr); +void gen_set_usr_field (int field,TCGv val); +void gen_set_usr_fieldi (int field,int x); +void gen_sat_i32 (TCGv dest,TCGv source,int width); +void gen_sat_i32_ext (TCGv ovfl,TCGv dest,TCGv source,int width); +void gen_satu_i32 (TCGv dest,TCGv source,int width); +void gen_satu_i32_ext (TCGv ovfl,TCGv dest,TCGv source,int width); +void gen_sat_i64 (TCGv_i64 dest,TCGv_i64 source,int width); +void gen_sat_i64_ext (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width); +void gen_satu_i64 (TCGv_i64 dest,TCGv_i64 source,int width); +void gen_satu_i64_ext (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width); +void gen_fbrev (TCGv result,TCGv src);#endif
target/hexagon/macros.h +9 -0
@@ -149,7 +149,16 @@#define MEM_STORE8 (VA ,DATA ,SLOT ) log_store64(env, VA, DATA, 8, SLOT)#endif +#ifdef QEMU_GENERATE +static inline void gen_cancel (unsigned slot) +{ +tcg_gen_ori_tl (hex_slot_cancelled, hex_slot_cancelled,1 << slot); +} + +#define CANCEL gen_cancel(slot); +#else #define CANCEL cancel_slot(env, slot) +#endif #define LOAD_CANCEL (EA ) do { CANCEL; } while (0)
Signature · 1 line
2.31.1
Re: [PATCH v4 06/12] target/hexagon: introduce new helper functions
target/hexagon/genptr.c static inline void gen_store_conditional8(CPUHexagonState *env, · line 351
Quoted 13 lines · Alessandro Di Federico
target/hexagon/genptr.c +13
-0+void gen_store32 (TCGv vaddr,TCGv src,tcg_target_long width,unsigned slot) +{ +tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_movi_tl (hex_store_width[slot], width); +tcg_gen_mov_tl (hex_store_val32[slot], src); +} + +void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +unsigned slot) +{ +gen_store32 (vaddr, src,1 , slot); + ctx->store_width[slot] =1 ; +}
Why is store_width here and not in gen_store32?
Do you really need so many helpers here, as opposed to making use of MemOp?
target/hexagon/genptr.c static inline void gen_store_conditional8(CPUHexagonState *env, · line 416
Quoted 6 lines
target/hexagon/genptr.c +6
-0+void gen_sat_i32_ext (TCGv ovfl,TCGv dest,TCGv source,int width) +{ +gen_sat_i32 (dest, source, width); +TCGv zero =tcg_const_i32 (0 ); +TCGv one =tcg_const_i32 (1 ); +tcg_gen_movcond_i32 (TCG_COND_NE , ovfl, source, dest, one, zero);
(source != dest ? 1 : 0) -> (source != dest).
Therefore, tcg_gen_setcond_i32.
Or did you intend
ovfl = (source != dest ? 1 : ovfl)?
which is probably still better as
tcg_gen_setcond_tl(TCG_COND_NE, tmp, source,dest); tcg_gen_or_tl(ovfl, ovfl, tmp);
Quoted 23 lines
target/hexagon/genptr.c +23
-0+void gen_fbrev (TCGv result,TCGv src) +{ +TCGv lo =tcg_temp_new (); +TCGv tmp1 =tcg_temp_new (); +TCGv tmp2 =tcg_temp_new (); + +/* Bit reversal of low 16 bits */ +tcg_gen_extract_tl (lo, src,0 ,16 ); +tcg_gen_andi_tl (tmp1, lo,0xaaaa ); +tcg_gen_shri_tl (tmp1, tmp1,1 ); +tcg_gen_andi_tl (tmp2, lo,0x5555 ); +tcg_gen_shli_tl (tmp2, tmp2,1 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_andi_tl (tmp1, lo,0xcccc ); +tcg_gen_shri_tl (tmp1, tmp1,2 ); +tcg_gen_andi_tl (tmp2, lo,0x3333 ); +tcg_gen_shli_tl (tmp2, tmp2,2 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_andi_tl (tmp1, lo,0xf0f0 ); +tcg_gen_shri_tl (tmp1, tmp1,4 ); +tcg_gen_andi_tl (tmp2, lo,0x0f0f ); +tcg_gen_shli_tl (tmp2, tmp2,4 ); +tcg_gen_or_tl (lo, tmp1, tmp2);
target/hexagon/genptr.c static inline void gen_store_conditional8(CPUHexagonState *env, · line 519
Quoted 10 lines
target/hexagon/genptr.c +10
-0+tcg_gen_bswap16_tl (lo, lo); + +/* Final tweaks */ +tcg_gen_deposit_tl (result, src, lo,0 ,16 ); +tcg_gen_or_tl (result, result, lo); + +tcg_temp_free (lo); +tcg_temp_free (tmp1); +tcg_temp_free (tmp2); +}
Coordinate with Taylor.
https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg10007.html
r~
RE: [PATCH v4 06/12] target/hexagon: introduce new helper functions
Quoted 23 lines
-----Original Message-----
From: Richard Henderson <[email protected]>
Sent: Sunday, April 18, 2021 4:31 PM
To: Alessandro Di Federico <[email protected]>; [email protected]
Cc: Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]; Alessandro Di Federico <[email protected]>
Subject: Re: [PATCH v4 06/12] target/hexagon: introduce new helper functionsQuoted 1 line · Alessandro Di Federico
+void gen_store32(TCGv vaddr, TCGv src,
tcg_target_longwidth, unsignedslot)
target/hexagon/genptr.c static inline void gen_store_conditional8(CPUHexagonState *env,
Quoted 7 lines
target/hexagon/genptr.c +7
-0+{ +tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_movi_tl (hex_store_width[slot], width); +tcg_gen_mov_tl (hex_store_val32[slot], src); +} + +void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src, DisasContext*ctx,
Quoted 9 lines
target/hexagon/genptr.c static inline void gen_store_conditional8(CPUHexagonState *env, · line 351
Quoted 5 lines
target/hexagon/genptr.c +5
-0+ unsigned slot) +{ +gen_store32 (vaddr, src,1 , slot); + ctx->store_width[slot] =1 ; +}Why is
store_widthhere and not ingen_store32?
Do you really need so many helpers here, as opposed to making use of MemOp?
These are included in this patch
https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01355.html
which hasn't been merged yet.
Quoted 49 lines
target/hexagon/genptr.c static inline void gen_store_conditional8(CPUHexagonState *env, · line 416
Quoted 7 lines
target/hexagon/genptr.c +6
-0+void gen_sat_i32_ext (TCGv ovfl,TCGv dest,TCGv source,int width) +{ +gen_sat_i32 (dest, source, width); +TCGv zero =tcg_const_i32 (0 ); +TCGv one =tcg_const_i32 (1 ); +tcg_gen_movcond_i32 (TCG_COND_NE , ovfl, source, dest, one, zero);(source != dest ? 1 : 0) -> (source != dest).
Therefore,
tcg_gen_setcond_i32.Or did you intend
ovfl = (source != dest ? 1 : ovfl)?
which is probably still better as
tcg_gen_setcond_tl(TCG_COND_NE, tmp, source,dest); tcg_gen_or_tl(ovfl, ovfl, tmp);Quoted 28 lines
target/hexagon/genptr.c +28
-0+void gen_fbrev (TCGv result,TCGv src) +{ +TCGv lo =tcg_temp_new (); +TCGv tmp1 =tcg_temp_new (); +TCGv tmp2 =tcg_temp_new (); + +/* Bit reversal of low 16 bits */ +tcg_gen_extract_tl (lo, src,0 ,16 ); +tcg_gen_andi_tl (tmp1, lo,0xaaaa ); +tcg_gen_shri_tl (tmp1, tmp1,1 ); +tcg_gen_andi_tl (tmp2, lo,0x5555 ); +tcg_gen_shli_tl (tmp2, tmp2,1 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_andi_tl (tmp1, lo,0xcccc ); +tcg_gen_shri_tl (tmp1, tmp1,2 ); +tcg_gen_andi_tl (tmp2, lo,0x3333 ); +tcg_gen_shli_tl (tmp2, tmp2,2 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_andi_tl (tmp1, lo,0xf0f0 ); +tcg_gen_shri_tl (tmp1, tmp1,4 ); +tcg_gen_andi_tl (tmp2, lo,0x0f0f ); +tcg_gen_shli_tl (tmp2, tmp2,4 ); +tcg_gen_or_tl (lo, tmp1, tmp2); +tcg_gen_bswap16_tl (lo, lo); + +/* Final tweaks */ +tcg_gen_deposit_tl (result, src, lo,0 ,16 ); +tcg_gen_or_tl (result, result, lo);
Quoted 8 lines
target/hexagon/genptr.c static inline void gen_store_conditional8(CPUHexagonState *env, · line 519
Quoted 5 lines
target/hexagon/genptr.c +5
-0+ +tcg_temp_free (lo); +tcg_temp_free (tmp1); +tcg_temp_free (tmp2); +}Coordinate with Taylor.
https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg10007.html
Once this patch series is merged, many load/store instructions will have manual overrides. I can easily provide overrides for the remainder. Then, we could skip them in the idef-parser. At a minimum, you should skip the ones that are part of that series
- circular addressing https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01355.html
- bit reverse addressing https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01354.html
- load and unpack bytes https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01353.html
- load into shifted register https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01359.html
Alessandro, what do you think?
Thanks,
Taylor
Re: [PATCH v4 06/12] target/hexagon: introduce new helper functions
Quoted 11 lines · On Mon, 19 Apr 2021 15:00:17 +0000 Taylor Simpson <[email protected]> wrote:
Once this patch series is merged, many load/store instructions will have manual overrides. I can easily provide overrides for the remainder. Then, we could skip them in the idef-parser. At a minimum, you should skip the ones that are part of that series
- circular addressing
https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01355.html
- bit reverse addressing
https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01354.html
- load and unpack bytes
https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01353.html
Quoted 4 lines
- load into shifted register
https://lists.gnu.org/archive/html/qemu-devel/2021-04/msg01359.htmlAlessandro, what do you think?
If, for an instruction, all idef-parse does is calling an helper, yeah, it makes sense to exclude them.
I'll look into this again once your patchset is in.
Signature · 2 lines
Alessandro Di Federico rev.ng
PATCH v4 7/12 target/hexagon: expose next PC in DisasContext
In reply to Alessandro Di Federico viaFrom: Paolo Montesel <[email protected]>
--- target/hexagon/translate.c | 3 ++- target/hexagon/translate.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
target/hexagon/translate.c +2 -1
@@ -503,11 +503,12 @@ static void decode_and_translate_packet(CPUHexagonState *env, DisasContext *ctx)if (decode_packet (nwords, words, &pkt, false) >0 ) {HEX_DEBUG_PRINT_PKT (&pkt);gen_start_packet (ctx, &pkt); + ctx->npc = ctx->base.pc_next + pkt.encod_pkt_size_in_bytes;for (i =0 ; i < pkt.num_insns; i++) {gen_insn (env, ctx, &pkt.insn[i], &pkt); }gen_commit_packet (ctx, &pkt); - ctx->base.pc_next += pkt.encod_pkt_size_in_bytes; + ctx->base.pc_next = ctx->npc; }else {gen_exception (HEX_EXCP_INVALID_PACKET ); ctx->base.is_jmp =DISAS_NORETURN ;
target/hexagon/translate.h +1 -0
@@ -36,6 +36,7 @@ typedef struct DisasContext {int preg_log_idx;uint8_t store_width[STORES_MAX ];uint8_t s1_store_processed; +uint32_t npc; } DisasContext;static inline void ctx_log_reg_write (DisasContext *ctx,int rnum)
Signature · 1 line
2.31.1
Re: [PATCH v4 07/12] target/hexagon: expose next PC in DisasContext
Quoted 8 lines · Alessandro Di Federico
From: Paolo Montesel<[email protected]>
Signed-off-by Alessandro Di Federico<[email protected]>Signed-off-by Paolo Montesel<[email protected]>--- target/hexagon/translate.c | 3 ++- target/hexagon/translate.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
r~
PATCH v4 8/12 target/hexagon: prepare input for the idef-parser
In reply to Alessandro Di Federico viaFrom: Alessandro Di Federico <[email protected]>
Introduce infrastructure necessary to produce a file suitable for being parsed by the idef-parser.
--- target/hexagon/gen_idef_parser_funcs.py | 114 ++++++++++++++++++ target/hexagon/idef-parser/macros.inc | 150 ++++++++++++++++++++++++ target/hexagon/idef-parser/prepare | 24 ++++ target/hexagon/meson.build | 17 +++ 4 files changed, 305 insertions(+) create mode 100644 target/hexagon/gen_idef_parser_funcs.py create mode 100644 target/hexagon/idef-parser/macros.inc create mode 100755 target/hexagon/idef-parser/prepare
target/hexagon/gen_idef_parser_funcs.py new file +114 -0
@@ -0,0 +1,114 @@ +#!/usr/bin/env python3 + +## +## Copyright(c) 2019-2021 rev.ng Srls. All Rights Reserved. +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program 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 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/>. +## + +import sys +import re +import string +from io import StringIO + +import hex_common + +## +## Generate code to be fed to the idef_parser +## +## Consider A2_add: +## +## Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;} +## +## We produce: +## +## A2_add(RdV, in RsV, in RtV) { +## { RdV=RsV+RtV;} +## } +## +## A2_add represents the instruction tag. Then we have a list of TCGv +## that the code generated by the parser can expect in input. Some of +## them are inputs ("in" prefix), while some others are outputs. +## +def main(): + hex_common.read_semantics_file(sys.argv[1]) + hex_common.read_attribs_file(sys.argv[2]) + hex_common.read_overrides_file(sys.argv[3]) + hex_common.calculate_attribs() + tagregs = hex_common.get_tagregs() + tagimms = hex_common.get_tagimms() + + with open(sys.argv[4], 'w') as f: + f.write('#include "macros.inc"\n\n') + + for tag in hex_common.tags: + ## Skip the priv instructions + if ( "A_PRIV" in hex_common.attribdict[tag] ) : + continue + ## Skip the guest instructions + if ( "A_GUEST" in hex_common.attribdict[tag] ) : + continue + ## Skip instructions using switch + if ( tag in {'S4_vrcrotate_acc', 'S4_vrcrotate'} ) : + continue + ## Skip trap instructions + if ( tag in {'J2_trap0', 'J2_trap1'} ) : + continue + ## Skip 128-bit instructions + if ( tag in {'A7_croundd_ri', 'A7_croundd_rr'} ) : + continue + ## Skip other unsupported instructions + if ( tag.startswith('S2_cabacdecbin') ) : + continue + if ( tag.startswith('Y') ) : + continue + if ( tag.startswith('V6_') ) : + continue + if ( tag.startswith('F') ) : + continue + if ( tag.endswith('_locked') ) : + continue + + regs = tagregs[tag] + imms = tagimms[tag] + + arguments = [] + if hex_common.need_ea(tag): + arguments.append("EA") + + for regtype,regid,toss,numregs in regs: + prefix = "in " if hex_common.is_read(regid) else "" + + is_pair = hex_common.is_pair(regid) + is_single_old = (hex_common.is_single(regid) + and hex_common.is_old_val(regtype, regid, tag)) + is_single_new = (hex_common.is_single(regid) + and hex_common.is_new_val(regtype, regid, tag)) + + if is_pair or is_single_old: + arguments.append("%s%s%sV" % (prefix, regtype, regid)) + elif is_single_new: + arguments.append("%s%s%sN" % (prefix, regtype, regid)) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + + for immlett,bits,immshift in imms: + arguments.append(hex_common.imm_name(immlett)) + + f.write("%s(%s) {\n" % (tag, ", ".join(arguments))) + f.write(" %s\n" % hex_common.semdict[tag]) + f.write("}\n\n") + +if __name__ == "__main__": + main()
target/hexagon/idef-parser/macros.inc new file +150 -0
150 lines not on this page · raw message
target/hexagon/idef-parser/prepare new file +24 -0
@@ -0,0 +1,24 @@ +#!/bin/bash + +# +# Copyright(c) 2019-2021 rev.ng Srls. All Rights Reserved. +# +# 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 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/>. +# + +set -e +set -o pipefail + +# Run the preprocessor and drop comments +cpp "$@" | grep -v '^#'
target/hexagon/meson.build +17 -0
@@ -20,6 +20,7 @@ hexagon_ss = ss.source_set() hex_common_py = 'hex_common.py' attribs_def = meson.current_source_dir() / 'attribs_def.h.inc' gen_tcg_h = meson.current_source_dir() / 'gen_tcg.h' +idef_parser_dir = meson.current_source_dir() / 'idef-parser' # # Step 1
@@ -176,4 +177,20 @@ hexagon_ss.add(files( 'conv_emu.c', )) +idef_parser_input_generated = custom_target( + 'idef_parser_input.h.inc', + output: 'idef_parser_input.h.inc', + depend_files: [hex_common_py], + command: [python, files('gen_idef_parser_funcs.py'), semantics_generated, attribs_def, gen_tcg_h, '@OUTPUT@'], +) + +idef_parser_input_generated_prep = custom_target( + 'idef_parser_input.preprocessed.h.inc', + output: 'idef_parser_input.preprocessed.h.inc', + input: idef_parser_input_generated, + capture: true, + depend_files: [hex_common_py], + command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir], +) + target_arch += {'hexagon': hexagon_ss}
Signature · 1 line
2.31.1
Re: [PATCH v4 08/12] target/hexagon: prepare input for the idef-parser
Quoted 16 lines · Alessandro Di Federico
+++ b/target/hexagon/idef-parser/prepare
target/hexagon/idef-parser/prepare new file +14
-0@@ -0,0 +1,24 @@ +#!/bin/bash + +# +# Copyright(c) 2019-2021 rev.ng Srls. All Rights Reserved. +# +# 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 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.
target/hexagon/idef-parser/prepare line 24
Quoted 10 lines
target/hexagon/idef-parser/prepare new file +10
-0+# +# 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/>. +# + +set -e +set -o pipefail + +# Run the preprocessor and drop comments +cpp "$@" | grep -v '^#'
Any reason not to handle '#' lines in the parser?
r~
PATCH v4 9/12 target/hexagon: import lexer for idef-parser
In reply to Alessandro Di Federico viaFrom: Paolo Montesel <[email protected]>
--- target/hexagon/idef-parser/idef-parser.h | 254 ++++++++ target/hexagon/idef-parser/idef-parser.lex | 611 ++++++++++++++++++ target/hexagon/meson.build | 4 + tests/docker/dockerfiles/alpine.docker | 1 + tests/docker/dockerfiles/centos7.docker | 1 + tests/docker/dockerfiles/centos8.docker | 1 + tests/docker/dockerfiles/debian10.docker | 1 + .../dockerfiles/fedora-i386-cross.docker | 1 + .../dockerfiles/fedora-win32-cross.docker | 1 + .../dockerfiles/fedora-win64-cross.docker | 1 + tests/docker/dockerfiles/fedora.docker | 1 + tests/docker/dockerfiles/opensuse-leap.docker | 1 + tests/docker/dockerfiles/ubuntu.docker | 1 + tests/docker/dockerfiles/ubuntu1804.docker | 1 + tests/docker/dockerfiles/ubuntu2004.docker | 3 +- 15 files changed, 882 insertions(+), 1 deletion(-) create mode 100644 target/hexagon/idef-parser/idef-parser.h create mode 100644 target/hexagon/idef-parser/idef-parser.lex
target/hexagon/idef-parser/idef-parser.h new file +254 -0
@@ -0,0 +1,254 @@ +/* +* Copyright(c) 2019-2021 rev.ng Srls. All Rights Reserved. +* +* 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 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 +* 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/>. +*/ + +#ifndef IDEF_PARSER_H +#define IDEF_PARSER_H + +#include <inttypes.h> +#include <stdio.h> +#include <stdbool.h> +#include <glib.h> + +#define TCGV_NAME_SIZE 7 +#define MAX_WRITTEN_REGS 32 +#define OFFSET_STR_LEN 32 +#define ALLOC_LIST_LEN 32 +#define ALLOC_NAME_SIZE 32 +#define INIT_LIST_LEN 32 +#define OUT_BUF_LEN (1024 * 1024) +#define SIGNATURE_BUF_LEN (128 * 1024) +#define HEADER_BUF_LEN (128 * 1024) + +/* Variadic macros to wrap the buffer printing functions */ +#define EMIT (c, ...) \ + do { \ + g_string_append_printf((c)->out_str, __VA_ARGS__); \ + } while (0) + +#define EMIT_SIG (c, ...) \ + do { \ + g_string_append_printf((c)->signature_str, __VA_ARGS__); \ + } while (0) + +#define EMIT_HEAD (c, ...) \ + do { \ + g_string_append_printf((c)->header_str, __VA_ARGS__); \ + } while (0) + +/** +* Type of register, assigned to the HexReg.type field +*/ +typedef enum {GENERAL_PURPOSE ,CONTROL ,MODIFIER ,DOTNEW }RegType ; + +/** +* Types of control registers, assigned to the HexReg.id field +*/ +typedef enum {SP ,FP ,LR ,GP ,LC0 ,LC1 ,SA0 ,SA1 }CregType ; + +/** +* Identifier string of the control registers, indexed by the CregType enum +*/ +extern const char *creg_str[]; + +/** +* Semantic record of the REG tokens, identifying registers +*/ +typedef struct HexReg { +CregType id;/**< Identifier of the register */ +RegType type;/**< Type of the register */ +unsigned bit_width;/**< Bit width of the reg, 32 or 64 bits */ +}HexReg ; + +/** +* Data structure, identifying a TCGv temporary value +*/ +typedef struct HexTmp { +int index;/**< Index of the TCGv temporary value */ +}HexTmp ; + +/** +* Enum of the possible immediated, an immediate is a value which is known +* at tinycode generation time, e.g. an integer value, not a TCGv +*/ +enum ImmUnionTag {I ,VARIABLE ,VALUE ,QEMU_TMP ,IMM_PC ,IMM_CONSTEXT }; + +/** +* Semantic record of the IMM token, identifying an immediate constant +*/ +typedef struct HexImm { +union { +char id;/**< Identifier of the immediate */ +uint64_t value;/**< Immediate value (for VALUE type immediates) */ +uint64_t index;/**< Index of the immediate (for int temp vars) */ + }; +enum ImmUnionTag type;/**< Type of the immediate */ +}HexImm ; + +/** +* Semantic record of the PRE token, identifying a predicate +*/ +typedef struct HexPre { +char id;/**< Identifier of the predicate */ +}HexPre ; + +/** +* Semantic record of the SAT token, identifying the saturate operator +*/ +typedef struct HexSat { +bool set_overflow;/**< Set-overflow feature for the sat operator */ +bool is_unsigned;/**< Unsigned flag for the saturate operator */ +}HexSat ; + +/** +* Semantic record of the CAST token, identifying the cast operator +*/ +typedef struct HexCast { +int bit_width;/**< Bit width of the cast operator */ +bool is_unsigned;/**< Unsigned flag for the cast operator */ +}HexCast ; + +/** +* Semantic record of the EXTRACT token, identifying the cast operator +*/ +typedef struct HexExtract { +int bit_width;/**< Bit width of the extract operator */ +int storage_bit_width;/**< Actual bit width of the extract operator */ +bool is_unsigned;/**< Unsigned flag for the extract operator */ +}HexExtract ; + +/** +* Semantic record of the MPY token, identifying the fMPY multiplication +* operator +*/ +typedef struct HexMpy { +int first_bit_width;/**< Bit width of the first operand of fMPY op */ +int second_bit_width;/**< Bit width of the second operand of fMPY */ +bool first_unsigned;/**< Unsigned flag for the first operand of fMPY */ +bool second_unsigned;/**< Unsigned flag for second operand of fMPY */ +}HexMpy ; + +/** +* Semantic record of the VARID token, identifying automatic variables +* of the input language +*/ +typedef struct HexVar { +GString *name;/**< Name of the VARID automatic variable */ +}HexVar ; + +/** +* Data structure uniquely identifying an automatic VARID variable, used for +* keeping track of declared variable, so that any variable is declared only +* once, and its properties are propagated through all the subsequent instances +* of that variable +*/ +typedef struct Var { +GString *name;/**< Name of the VARID automatic variable */ +uint8_t bit_width;/**< Bit width of the VARID automatic variable */ +bool is_unsigned;/**< Unsigned flag for the VARID automatic var */ +}Var ; + +/** +* Enum of the possible rvalue types, used in the HexValue.type field +*/ +typedef enum RvalueUnionTag { +REGISTER ,TEMP ,IMMEDIATE ,PREDICATE ,VARID +}RvalueUnionTag ; + +/** +* Semantic record of the rvalue token, identifying any numeric value, +* immediate or register based. The rvalue tokens are combined together +* through the use of several operators, to encode expressions +*/ +typedef struct HexValue { +union { +HexReg reg;/**< rvalue of register type */ +HexTmp tmp;/**< rvalue of temporary type */ +HexImm imm;/**< rvalue of immediate type */ +HexPre pre;/**< rvalue of predicate type */ +HexVar var;/**< rvalue of automatic variable type */ + }; +RvalueUnionTag type;/**< Type of the rvalue */ +unsigned bit_width;/**< Bit width of the rvalue */ +bool is_unsigned;/**< Unsigned flag for the rvalue */ +bool is_dotnew;/**< rvalue of predicate type is dotnew? */ +bool is_manual;/**< Opt out of automatic freeing of params */ +}HexValue ; + +/** +* State of ternary operator +*/ +typedef enum TernaryState {IN_LEFT ,IN_RIGHT }TernaryState ; + +/** +* Data structure used to handle side effects inside ternary operators +*/ +typedef struct Ternary { +TernaryState state; +HexValue cond; +}Ternary ; + +/** +* Operator type, used for referencing the correct operator when calling the +* gen_bin_op() function, which in turn will generate the correct code to +* execute the operation between the two rvalues +*/ +typedef enum OpType { +ADD_OP ,SUB_OP ,MUL_OP ,ASL_OP ,ASR_OP ,LSR_OP ,ANDB_OP ,ORB_OP , +XORB_OP ,ANDL_OP ,MINI_OP ,MAXI_OP ,MOD_OP +}OpType ; + +/** +* Data structure including instruction specific information, to be cleared +* out after the compilation of each instruction +*/ +typedef struct Inst { +GString *name;/**< Name of the compiled instruction */ +char *code_begin;/**< Beginning of instruction input code */ +char *code_end;/**< End of instruction input code */ +int tmp_count;/**< Index of the last declared TCGv temp */ +int qemu_tmp_count;/**< Index of the last declared int temp */ +int if_count;/**< Index of the last declared if label */ +int error_count;/**< Number of generated errors */ +GArray *allocated;/**< Allocated VARID automatic vars */ +GArray *init_list;/**< List of initialized registers */ +GArray *strings;/**< Strings allocated by the instruction */ +}Inst ; + +/** +* Data structure representing the whole translation context, which in a +* reentrant flex/bison parser just like ours is passed between the scanner +* and the parser, holding all the necessary information to perform the +* parsing, this data structure survives between the compilation of different +* instructions +* +*/ +typedef struct Context { +void *scanner;/**< Reentrant parser state pointer */ +char *input_buffer;/**< Buffer containing the input code */ +GString *out_str;/**< String containing the output code */ +GString *signature_str;/**< String containing the signatures code */ +GString *header_str;/**< String containing the output code */ +FILE *defines_file;/**< FILE * of the generated header */ +FILE *output_file;/**< FILE * of the C output file */ +FILE *enabled_file;/**< FILE * of the list of enabled inst */ +GArray *ternary;/**< Array to track nesting of ternary ops */ +int total_insn;/**< Number of instructions in input file */ +int implemented_insn;/**< Instruction compiled without errors */ +Inst inst;/**< Parsing data of the current inst */ +}Context ; + +#endif /* IDEF_PARSER_H */
target/hexagon/idef-parser/idef-parser.lex new file +611 -0
611 lines not on this page · raw message
target/hexagon/meson.build +4 -0
@@ -193,4 +193,8 @@ idef_parser_input_generated_prep = custom_target( command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir], ) +flex = generator(find_program('flex'), + output: ['@[email protected]', '@[email protected]'], + arguments: ['-o', '@OUTPUT0@', '--header-file=@OUTPUT1@', '@INPUT@']) + target_arch += {'hexagon': hexagon_ss}
tests/docker/dockerfiles/alpine.docker +1 -0
@@ -11,6 +11,7 @@ ENV PACKAGES \ binutils \ coreutils \ curl-dev \ + flex \ g++ \ gcc \ git \
tests/docker/dockerfiles/centos7.docker +1 -0
@@ -10,6 +10,7 @@ ENV PACKAGES \ ccache \ csnappy-devel \ dbus-daemon \ + flex \ gcc-c++ \ gcc \ gettext \
tests/docker/dockerfiles/centos8.docker +1 -0
@@ -7,6 +7,7 @@ ENV PACKAGES \ bzip2-devel \ dbus-daemon \ diffutils \ + flex \ gcc \ gcc-c++ \ genisoimage \
tests/docker/dockerfiles/debian10.docker +1 -0
@@ -23,6 +23,7 @@ RUN apt update && \ ccache \ clang \ dbus \ + flex \ gdb-multiarch \ gettext \ git \
tests/docker/dockerfiles/fedora-i386-cross.docker +1 -0
@@ -3,6 +3,7 @@ ENV PACKAGES \ bzip2 \ diffutils \ findutils \ + flex \ gcc \ git \ libtasn1-devel.i686 \
tests/docker/dockerfiles/fedora-win32-cross.docker +1 -0
@@ -6,6 +6,7 @@ ENV PACKAGES \ bzip2 \ diffutils \ findutils \ + flex \ gcc \ gettext \ git \
tests/docker/dockerfiles/fedora-win64-cross.docker +1 -0
@@ -6,6 +6,7 @@ ENV PACKAGES \ bzip2 \ diffutils \ findutils \ + flex \ gcc \ gettext \ git \
tests/docker/dockerfiles/fedora.docker +1 -0
@@ -14,6 +14,7 @@ ENV PACKAGES \ device-mapper-multipath-devel \ diffutils \ findutils \ + flex \ gcc \ gcc-c++ \ genisoimage \
tests/docker/dockerfiles/opensuse-leap.docker +1 -0
@@ -6,6 +6,7 @@ ENV PACKAGES \ brlapi-devel \ bzip2 \ cyrus-sasl-devel \ + flex \ gcc \ gcc-c++ \ mkisofs \
tests/docker/dockerfiles/ubuntu.docker +1 -0
@@ -14,6 +14,7 @@ ENV PACKAGES \ ccache \ clang \ dbus \ + flex \ gcc \ gettext \ git \
tests/docker/dockerfiles/ubuntu1804.docker +1 -0
@@ -2,6 +2,7 @@ FROM ubuntu:18.04 ENV PACKAGES \ ccache \ clang \ + flex \ gcc \ gettext \ git \
tests/docker/dockerfiles/ubuntu2004.docker +2 -1
@@ -1,8 +1,9 @@ FROM ubuntu:20.04 -ENV PACKAGES flex bison \ +ENV PACKAGES bison \ bsdmainutils \ ccache \ clang-10\ + flex \ gcc \ gcovr \ genisoimage \
Signature · 1 line
2.31.1
RE: [PATCH v4 09/12] target/hexagon: import lexer for idef-parser
Quoted 11 lines
-----Original Message-----
From: Alessandro Di Federico <[email protected]>
Sent: Thursday, April 15, 2021 11:35 AM
To: [email protected]
Cc: Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Alessandro Di Federico <[email protected]>
Subject: [PATCH v4 09/12] target/hexagon: import lexer for idef-parser
target/hexagon/idef-parser/idef-parser.h line 95
Quoted 7 lines
target/hexagon/idef-parser/idef-parser.h new file +7
-0+/** +* Semantic record of the IMM token, identifying an immediate constant +*/ +typedef struct HexImm { + union { + char id; /**< Identifier of the immediate */ + uint64_t value; /**< Immediate value (for VALUE type immediates) */
Most immediates are 32 bits. Since you treat them as 64 bits, you end up with unnecessary extends and truncates in the TCG.
Here's an example from idef-generated-emitter.c
void emit_J2_jump(DisasContext *ctx, Insn *insn, Packet *pkt, int riV) /* fIMMEXT(riV); (riV = riV & ~3); (PC = fREAD_PC()+riV);} */ {int64_t qemu_tmp_0 = ~((int64_t)3ULL);int32_t qemu_tmp_1 = riV & qemu_tmp_0;
riV = qemu_tmp_1;TCGv_i32 tmp_0 = tcg_temp_local_new_i32(); tcg_gen_movi_i32(tmp_0, ctx->base.pc_next);TCGv_i64 tmp_1 = tcg_temp_local_new_i64();tcg_gen_ext_i32_i64(tmp_1, tmp_0); <- Don't need this extensiontcg_temp_free_i32(tmp_0);TCGv_i64 tmp_2 = tcg_temp_local_new_i64();tcg_gen_addi_i64(tmp_2, tmp_1, (int64_t)riV); <- This should be 32 bitstcg_temp_free_i64(tmp_1);TCGv_i32 tmp_3 = tcg_temp_local_new_i32();tcg_gen_trunc_i64_tl(tmp_3, tmp_2); <- Don't need this truncationtcg_temp_free_i64(tmp_2);gen_write_new_pc(tmp_3);tcg_temp_free_i32(tmp_3);
}
Quoted 2 lines
target/hexagon/idef-parser/idef-parser.h new file +2
-0+uint64_t index;/**< Index of the immediate (for int temp vars) */ + };
Re: [PATCH v4 09/12] target/hexagon: import lexer for idef-parser
Quoted 30 lines
target/hexagon/idef-parser/idef-parser.h
Quoted 7 lines
target/hexagon/idef-parser/idef-parser.h new file +6
-0+/** +* Semantic record of the IMM token, identifying an immediate constant +*/ +typedef struct HexImm { + union { + char id; /**< Identifier of the immediate*/Quoted 1 line
+
uint64_tvalue; /**< Immediate value (for VALUE typeimmediates) */
Most immediates are 32 bits. Since you treat them as 64 bits, you end up with unnecessary extends and truncates in the TCG.
Here's an example from
idef-generated-emitter.c
voidemit_J2_jump(DisasContext *ctx, Insn *insn, Packet *pkt, int riV)/* fIMMEXT(riV); (riV = riV & ~3); (PC = fREAD_PC()+riV);} */ {int64_tqemu_tmp_0= ~((int64_t)3ULL);int32_tqemu_tmp_1= riV &qemu_tmp_0;
riV =qemu_tmp_1;TCGv_i32tmp_0=tcg_temp_local_new_i32();tcg_gen_movi_i32(tmp_0, ctx->base.pc_next);TCGv_i64tmp_1=tcg_temp_local_new_i64();tcg_gen_ext_i32_i64(tmp_1, tmp_0);
<- Don't need this extensiontcg_temp_free_i32(tmp_0);TCGv_i64tmp_2=tcg_temp_local_new_i64();tcg_gen_addi_i64(tmp_2, tmp_1, (int64_t)riV); <-
This should be 32 bits
Quoted 9 lines
tcg_temp_free_i64(tmp_1);TCGv_i32tmp_3=tcg_temp_local_new_i32();tcg_gen_trunc_i64_tl(tmp_3, tmp_2);
<- Don't need this truncationtcg_temp_free_i64(tmp_2);gen_write_new_pc(tmp_3);tcg_temp_free_i32(tmp_3);
}
Thanks for spotting this. It's actually a bug in the lexer. The token {IMM_ID}"iV" didn't initialize bit_width. Now it does. This is the result:
void emit_J2_jump(DisasContext *ctx, Insn *insn, Packet *pkt, int riV) /* fIMMEXT(riV); (riV = riV & ~3); (PC = fREAD_PC()+riV);} */ {int64_t qemu_tmp_0 = ~((int64_t)3ULL);int32_t qemu_tmp_1 = riV & qemu_tmp_0;
riV = qemu_tmp_1;TCGv_i32 tmp_0 = tcg_temp_local_new_i32(); tcg_gen_movi_i32(tmp_0, ctx->base.pc_next);TCGv_i32 tmp_1 = tcg_temp_local_new_i32(); tcg_gen_addi_i32(tmp_1, tmp_0, (int64_t)riV); tcg_temp_free_i32(tmp_0);gen_write_new_pc(tmp_1);tcg_temp_free_i32(tmp_1);
}
The (int64_t)riV cast is actually useless so I simply dropped it, thanks for pointing it out.
This is all gonna be in the next patchset ofc.
~Paolo
RE: [PATCH v4 09/12] target/hexagon: import lexer for idef-parser
Quoted 25 lines
From: Paolo Montesel <[email protected]>
Sent: Wednesday, April 28, 2021 5:25 AM
To: Taylor Simpson <[email protected]>
Cc: Alessandro Di Federico <[email protected]>; [email protected]; Brian Cain <[email protected]>; [email protected]; >[email protected]; [email protected]; Alessandro Di Federico <[email protected]>
Subject: Re: [PATCH v4 09/12] target/hexagon: import lexer for idef-parserThanks for spotting this. It's actually a bug in the lexer. The token
{IMM_ID}"iV"didn't initializebit_width. Now it does. This is the >result:void
emit_J2_jump(DisasContext *ctx, Insn *insn, Packet *pkt, int riV)/* fIMMEXT(riV); (riV = riV & ~3); (PC = fREAD_PC()+riV);} */ {int64_tqemu_tmp_0= ~((int64_t)3ULL);int32_tqemu_tmp_1= riV &qemu_tmp_0;
riV =qemu_tmp_1;TCGv_i32tmp_0=tcg_temp_local_new_i32();tcg_gen_movi_i32(tmp_0, ctx->base.pc_next);TCGv_i32tmp_1=tcg_temp_local_new_i32();tcg_gen_addi_i32(tmp_1, tmp_0, (int64_t)riV);tcg_temp_free_i32(tmp_0);gen_write_new_pc(tmp_1);tcg_temp_free_i32(tmp_1);
}
Quoted 5 lines
The
(int64_t)riVcast is actually useless so I simply dropped it, thanks for pointing it out.This is all gonna be in the next patchset ofc.
~Paolo
This could be further simplified by doing the add in the parser and generating
TCGv tmp_1 = tcg_const_tl(ctx->base.pc_next + riV);
Have you looked at the host code that is generated? I would expect it to do the constant folding, so the executed code is OK. However, there's extra time spent building up TCG that could be avoided.
Taylor
Re: [PATCH v4 09/12] target/hexagon: import lexer for idef-parser
Quoted 28 lines · Taylor Simpson
Quoted 28 lines
From: Paolo Montesel <[email protected]>
Sent: Wednesday, April 28, 2021 5:25 AM
To: Taylor Simpson <[email protected]>
Cc: Alessandro Di Federico <[email protected]>; [email protected]; Brian Cain <[email protected]>; [email protected]; >[email protected]; [email protected]; Alessandro Di Federico <[email protected]>
Subject: Re: [PATCH v4 09/12] target/hexagon: import lexer for idef-parserThanks for spotting this. It's actually a bug in the lexer. The token
{IMM_ID}"iV"didn't initializebit_width. Now it does. This is the >result:void
emit_J2_jump(DisasContext *ctx, Insn *insn, Packet *pkt, int riV)/* fIMMEXT(riV); (riV = riV & ~3); (PC = fREAD_PC()+riV);} */ {int64_tqemu_tmp_0= ~((int64_t)3ULL);int32_tqemu_tmp_1= riV &qemu_tmp_0;
riV =qemu_tmp_1;TCGv_i32tmp_0=tcg_temp_local_new_i32();tcg_gen_movi_i32(tmp_0, ctx->base.pc_next);TCGv_i32tmp_1=tcg_temp_local_new_i32();tcg_gen_addi_i32(tmp_1, tmp_0, (int64_t)riV);tcg_temp_free_i32(tmp_0);gen_write_new_pc(tmp_1);tcg_temp_free_i32(tmp_1);
}The
(int64_t)riVcast is actually useless so I simply dropped it, thanks for pointing it out.
Quoted 7 lines
Quoted 3 lines
This is all gonna be in the next patchset ofc.
~Paolo
This could be further simplified by doing the add in the parser and generating
TCGv tmp_1 = tcg_const_tl(ctx->base.pc_next + riV);Have you looked at the host code that is generated? I would expect it to do the constant folding, so the executed code is OK. However, there's extra time spent building up TCG that could be avoided.
I agree. Since relative jumps happen somewhat often, I went ahead and added two immediate types (one for the current PC and one for next PC).
I also noticed that we were using temps for rvalue_materialize when, in fact, we can simply use tcg_const.
Overall it should give a nice improvement.
Anyway, this is how the code looks like now:
void emit_J2_jump(DisasContext *ctx, Insn *insn, Packet *pkt, int riV) /* fIMMEXT(riV); (riV = riV & ~3); (PC = fREAD_PC()+riV);} */ {int64_t qemu_tmp_0 = ~((int64_t)3ULL);int32_t qemu_tmp_1 = riV & qemu_tmp_0;
riV = qemu_tmp_1;int32_t qemu_tmp_2 = ctx->base.pc_next + riV;TCGv_i32 tmp_0 = tcg_const_i32(qemu_tmp_2); gen_write_new_pc(tmp_0);tcg_temp_free_i32(tmp_0);
}
That doesn't look too bad (:
PATCH v4 10/12 target/hexagon: import parser for idef-parser
In reply to Alessandro Di Federico viaFrom: Paolo Montesel <[email protected]>
--- target/hexagon/idef-parser/idef-parser.y | 947 +++++++ target/hexagon/idef-parser/parser-helpers.c | 2374 +++++++++++++++++ target/hexagon/idef-parser/parser-helpers.h | 347 +++ target/hexagon/meson.build | 26 +- tests/docker/dockerfiles/alpine.docker | 1 + tests/docker/dockerfiles/centos7.docker | 1 + tests/docker/dockerfiles/centos8.docker | 1 + tests/docker/dockerfiles/debian10.docker | 2 + .../dockerfiles/fedora-i386-cross.docker | 2 + .../dockerfiles/fedora-win32-cross.docker | 2 + .../dockerfiles/fedora-win64-cross.docker | 2 + tests/docker/dockerfiles/fedora.docker | 1 + tests/docker/dockerfiles/opensuse-leap.docker | 1 + tests/docker/dockerfiles/ubuntu.docker | 2 + tests/docker/dockerfiles/ubuntu1804.docker | 2 + tests/docker/dockerfiles/ubuntu2004.docker | 4 +- 16 files changed, 3713 insertions(+), 2 deletions(-) create mode 100644 target/hexagon/idef-parser/idef-parser.y create mode 100644 target/hexagon/idef-parser/parser-helpers.c create mode 100644 target/hexagon/idef-parser/parser-helpers.h
target/hexagon/idef-parser/idef-parser.y new file +947 -0
@@ -0,0 +1,947 @@ +%{ +/* + * Copyright(c) 2019-2021 rev.ng Srls. All Rights Reserved. + * + * 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 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/>. + */ + +#include "idef-parser.h" +#include "parser-helpers.h" +#include "idef-parser.tab.h" +#include "idef-parser.yy.h" + +/* Uncomment this to disable yyasserts */ +/* #define NDEBUG */ + +#define ERR_LINE_CONTEXT 40 + +%} + +%lex-param {void *scanner} +%parse-param {void *scanner} +%parse-param {Context *c} + +%define parse.error verbose +%define parse.lac full +%define api.pure full + +%locations + +%union { + GString *string; + HexValue rvalue; + HexSat sat; + HexCast cast; + HexExtract extract; + HexMpy mpy; + bool is_unsigned; + int index; +} + +/* Tokens */ +%start input + +%expect 1 + +%token INAME DREG DIMM DPRE DEA RREG WREG FREG FIMM RPRE WPRE FPRE FWRAP FEA VAR +%token POW ABS CROUND ROUND CIRCADD COUNTONES INC DEC ANDA ORA XORA PLUSPLUS ASL +%token ASR LSR EQ NEQ LTE GTE MIN MAX ANDL ORL FOR ICIRC IF MUN FSCR FCHK SXT +%token ZXT CONSTEXT LOCNT BREV SIGN LOAD STORE CONSTLL CONSTULL PC NPC LPCFG +%token CANCEL IDENTITY PART1 BREV_4 BREV_8 ROTL INSBITS SETBITS EXTBITS EXTRANGE +%token CAST4_8U SETOVF FAIL DEINTERLEAVE INTERLEAVE CARRY_FROM_ADD + +%token <rvalue> REG IMM PRE +%token <index> ELSE +%token <mpy> MPY +%token <sat> SAT +%token <cast> CAST DEPOSIT SETHALF +%token <extract> EXTRACT +%type <string> INAME +%type <rvalue> rvalue lvalue VAR assign_statement var +%type <rvalue> DREG DIMM DPRE RREG RPRE FAIL +%type <index> if_stmt IF +%type <is_unsigned> SIGN + +/* Operator Precedences */ +%left MIN MAX +%left '(' +%left ',' +%left '=' +%right CIRCADD +%right INC DEC ANDA ORA XORA +%left '?' ':' +%left ORL +%left ANDL +%left '|' +%left '^' ANDOR +%left '&' +%left EQ NEQ +%left '<' '>' LTE GTE +%left ASL ASR LSR +%right ABS +%left '-' '+' +%left POW +%left '*' '/' '%' MPY +%right '~' '!' +%left '[' +%right CAST +%right LOCNT BREV + +/* Bison Grammar */ +%% + +/* Input file containing the description of each hexagon instruction */ +input : instructions + { + YYACCEPT; + } + ; + +instructions : instruction instructions + | %empty + ; + +instruction : INAME + { + gen_inst(c, $1); + } + arguments + { + gen_inst_args(c, &@1); + } + code + { + gen_inst_code(c, &@1); + } + | error /* Recover gracefully after instruction compilation error */ + { + free_instruction(c); + } + ; + +arguments : '(' ')' + | '(' argument_list ')'; + +argument_list : decl ',' argument_list + | decl + ; + +var : VAR + { + track_string(c, $1.var.name); + $$ = $1; + } + ; + +/* Return the modified registers list */ +code : '{' statements '}' + { + c->inst.code_begin = c->input_buffer + @2.first_column; + c->inst.code_end = c->input_buffer + @2.last_column - 1; + } + | '{' + { + /* Nop */ + } + '}' + ; + +decl : REG + { + emit_arg(c, &@1, &$1); + /* Enqueue register into initialization list */ + g_array_append_val(c->inst.init_list, $1); + } + | IMM + { + EMIT_SIG(c, ", int %ciV", $1.imm.id); + } + | PRE + { + emit_arg(c, &@1, &$1); + /* Enqueue predicate into initialization list */ + g_array_append_val(c->inst.init_list, $1); + } + | var + { + yyassert(c, &@1, !strcmp($1.var.name->str, "EA"), + "Unknown argument variable!"); + } + | RREG + { + emit_arg(c, &@1, &$1); + } + | WREG + | FREG + | FIMM + | RPRE + { + emit_arg(c, &@1, &$1); + } + | WPRE + | FPRE + | FEA + ; + +code_block : '{' statements '}' + | '{' '}' + ; + +/* A list of one or more statements */ +statements : statements statement + | statement + ; + +/* Statements can be assignment (rvalue ';'), control or memory statements */ +statement : control_statement + | rvalue ';' + { + rvalue_free(c, &@1, &$1); + } + | code_block + | ';' + ; + +assign_statement : lvalue '=' rvalue + { + @1.last_column = @3.last_column; + gen_assign(c, &@1, &$1, &$3); + $$ = $1; + } + | lvalue INC rvalue + { + @1.last_column = @3.last_column; + HexValue tmp = gen_bin_op(c, &@1, ADD_OP, &$1, &$3); + gen_assign(c, &@1, &$1, &tmp); + $$ = $1; + } + | lvalue DEC rvalue + { + @1.last_column = @3.last_column; + HexValue tmp = gen_bin_op(c, &@1, SUB_OP, &$1, &$3); + gen_assign(c, &@1, &$1, &tmp); + $$ = $1; + } + | lvalue ANDA rvalue + { + @1.last_column = @3.last_column; + HexValue tmp = gen_bin_op(c, &@1, ANDB_OP, &$1, &$3); + gen_assign(c, &@1, &$1, &tmp); + $$ = $1; + } + | lvalue ORA rvalue + { + @1.last_column = @3.last_column; + HexValue tmp = gen_bin_op(c, &@1, ORB_OP, &$1, &$3); + gen_assign(c, &@1, &$1, &tmp); + $$ = $1; + } + | lvalue XORA rvalue + { + @1.last_column = @3.last_column; + HexValue tmp = gen_bin_op(c, &@1, XORB_OP, &$1, &$3); + gen_assign(c, &@1, &$1, &tmp); + $$ = $1; + } + | PRE '=' rvalue + { + @1.last_column = @3.last_column; + gen_pre_assign(c, &@1, &$1, &$3); + } + | IMM '=' rvalue + { + @1.last_column = @3.last_column; + yyassert(c, &@1, $3.type == IMMEDIATE, + "Cannot assign non-immediate to immediate!"); + yyassert(c, &@1, $1.imm.type == VARIABLE, + "Cannot assign to non-variable!"); + /* Assign to the function argument */ + OUT(c, &@1, &$1, " = ", &$3, ";\n"); + $$ = $1; + } + | PC '=' rvalue + { + @1.last_column = @3.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + $3 = rvalue_truncate(c, &@1, &$3); + $3 = rvalue_materialize(c, &@1, &$3); + OUT(c, &@1, "gen_write_new_pc(", &$3, ");\n"); + rvalue_free(c, &@1, &$3); /* Free temporary value */ + } + | LOAD '(' IMM ',' IMM ',' SIGN ',' var ',' lvalue ')' + { + @1.last_column = @12.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + gen_load(c, &@1, &$3, &$5, $7, &$9, &$11); + } + | STORE '(' IMM ',' IMM ',' var ',' rvalue ')' + /* Store primitive */ + { + @1.last_column = @10.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + gen_store(c, &@1, &$3, &$5, &$7, &$9); + } + | LPCFG '=' rvalue + { + @1.last_column = @3.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + $3 = rvalue_truncate(c, &@1, &$3); + $3 = rvalue_materialize(c, &@1, &$3); + OUT(c, &@1, "SET_USR_FIELD(USR_LPCFG, ", &$3, ");\n"); + rvalue_free(c, &@1, &$3); + } + | DEPOSIT '(' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + gen_deposit_op(c, &@1, &$5, &$7, &$3, &$1); + } + | SETHALF '(' rvalue ',' lvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + gen_sethalf(c, &@1, &$1, &$3, &$5, &$7); + } + | SETBITS '(' rvalue ',' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @10.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + gen_setbits(c, &@1, &$3, &$5, &$7, &$9); + } + | INSBITS '(' lvalue ',' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @10.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + gen_rdeposit_op(c, &@1, &$3, &$9, &$7, &$5); + } + | IDENTITY '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = $3; + } + ; + +control_statement : frame_check + | cancel_statement + | if_statement + | for_statement + | fpart1_statement + ; + +frame_check : FCHK '(' rvalue ',' rvalue ')' ';' + { + rvalue_free(c, &@1, &$3); + rvalue_free(c, &@1, &$5); + } + ; + +cancel_statement : CANCEL + { + OUT(c, &@1, "gen_cancel(insn->slot);\n"); + } + ; + +if_statement : if_stmt + { + /* Fix else label */ + OUT(c, &@1, "gen_set_label(if_label_", &$1, ");\n"); + } + | if_stmt ELSE + { + @1.last_column = @2.last_column; + $2 = gen_if_else(c, &@1, $1); + } + statement + { + OUT(c, &@1, "gen_set_label(if_label_", &$2, ");\n"); + } + ; + +for_statement : FOR '(' IMM '=' IMM ';' IMM '<' IMM ';' IMM PLUSPLUS ')' + { + @1.last_column = @13.last_column; + OUT(c, &@1, "for (int ", &$3, " = ", &$5, "; ", + &$7, " < ", &$9); + OUT(c, &@1, "; ", &$11, "++) {\n"); + } + code_block + { + OUT(c, &@1, "}\n"); + } + | FOR '(' IMM '=' IMM ';' IMM '<' IMM ';' IMM INC IMM ')' + { + @1.last_column = @14.last_column; + OUT(c, &@1, "for (int ", &$3, " = ", &$5, "; ", + &$7, " < ", &$9); + OUT(c, &@1, "; ", &$11, " += ", &$13, ") {\n"); + } + code_block + { + OUT(c, &@1, "}\n"); + } + ; + +fpart1_statement : PART1 + { + OUT(c, &@1, "if (insn->part1) {\n"); + } + '(' statements ')' + { + @1.last_column = @3.last_column; + OUT(c, &@1, "return; }\n"); + } + ; + +if_stmt : IF '(' rvalue ')' + { + @1.last_column = @3.last_column; + $1 = gen_if_cond(c, &@1, &$3); + } + statement + { + $$ = $1; + } + ; + +rvalue : FAIL + { + yyassert(c, &@1, false, "Encountered a FAIL token as rvalue.\n"); + } + | assign_statement + | REG + { + if ($1.reg.type == CONTROL) { + $$ = gen_read_creg(c, &@1, &$1); + } else { + $$ = $1; + } + } + | IMM + { + $$ = $1; + } + | CONSTLL '(' IMM ')' + { + $3.is_unsigned = false; + $3.bit_width = 64; + $$ = $3; + } + | CONSTULL '(' IMM ')' + { + $3.is_unsigned = true; + $3.bit_width = 64; + $$ = $3; + } + | PRE + { + $$ = gen_rvalue_pre(c, &@1, &$1); + } + | PC + { + /* Read PC from the CR */ + $$ = gen_tmp(c, &@1, 32); + OUT(c, &@1, "tcg_gen_movi_i32(", &$$, ", ctx->base.pc_next);\n"); + } + | NPC + { + /* NPC is only read from CALLs, so we can hardcode it + at translation time */ + $$ = gen_tmp(c, &@1, 32); + OUT(c, &@1, "tcg_gen_movi_i32(", &$$, ", ctx->npc);\n"); + } + | CONSTEXT + { + HexValue rvalue; + rvalue.type = IMMEDIATE; + rvalue.imm.type = IMM_CONSTEXT; + rvalue.is_unsigned = true; + rvalue.is_dotnew = false; + rvalue.is_manual = false; + $$ = rvalue; + } + | var + { + $$ = gen_rvalue_var(c, &@1, &$1); + } + | MPY '(' rvalue ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_rvalue_mpy(c, &@1, &$1, &$3, &$5); + } + | rvalue '+' rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, ADD_OP, &$1, &$3); + } + | rvalue '-' rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, SUB_OP, &$1, &$3); + } + | rvalue '*' rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, MUL_OP, &$1, &$3); + } + | rvalue POW rvalue + { + @1.last_column = @3.last_column; + $$ = gen_rvalue_pow(c, &@1, &$1, &$3); + } + | rvalue '%' rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, MOD_OP, &$1, &$3); + } + | rvalue ASL rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, ASL_OP, &$1, &$3); + } + | rvalue ASR rvalue + { + @1.last_column = @3.last_column; + if ($1.is_unsigned) { + $$ = gen_bin_op(c, &@1, LSR_OP, &$1, &$3); + } else { + $$ = gen_bin_op(c, &@1, ASR_OP, &$1, &$3); + } + } + | rvalue LSR rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, LSR_OP, &$1, &$3); + } + | rvalue '&' rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, ANDB_OP, &$1, &$3); + } + | rvalue '|' rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, ORB_OP, &$1, &$3); + } + | rvalue '^' rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, XORB_OP, &$1, &$3); + } + | rvalue ANDL rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, ANDL_OP, &$1, &$3); + } + | MIN '(' rvalue ',' rvalue ')' + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, MINI_OP, &$3, &$5); + } + | MAX '(' rvalue ',' rvalue ')' + { + @1.last_column = @3.last_column; + $$ = gen_bin_op(c, &@1, MAXI_OP, &$3, &$5); + } + | '~' rvalue + { + @1.last_column = @2.last_column; + $$ = gen_rvalue_not(c, &@1, &$2); + } + | '!' rvalue + { + @1.last_column = @2.last_column; + $$ = gen_rvalue_notl(c, &@1, &$2); + } + | SAT '(' IMM ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_rvalue_sat(c, &@1, &$1, &$3, &$5); + } + | CAST rvalue + { + @1.last_column = @2.last_column; + /* Assign target signedness */ + $2.is_unsigned = $1.is_unsigned; + $$ = gen_cast_op(c, &@1, &$2, $1.bit_width); + $$.is_unsigned = $1.is_unsigned; + } + | rvalue '[' rvalue ']' + { + @1.last_column = @4.last_column; + if ($3.type == IMMEDIATE) { + $$ = gen_tmp(c, &@1, $1.bit_width); + OUT(c, &@1, "tcg_gen_extract_i", &$$.bit_width, "("); + OUT(c, &@1, &$$, ", ", &$1, ", ", &$3, ", 1);\n"); + } else { + HexValue one = gen_imm_value(c, &@1, 1, $3.bit_width); + HexValue tmp = gen_bin_op(c, &@1, ASR_OP, &$1, &$3); + $$ = gen_bin_op(c, &@1, ANDB_OP, &tmp, &one); + } + } + | rvalue EQ rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_cmp(c, &@1, TCG_COND_EQ, &$1, &$3); + } + | rvalue NEQ rvalue + { + @1.last_column = @3.last_column; + $$ = gen_bin_cmp(c, &@1, TCG_COND_NE, &$1, &$3); + } + | rvalue '<' rvalue + { + @1.last_column = @3.last_column; + if ($1.is_unsigned || $3.is_unsigned) { + $$ = gen_bin_cmp(c, &@1, TCG_COND_LTU, &$1, &$3); + } else { + $$ = gen_bin_cmp(c, &@1, TCG_COND_LT, &$1, &$3); + } + } + | rvalue '>' rvalue + { + @1.last_column = @3.last_column; + if ($1.is_unsigned || $3.is_unsigned) { + $$ = gen_bin_cmp(c, &@1, TCG_COND_GTU, &$1, &$3); + } else { + $$ = gen_bin_cmp(c, &@1, TCG_COND_GT, &$1, &$3); + } + } + | rvalue LTE rvalue + { + @1.last_column = @3.last_column; + if ($1.is_unsigned || $3.is_unsigned) { + $$ = gen_bin_cmp(c, &@1, TCG_COND_LEU, &$1, &$3); + } else { + $$ = gen_bin_cmp(c, &@1, TCG_COND_LE, &$1, &$3); + } + } + | rvalue GTE rvalue + { + @1.last_column = @3.last_column; + if ($1.is_unsigned || $3.is_unsigned) { + $$ = gen_bin_cmp(c, &@1, TCG_COND_GEU, &$1, &$3); + } else { + $$ = gen_bin_cmp(c, &@1, TCG_COND_GE, &$1, &$3); + } + } + | rvalue '?' + { + $1.is_manual = true; + Ternary t = {0}; + t.state = IN_LEFT; + t.cond = $1; + g_array_append_val(c->ternary, t); + } + rvalue ':' + { + Ternary *t = &g_array_index(c->ternary, Ternary, + c->ternary->len - 1); + t->state = IN_RIGHT; + } + rvalue + { + @1.last_column = @5.last_column; + $$ = gen_rvalue_ternary(c, &@1, &$1, &$4, &$7); + } + | FSCR '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_rvalue_fscr(c, &@1, &$3); + } + | SXT '(' rvalue ',' IMM ',' rvalue ')' + { + @1.last_column = @8.last_column; + yyassert(c, &@1, $5.type == IMMEDIATE && + $5.imm.type == VALUE, + "SXT expects immediate values\n"); + $5.imm.value = 64; + $$ = gen_extend_op(c, &@1, &$3, &$5, &$7, false); + } + | ZXT '(' rvalue ',' IMM ',' rvalue ')' + { + @1.last_column = @8.last_column; + yyassert(c, &@1, $5.type == IMMEDIATE && + $5.imm.type == VALUE, + "ZXT expects immediate values\n"); + $$ = gen_extend_op(c, &@1, &$3, &$5, &$7, true); + } + | '(' rvalue ')' + { + $$ = $2; + } + | ABS rvalue + { + @1.last_column = @2.last_column; + $$ = gen_rvalue_abs(c, &@1, &$2); + } + | CROUND '(' rvalue ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_convround_n(c, &@1, &$3, &$5); + } + | CROUND '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_convround(c, &@1, &$3); + } + | ROUND '(' rvalue ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_round(c, &@1, &$3, &$5); + } + | '-' rvalue + { + @1.last_column = @2.last_column; + $$ = gen_rvalue_neg(c, &@1, &$2); + } + | ICIRC '(' rvalue ')' ASL IMM + { + @1.last_column = @6.last_column; + $$ = gen_tmp(c, &@1, 32); + OUT(c, &@1, "gen_read_ireg(", &$$, ", ", &$3, ", ", &$6, ");\n"); + rvalue_free(c, &@1, &$3); + } + | CIRCADD '(' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + gen_circ_op(c, &@1, &$3, &$5, &$7); + } + | LOCNT '(' rvalue ')' + { + @1.last_column = @4.last_column; + /* Leading ones count */ + $$ = gen_locnt_op(c, &@1, &$3); + } + | COUNTONES '(' rvalue ')' + { + @1.last_column = @4.last_column; + /* Ones count */ + $$ = gen_ctpop_op(c, &@1, &$3); + } + | LPCFG + { + $$ = gen_tmp_value(c, &@1, "0", 32); + OUT(c, &@1, "tcg_gen_extract_tl(", &$$, + ", hex_gpr[HEX_REG_USR], "); + OUT(c, &@1, "reg_field_info[USR_LPCFG].offset, "); + OUT(c, &@1, "reg_field_info[USR_LPCFG].width);\n"); + } + | EXTRACT '(' rvalue ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_extract_op(c, &@1, &$5, &$3, &$1); + } + | EXTBITS '(' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + yyassert(c, &@1, $5.type == IMMEDIATE && + $5.imm.type == VALUE && + $7.type == IMMEDIATE && + $7.imm.type == VALUE, + "Range extract needs immediate values!\n"); + $$ = gen_rextract_op(c, &@1, &$3, $7.imm.value, $5.imm.value); + } + | EXTRANGE '(' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + yyassert(c, &@1, $5.type == IMMEDIATE && + $5.imm.type == VALUE && + $7.type == IMMEDIATE && + $7.imm.type == VALUE, + "Range extract needs immediate values!\n"); + $$ = gen_rextract_op(c, + &@1, + &$3, + $7.imm.value, + $5.imm.value - $7.imm.value + 1); + } + | CAST4_8U '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = rvalue_truncate(c, &@1, &$3); + $$.is_unsigned = true; + $$ = rvalue_materialize(c, &@1, &$$); + $$ = rvalue_extend(c, &@1, &$$); + } + | BREV '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_rvalue_brev(c, &@1, &$3); + } + | BREV_4 '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_fbrev_4(c, &@1, &$3); + } + | BREV_8 '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_fbrev_8(c, &@1, &$3); + } + | ROTL '(' rvalue ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_rotl(c, &@1, &$3, &$5); + } + | SETOVF '(' ')' + { + @1.last_column = @3.last_column; + HexValue ovfl = gen_imm_value(c, &@1, 1, 32); + gen_set_overflow(c, &@1, &ovfl); + } + | SETOVF '(' rvalue ')' + { + /* Convenience fSET_OVERFLOW with pass-through */ + @1.last_column = @3.last_column; + HexValue ovfl = gen_imm_value(c, &@1, 1, 32); + gen_set_overflow(c, &@1, &ovfl); + $$ = $3; + } + | DEINTERLEAVE '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_deinterleave(c, &@1, &$3); + } + | INTERLEAVE '(' rvalue ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_interleave(c, &@1, &$3, &$5); + } + | CARRY_FROM_ADD '(' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + $$ = gen_carry_from_add(c, &@1, &$3, &$5, &$7); + } + ; + +lvalue : FAIL + { + @1.last_column = @1.last_column; + yyassert(c, &@1, false, "Encountered a FAIL token as lvalue.\n"); + } + | REG + { + $$ = $1; + } + | var + { + $$ = $1; + } + ; + +%% + +int main(int argc, char **argv) +{ + if (argc != 5) { + fprintf(stderr, + "Semantics: Hexagon ISA to tinycode generator compiler\n\n"); + fprintf(stderr, + "Usage: ./semantics IDEFS EMITTER_C EMITTER_H " + "ENABLED_INSTRUCTIONS_LIST\n"); + return 1; + } + + enum { + ARG_INDEX_ARGV0 = 0, + ARG_INDEX_IDEFS, + ARG_INDEX_EMITTER_C, + ARG_INDEX_EMITTER_H, + ARG_INDEX_ENABLED_INSTRUCTIONS_LIST + }; + + FILE *enabled_file = fopen(argv[ARG_INDEX_ENABLED_INSTRUCTIONS_LIST], "w"); + + FILE *output_file = fopen(argv[ARG_INDEX_EMITTER_C], "w"); + fputs("#include \"qemu/osdep.h\"\n", output_file); + fputs("#include \"qemu/log.h\"\n", output_file); + fputs("#include \"cpu.h\"\n", output_file); + fputs("#include \"internal.h\"\n", output_file); + fputs("#include \"tcg/tcg-op.h\"\n", output_file); + fputs("#include \"insn.h\"\n", output_file); + fputs("#include \"opcodes.h\"\n", output_file); + fputs("#include \"translate.h\"\n", output_file); + fputs("#define QEMU_GENERATE\n", output_file); + fputs("#include \"genptr.h\"\n", output_file); + fputs("#include \"tcg/tcg.h\"\n", output_file); + fputs("#include \"macros.h\"\n", output_file); + fprintf(output_file, "#include \"%s\"\n", argv[ARG_INDEX_EMITTER_H]); + + FILE *defines_file = fopen(argv[ARG_INDEX_EMITTER_H], "w"); + assert(defines_file != NULL); + fputs("#ifndef HEX_EMITTER_H\n", defines_file); + fputs("#define HEX_EMITTER_H\n", defines_file); + fputs("\n", defines_file); + fputs("#include \"insn.h\"\n\n", defines_file); + + /* Parser input file */ + Context context = { 0 }; + context.defines_file = defines_file; + context.output_file = output_file; + context.enabled_file = enabled_file; + /* Initialize buffers */ + context.out_str = g_string_new(NULL); + context.signature_str = g_string_new(NULL); + context.header_str = g_string_new(NULL); + context.ternary = g_array_new(FALSE, TRUE, sizeof(Ternary)); + /* Read input file */ + FILE *input_file = fopen(argv[ARG_INDEX_IDEFS], "r"); + fseek(input_file, 0L, SEEK_END); + long input_size = ftell(input_file); + context.input_buffer = (char *) calloc(input_size + 1, sizeof(char)); + fseek(input_file, 0L, SEEK_SET); + size_t read_chars = fread(context.input_buffer, + sizeof(char), + input_size, + input_file); + if (read_chars != input_size) { + fprintf(stderr, "Error: an error occurred while reading input file!\n"); + return -1; + } + yylex_init(&context.scanner); + YY_BUFFER_STATE buffer; + buffer = yy_scan_string(context.input_buffer, context.scanner); + /* Start the parsing procedure */ + yyparse(context.scanner, &context); + if (context.implemented_insn != context.total_insn) { + fprintf(stderr, + "Warning: %d/%d meta instructions have been implemented!\n", + context.implemented_insn, + context.total_insn); + } + fputs("#endif " START_COMMENT " HEX_EMITTER_h " END_COMMENT "\n", + defines_file); + /* Cleanup */ + yy_delete_buffer(buffer, context.scanner); + yylex_destroy(context.scanner); + free(context.input_buffer); + g_string_free(context.out_str, TRUE); + g_string_free(context.signature_str, TRUE); + g_string_free(context.header_str, TRUE); + g_array_free(context.ternary, TRUE); + fclose(output_file); + fclose(input_file); + fclose(defines_file); + fclose(enabled_file); + + return 0; +}
target/hexagon/idef-parser/parser-helpers.c new file +2374 -0
2,053 lines not on this page · raw message
target/hexagon/idef-parser/parser-helpers.h new file +347 -0
347 lines not on this page · raw message
tests/docker/dockerfiles/centos7.docker +1 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/centos8.docker +1 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/debian10.docker +2 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/fedora-i386-cross.docker +2 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/fedora-win32-cross.docker +2 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/fedora-win64-cross.docker +2 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/opensuse-leap.docker +1 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/ubuntu1804.docker +2 -0
Lines of this file are not shown. View the raw message.
tests/docker/dockerfiles/ubuntu2004.docker +3 -1
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1
Part of the diff is not shown here. View the raw message.
PATCH v4 11/12 target/hexagon: call idef-parser functions
In reply to Alessandro Di Federico viaFrom: Alessandro Di Federico <[email protected]>
Extend gen_tcg_funcs.py in order to emit calls to the functions emitted by the idef-parser, if available.
--- target/hexagon/gen_tcg_funcs.py | 28 ++++++++++++++++++++++++++-- target/hexagon/hex_common.py | 10 ++++++++++ target/hexagon/meson.build | 22 +++++++++++++--------- 3 files changed, 49 insertions(+), 11 deletions(-)
target/hexagon/gen_tcg_funcs.py +26 -2
@@ -394,7 +394,29 @@ def gen_tcg_func(f, tag, regs, imms): if (hex_common.is_read(regid)): genptr_src_read_opn(f,regtype,regid,tag) - if ( hex_common.skip_qemu_helper(tag) ): + if hex_common.is_idef_parser_enabled(tag): + declared = [] + ## Handle registers + for regtype,regid,toss,numregs in regs: + if (hex_common.is_pair(regid) + or (hex_common.is_single(regid) + and hex_common.is_old_val(regtype, regid, tag))): + declared.append("%s%sV" % (regtype, regid)) + if regtype == "M": + declared.append("%s%sN" % (regtype, regid)) + elif hex_common.is_new_val(regtype, regid, tag): + declared.append("%s%sN" % (regtype,regid)) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + + ## Handle immediates + for immlett,bits,immshift in imms: + declared.append(hex_common.imm_name(immlett)) + + arguments = ", ".join(["ctx", "insn", "pkt"] + declared) + f.write(" emit_%s(%s);\n" % (tag, arguments)) + + elif ( hex_common.skip_qemu_helper(tag) ): f.write(" fGEN_TCG_%s(%s);\n" % (tag, hex_common.semdict[tag])) else: ## Generate the call to the helper
@@ -455,12 +477,14 @@ def main(): hex_common.read_attribs_file(sys.argv[2]) hex_common.read_overrides_file(sys.argv[3]) hex_common.calculate_attribs() + hex_common.read_idef_parser_enabled_file(sys.argv[4]) tagregs = hex_common.get_tagregs() tagimms = hex_common.get_tagimms() - with open(sys.argv[4], 'w') as f: + with open(sys.argv[5], 'w') as f: f.write("#ifndef HEXAGON_TCG_FUNCS_H\n") f.write("#define HEXAGON_TCG_FUNCS_H\n\n") + f.write("#include \"idef-generated-emitter.h.inc\"\n\n") for tag in hex_common.tags: ## Skip the priv instructions
target/hexagon/hex_common.py +10 -0
@@ -28,6 +28,7 @@ attribinfo = {} # Register information and misc tags = [] # list of all tags overrides = {} # tags with helper overrides +idef_parser_enabled = {} # tags enabled for idef-parser # We should do this as a hash for performance, # but to keep order let's keep it as a list.
@@ -201,6 +202,9 @@ def need_ea(tag): def skip_qemu_helper(tag): return tag in overrides.keys() +def is_idef_parser_enabled(tag): + return tag in idef_parser_enabled + def imm_name(immlett): return "%siV" % immlett
@@ -232,3 +236,9 @@ def read_overrides_file(name): continue tag = overridere.findall(line)[0] overrides[tag] = True + +def read_idef_parser_enabled_file(name): + global idef_parser_enabled + with open(name, "r") as idef_parser_enabled_file: + lines = idef_parser_enabled_file.read().strip().split("\n") + idef_parser_enabled = set(lines)
target/hexagon/meson.build +13 -9
@@ -69,15 +69,6 @@ helper_protos_generated = custom_target( ) hexagon_ss.add(helper_protos_generated) -tcg_funcs_generated = custom_target( - 'tcg_funcs_generated.c.inc', - output: 'tcg_funcs_generated.c.inc', - depends: [semantics_generated], - depend_files: [hex_common_py, attribs_def, gen_tcg_h], - command: [python, files('gen_tcg_funcs.py'), semantics_generated, attribs_def, gen_tcg_h, '@OUTPUT@'], -) -hexagon_ss.add(tcg_funcs_generated) - tcg_func_table_generated = custom_target( 'tcg_func_table_generated.c.inc', output: 'tcg_func_table_generated.c.inc',
@@ -221,4 +212,17 @@ idef_generated_tcg = custom_target( command: [idef_parser, '@INPUT@', '@OUTPUT0@', '@OUTPUT1@', '@OUTPUT2@'], ) +idef_generated_list = idef_generated_tcg[2].full_path() + +hexagon_ss.add(idef_generated_tcg) + +tcg_funcs_generated = custom_target( + 'tcg_funcs_generated.c.inc', + output: 'tcg_funcs_generated.c.inc', + depends: [semantics_generated, idef_generated_tcg], + depend_files: [hex_common_py, attribs_def, gen_tcg_h], + command: [python, files('gen_tcg_funcs.py'), semantics_generated, attribs_def, gen_tcg_h, idef_generated_list, '@OUTPUT@'], +) +hexagon_ss.add(tcg_funcs_generated) + target_arch += {'hexagon': hexagon_ss}
Signature · 1 line
2.31.1
RE: [PATCH v4 11/12] target/hexagon: call idef-parser functions
Quoted 49 lines
-----Original Message-----
From: Alessandro Di Federico <[email protected]>
Sent: Thursday, April 15, 2021 11:35 AM
To: [email protected]
Cc: Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Alessandro Di Federico <[email protected]>
Subject: [PATCH v4 11/12] target/hexagon: call idef-parser functionsFrom: Alessandro Di Federico <[email protected]>
Extend
gen_tcg_funcs.pyin order to emit calls to the functions emitted by the idef-parser, if available.Signed-off-by Alessandro Di Federico <[email protected]>--- target/hexagon/gen_tcg_funcs.py | 28 ++++++++++++++++++++++++++-- target/hexagon/hex_common.py | 10 ++++++++++ target/hexagon/meson.build | 22 +++++++++++++--------- 3 files changed, 49 insertions(+), 11 deletions(-)target/hexagon/gen_tcg_funcs.py +16
-1@@ -394,7 +394,29 @@ def gen_tcg_func(f, tag, regs, imms): if (hex_common.is_read(regid)): genptr_src_read_opn(f,regtype,regid,tag) - if ( hex_common.skip_qemu_helper(tag) ): + if hex_common.is_idef_parser_enabled(tag): + declared = [] + ## Handle registers + for regtype,regid,toss,numregs in regs: + if (hex_common.is_pair(regid) + or (hex_common.is_single(regid) + and hex_common.is_old_val(regtype, regid, tag))): + declared.append("%s%sV" % (regtype, regid)) + if regtype == "M": + declared.append("%s%sN" % (regtype, regid)) + elif hex_common.is_new_val(regtype, regid, tag): + declared.append("%s%sN" % (regtype,regid)) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + + ## Handle immediates
target/hexagon/gen_tcg_funcs.py def gen_tcg_func(f, tag, regs, imms): · line 422
Quoted 10 lines
target/hexagon/gen_tcg_funcs.py +7
-0+ for immlett,bits,immshift in imms: + declared.append(hex_common.imm_name(immlett)) + + arguments = ", ".join(["ctx", "insn", "pkt"] + declared) + f.write(" emit_%s(%s);\n" % (tag, arguments)) + + elif ( hex_common.skip_qemu_helper(tag) ): f.write(" fGEN_TCG_%s(%s);\n" % (tag, hex_common.semdict[tag])) else: ## Generate the call to the helper
You should add the hex_common.is_idef_parser_enabled(tag) check to gen_helper_protos.py and gen_helper_funcs.py.
Look for these lines in each of those files
if ( hex_common.skip_qemu_helper(tag) ):
continue
If you add
if ( hex_common.is_idef_parser_enabled(tag) ):
continue
that will greatly reduce the size of helper_protos_generated.c.inc and helper_funcs.c.inc. That will reduce the build time for the Hexagon target as well as the size of the qemu executable.
You'll also need to modify the main function in each of those files and the corresponding invocation in meson.build to do the setup so the check does what you expect.
Thanks,
Taylor
PATCH v4 12/12 target/hexagon: import additional tests
In reply to Alessandro Di Federico viaFrom: Niccolò Izzo <[email protected]>
--- tests/tcg/hexagon/Makefile.target | 36 ++++++++++++++++- tests/tcg/hexagon/crt.S | 28 +++++++++++++ tests/tcg/hexagon/test_abs.S | 20 ++++++++++ tests/tcg/hexagon/test_add.S | 20 ++++++++++ tests/tcg/hexagon/test_andp.S | 23 +++++++++++ tests/tcg/hexagon/test_bitcnt.S | 42 ++++++++++++++++++++ tests/tcg/hexagon/test_bitsplit.S | 25 ++++++++++++ tests/tcg/hexagon/test_call.S | 63 ++++++++++++++++++++++++++++++ tests/tcg/hexagon/test_clobber.S | 35 +++++++++++++++++ tests/tcg/hexagon/test_cmp.S | 34 ++++++++++++++++ tests/tcg/hexagon/test_cmpy.S | 31 +++++++++++++++ tests/tcg/hexagon/test_djump.S | 24 ++++++++++++ tests/tcg/hexagon/test_dotnew.S | 39 ++++++++++++++++++ tests/tcg/hexagon/test_dstore.S | 29 ++++++++++++++ tests/tcg/hexagon/test_ext.S | 18 +++++++++ tests/tcg/hexagon/test_fibonacci.S | 33 ++++++++++++++++ tests/tcg/hexagon/test_hello.S | 21 ++++++++++ tests/tcg/hexagon/test_hl.S | 19 +++++++++ tests/tcg/hexagon/test_hwloops.S | 25 ++++++++++++ tests/tcg/hexagon/test_jmp.S | 25 ++++++++++++ tests/tcg/hexagon/test_lsr.S | 39 ++++++++++++++++++ tests/tcg/hexagon/test_mpyi.S | 20 ++++++++++ tests/tcg/hexagon/test_overflow.S | 63 ++++++++++++++++++++++++++++++ tests/tcg/hexagon/test_packet.S | 26 ++++++++++++ tests/tcg/hexagon/test_reorder.S | 31 +++++++++++++++ tests/tcg/hexagon/test_round.S | 31 +++++++++++++++ tests/tcg/hexagon/test_vavgw.S | 33 ++++++++++++++++ tests/tcg/hexagon/test_vcmpb.S | 32 +++++++++++++++ tests/tcg/hexagon/test_vcmpw.S | 29 ++++++++++++++ tests/tcg/hexagon/test_vcmpy.S | 50 ++++++++++++++++++++++++ tests/tcg/hexagon/test_vlsrw.S | 23 +++++++++++ tests/tcg/hexagon/test_vmaxh.S | 37 ++++++++++++++++++ tests/tcg/hexagon/test_vminh.S | 37 ++++++++++++++++++ tests/tcg/hexagon/test_vpmpyh.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vspliceb.S | 33 ++++++++++++++++ 35 files changed, 1103 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/crt.S create mode 100644 tests/tcg/hexagon/test_abs.S create mode 100644 tests/tcg/hexagon/test_add.S create mode 100644 tests/tcg/hexagon/test_andp.S create mode 100644 tests/tcg/hexagon/test_bitcnt.S create mode 100644 tests/tcg/hexagon/test_bitsplit.S create mode 100644 tests/tcg/hexagon/test_call.S create mode 100644 tests/tcg/hexagon/test_clobber.S create mode 100644 tests/tcg/hexagon/test_cmp.S create mode 100644 tests/tcg/hexagon/test_cmpy.S create mode 100644 tests/tcg/hexagon/test_djump.S create mode 100644 tests/tcg/hexagon/test_dotnew.S create mode 100644 tests/tcg/hexagon/test_dstore.S create mode 100644 tests/tcg/hexagon/test_ext.S create mode 100644 tests/tcg/hexagon/test_fibonacci.S create mode 100644 tests/tcg/hexagon/test_hello.S create mode 100644 tests/tcg/hexagon/test_hl.S create mode 100644 tests/tcg/hexagon/test_hwloops.S create mode 100644 tests/tcg/hexagon/test_jmp.S create mode 100644 tests/tcg/hexagon/test_lsr.S create mode 100644 tests/tcg/hexagon/test_mpyi.S create mode 100644 tests/tcg/hexagon/test_overflow.S create mode 100644 tests/tcg/hexagon/test_packet.S create mode 100644 tests/tcg/hexagon/test_reorder.S create mode 100644 tests/tcg/hexagon/test_round.S create mode 100644 tests/tcg/hexagon/test_vavgw.S create mode 100644 tests/tcg/hexagon/test_vcmpb.S create mode 100644 tests/tcg/hexagon/test_vcmpw.S create mode 100644 tests/tcg/hexagon/test_vcmpy.S create mode 100644 tests/tcg/hexagon/test_vlsrw.S create mode 100644 tests/tcg/hexagon/test_vmaxh.S create mode 100644 tests/tcg/hexagon/test_vminh.S create mode 100644 tests/tcg/hexagon/test_vpmpyh.S create mode 100644 tests/tcg/hexagon/test_vspliceb.S
tests/tcg/hexagon/Makefile.target +35 -1
@@ -32,7 +32,7 @@ CFLAGS += -Wno-incompatible-pointer-types -Wno-undefined-internal HEX_SRC=$(SRC_PATH)/tests/tcg/hexagon VPATH += $(HEX_SRC) -first: $(HEX_SRC)/first.S +%: $(HEX_SRC)/%.S $(HEX_SRC)/crt.S $(CC) -static -mv67 -nostdlib $^ -o $@ HEX_TESTS = first
@@ -43,4 +43,38 @@ HEX_TESTS += mem_noshuf HEX_TESTS += atomics HEX_TESTS += fpstuff +HEX_TESTS += test_abs +HEX_TESTS += test_add +HEX_TESTS += test_andp +HEX_TESTS += test_bitcnt +HEX_TESTS += test_bitsplit +HEX_TESTS += test_call +HEX_TESTS += test_clobber +HEX_TESTS += test_cmp +HEX_TESTS += test_cmpy +HEX_TESTS += test_djump +HEX_TESTS += test_dotnew +HEX_TESTS += test_dstore +HEX_TESTS += test_ext +HEX_TESTS += test_fibonacci +HEX_TESTS += test_hello +HEX_TESTS += test_hl +HEX_TESTS += test_hwloops +HEX_TESTS += test_jmp +HEX_TESTS += test_lsr +HEX_TESTS += test_mpyi +HEX_TESTS += test_overflow +HEX_TESTS += test_packet +HEX_TESTS += test_reorder +HEX_TESTS += test_round +HEX_TESTS += test_vavgw +HEX_TESTS += test_vcmpb +HEX_TESTS += test_vcmpw +HEX_TESTS += test_vcmpy +HEX_TESTS += test_vlsrw +HEX_TESTS += test_vmaxh +HEX_TESTS += test_vminh +HEX_TESTS += test_vpmpyh +HEX_TESTS += test_vspliceb + TESTS += $(HEX_TESTS)
tests/tcg/hexagon/crt.S new file +28 -0
@@ -0,0 +1,28 @@ +#define SYS_exit_group 94 + + .text + .globl init +init: + { + allocframe(r29,#0):raw + } + { + r0=#256 + } + { + dealloc_return + } + + .space 240 + + .globl pass +pass: + r0 = #0 + r6 = #SYS_exit_group + trap0(#1) + + .globl fail +fail: + r0 = #1 + r6 = #SYS_exit_group + trap0(#1)
tests/tcg/hexagon/test_abs.S new file +20 -0
@@ -0,0 +1,20 @@ +/* Purpose: test example, verify the soundness of the abs operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#-2 + r2=#2 + } + { + r3=abs(r1) + } + { + p0 = cmp.eq(r3, r2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_add.S new file +20 -0
@@ -0,0 +1,20 @@ +/* Purpose: test example, verify the soundness of the add operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#0 + r2=#0 + } + { + r3=add(r1,r2) + } + { + p0 = cmp.eq(r3, #0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_andp.S new file +23 -0
@@ -0,0 +1,23 @@ +/* Purpose: test a multiple predicate AND combination */ + + .text + .globl _start + +_start: + { + r1+=sub(r2,r3) + call init + } + { + r0=#0 + r1=#1 + } + { + p0=cmp.gt(r0,r1) + p0=cmp.gt(r0,r1) + p0=cmp.gt(r1,r0) + } + { + if (!p0) jump:t pass + jump fail + }
tests/tcg/hexagon/test_bitcnt.S new file +42 -0
42 lines not on this page · raw message
tests/tcg/hexagon/test_bitsplit.S new file +25 -0
@@ -0,0 +1,25 @@ +/* Purpose: test example, verify the soundness of the bitsplit operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#187 + } + { + r3:2=bitsplit(r1, #3) + } + { + p0 = cmp.eq(r2, #3); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r3, #23); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_call.S new file +63 -0
63 lines not on this page · raw message
tests/tcg/hexagon/test_clobber.S new file +35 -0
@@ -0,0 +1,35 @@ +/* Purpose: demonstrate the succesful operation of the register save mechanism, + * in which the caller saves the registers that will be clobbered, and restores + * them after the call. + */ + + .text + .globl _start + +_start: + { + call init + } + { + r16=#47 + r17=#155 + } + { + memd(r29+#-16)=r17:16; allocframe(#8) + } + { + r16=#255 + r17=#42 + } + { + r17:16=memd(r29+#0); deallocframe + } + { + r3=add(r16,r17) + } + { + p0 = cmp.eq(r3, #202); if (p0.new) jump:t pass + } + { + jump fail + }
tests/tcg/hexagon/test_cmp.S new file +34 -0
@@ -0,0 +1,34 @@ +/* Purpose: test a signed and unsigned comparison */ + + .text + .globl _start + +_start: + { + call init + } + { + jump signed + } + + .globl signed +signed: + { + r0=#-2 + r1=#0 + } + { + p0 = cmp.lt(r0, r1); if (p0.new) jump:t unsigned + jump fail + } + + .globl unsigned +unsigned: + { + r0=#-2 + r1=#0 + } + { + p0 = cmp.gtu(r0, r1); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_cmpy.S new file +31 -0
@@ -0,0 +1,31 @@ +/* Purpose: test example, verify the soundness of the cmpy operation + * + * 3j+5 * 2j+4 = 22j+14 + * + * the complex multiply between 0x00030005 and 0x00020004 is 0x000000160000000e + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#196613 + r1=#131076 + } + { + r3:2=cmpy(r0, r1):sat + } + { + p0 = cmp.eq(r2, #14); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r3, #22); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_djump.S new file +24 -0
@@ -0,0 +1,24 @@ +/* Purpose: show dual jumps actually work. This program features a packet where + * two jumps should (in theory) be performed if !P0. However, we correctly + * handle the situation by performing only the first one and ignoring the second + * one. This can be verified by checking that the CPU dump contains 0xDEADBEEF + * in R2. + */ + + .text + .globl _start + +_start: + { + call init + } + { + r1 = #255; + } + { + p0 = r1; + } + { + if (p0) jump:t pass + jump fail + }
tests/tcg/hexagon/test_dotnew.S new file +39 -0
@@ -0,0 +1,39 @@ +/* Purpose: test the .new operator while performing memory stores. + * In the final CPU dump R0 should contain 3, R1 should contain 2 and R2 should + * contain 1. + */ + .text + .globl _start + +_start: + { + call init + } + { + r0=#1 + memw(sp+#0)=r0.new + } + { + r1=#2 + memw(sp+#4)=r1.new + } + { + r2=#3 + memw(sp+#8)=r2.new + } + { + r0=memw(sp+#8) + } + { + r1=memw(sp+#4) + } + { + r2=memw(sp+#0) + } + { + r3=mpyi(r1,r2) + } + { + p0 = cmp.eq(r3, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_dstore.S new file +29 -0
@@ -0,0 +1,29 @@ +/* Purpose: test dual stores correctness. + * In this example the values 1 and 2 are both written on the top of the stack + * in a single packet. + * The value is then read back in R3, which should contain only the latest value + * written (2). + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#1 + r1=#2 + } + { + memw(sp+#0)=r0 + memw(sp+#0)=r1 + } + { + r3=memw(sp+#0) + } + { + p0 = cmp.eq(r3, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_ext.S new file +18 -0
@@ -0,0 +1,18 @@ +/* Purpose: test immediate extender instructions. + * In the CPU dump R0 should contain 0xDEADBEEF. + */ + + .text + .globl _start + +_start: + { + call init + } + { + r2=##-559038737 + } + { + p0 = cmp.eq(r2, ##-559038737); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_fibonacci.S new file +33 -0
@@ -0,0 +1,33 @@ +/* Purpose: computes the Fibonacci series up to a constant number. */ + + .text + .globl _start + +_start: + { + call init + } + { + r2=#100 + } + { + p0=cmp.gt(r2,#0); if (!p0.new) jump:nt .LBB0_3 + } + { + r3=#0 + r4=#1 + } +.LBB0_2: + { + r5=r4 + } + { + p0=cmp.gt(r2,r5); if (p0.new) jump:nt .LBB0_2 + r4=add(r3,r4) + r3=r5 + } +.LBB0_3: + { + p0 = cmp.eq(r3, #144); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_hello.S new file +21 -0
@@ -0,0 +1,21 @@ +/* Purpose: simple hello world program. */ + + .text + .globl _start + +_start: + { + call init + } + { r0=#4; } + { + r1=##.L.str + } + { trap0(#0); } + { + jump pass + } + +.L.str: + .string "Hello world!\n" + .size .L.str, 14
tests/tcg/hexagon/test_hl.S new file +19 -0
@@ -0,0 +1,19 @@ +/* Purpose: test example, verify the soundness of the high/low assignment */ + + .text + .globl _start + +_start: + { + call init + } + { + r0.H=#42 + } + { + r0.L=#69 + } + { + p0 = cmp.eq(r0, #2752581); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_hwloops.S new file +25 -0
@@ -0,0 +1,25 @@ +/* Purpose: simple C Program to test hardware loops. + * It should print numbersfrom 0 to 9. + */ + + .text + .globl _start + +_start: + { + call init + } + { + loop0(.LBB0_1,#10) + r2=#0 + } +.Ltmp0: +.LBB0_1: + { + r2=add(r2,#1) + nop + }:endloop0 + { + p0 = cmp.eq(r2, #10); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_jmp.S new file +25 -0
@@ -0,0 +1,25 @@ +/* Purpose: test example, verify the soundness of the add operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#0 + r2=#0 + } + { + r3=add(r1,r2) + } + { + p0 = cmp.eq(r3, #0) + } + { + if (p0) jump:t pass + } + { + jump fail + }
tests/tcg/hexagon/test_lsr.S new file +39 -0
@@ -0,0 +1,39 @@ +/* Purpose: test the soundness of the lsr operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#-56984 + r1=#2147483647 + } + { + r2=#0x19 + } + { + r0&=lsr(r1, r2) + } + { + p0 = cmp.eq(r0, #0x28); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r0=#0x0000000a + r1=#0x00000000 + } + { + r2=#-1 + } + { + r1:0=lsl(r1:0, r2) + } + { + p0 = cmp.eq(r0, #0x5); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_mpyi.S new file +20 -0
@@ -0,0 +1,20 @@ +/* Purpose: test a simple multiplication operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#4 + r2=#6 + } + { + r3=mpyi(r1,r2) + } + { + p0 = cmp.eq(r3, #24); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_overflow.S new file +63 -0
63 lines not on this page · raw message
tests/tcg/hexagon/test_packet.S new file +26 -0
@@ -0,0 +1,26 @@ +/* Purpose: test that writes of a register in a packet are performed only after + * that packet has finished its execution. + */ + + .text + .globl _start + +_start: + { + call init + } + { + r2=#4 + r3=#6 + } + { + memw(sp+#0)=r2 + } + { + r3=memw(sp+#0) + r0=add(r2,r3) + } + { + p0 = cmp.eq(r0, #10); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_reorder.S new file +31 -0
@@ -0,0 +1,31 @@ +/* Purpose: demonstrate handling of .new uses appearing before the associated + * definition. + * Here we perform a jump that skips the code resetting R2 from 0xDEADBEEF to 0, + * only if P0.new is true, but P0 is assigned to 1 (R4) in the next instruction + * in the packet. + * A successful run of the program will show R2 retaining the 0xDEADBEEF value + * in the CPU dump. + */ + + .text + .globl _start + +_start: + { + call init + } + { r2=#-559038737 } + { r4=#1 } + { + if (p0.new) jump:nt skip + p0=r4; + } + +fallthrough: + { r2=#0 } + +skip: + { + p0 = cmp.eq(r2, #-559038737); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_round.S new file +31 -0
@@ -0,0 +1,31 @@ +/* Purpose: test example, verify the soundness of the cround operation + * 106 = 0b1101010 with the comma at third digit is 12.5 which is crounded to 12 + * but rounded to 13 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#200 + } + { + r2=round(r1, #4) + } + { + p0 = cmp.eq(r2, #13); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r2=cround(r1, #4) + } + { + p0 = cmp.eq(r2, #12); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vavgw.S new file +33 -0
@@ -0,0 +1,33 @@ +/* Purpose: test example, verify the soundness of the vavgw operation + * + * 0x00030001 averaged with 0x00010003 results 0x00020002 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#3 + r1=#1 + } + { + r2=#1 + r3=#3 + } + { + r1:0=vavgw(r1:0, r3:2):crnd + } + { + p0 = cmp.eq(r0, #2); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpb.S new file +32 -0
@@ -0,0 +1,32 @@ +/* Purpose: test example, verify the soundness of the vector compare bytes + * operation + * + * Vector word comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0x11110000 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#305419896 + r1=#-2023406815 + } + { + r2=#305419896 + r3=#0 + } + { + p2=vcmpb.eq(r1:0, r3:2) + } + { + r4=p2 + } + { + p0 = cmp.eq(r4, #15); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpw.S new file +29 -0
@@ -0,0 +1,29 @@ +/* Purpose: test example, verify the soundness of the vector compare words + * operation + * + * Vector word comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0x11110000 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#305419896 + r1=#-2023406815 + } + { + r2=#305419896 + r3=#0 + } + { + p2=vcmpw.eq(r1:0, r3:2) + } + { + if (p2) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpy.S new file +50 -0
50 lines not on this page · raw message
tests/tcg/hexagon/test_vlsrw.S new file +23 -0
@@ -0,0 +1,23 @@ +/* Purpose: test the soundness of the vlsrw operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#0x00000001 + r1=#0x00000001 + } + { + r1:0=vlsrw(r1:0, #1) + } + { + r0 = add(r0, r1) + } + { + p0 = cmp.eq(r0, #0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vmaxh.S new file +37 -0
@@ -0,0 +1,37 @@ +/* Purpose: test example, verify the soundness of the vrmaxh operation + * + * the maximum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007. + * + * r1=0x00010003 r0=0x00010005 r3=0x00030002 r2=0x00020007 + * result: r1=0x00030003 r0=0x00020007 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#65541 + r1=#65539 + } + { + r2=#131079 + r3=#196610 + } + { + r1:0=vmaxh(r1:0, r3:2) + } + { + p0 = cmp.eq(r0, #131079); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #196611); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vminh.S new file +37 -0
@@ -0,0 +1,37 @@ +/* Purpose: test example, verify the soundness of the vrmaxh operation + * + * the minimum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007 + * + * r1=0x00010003 r0=0x00010005 r3=0x00030002 r2=0x00020007 + * result: r1=0x00010002 r0=0x00010005 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#65541 + r1=#65539 + } + { + r2=#131079 + r3=#196610 + } + { + r1:0=vminh(r1:0, r3:2) + } + { + p0 = cmp.eq(r0, #65541); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #65538); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vpmpyh.S new file +30 -0
@@ -0,0 +1,30 @@ +/* Purpose: test example, verify the soundness of the vpmpyh operator + * + * 0x01020304 vector polynomial multiplied with 0x04030201 results + * 0x000400060b060b04 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#16909060 + r1=#67305985 + } + { + r1:0=vpmpyh(r0, r1) + } + { + p0 = cmp.eq(r0, #184945412); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #262150); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vspliceb.S new file +33 -0
@@ -0,0 +1,33 @@ +/* Purpose: test example, verify the soundness of the vspliceb operation + * the operation is a binary splice of two 64bit operators + * + * vspliceb(0xffffffffffffffff,0x0000000000000000,5) = 0x000000000000001f + */ + .text + .globl _start + +_start: + { + call init + } + { + r0=#-1 + r1=#-1 + } + { + r2=#0 + r3=#0 + } + { + r5:4=vspliceb(r1:0, r3:2, #5) + } + { + p0 = cmp.eq(r4, #-1); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r5, #255); if (p0.new) jump:t pass + jump fail + }
Signature · 1 line
2.31.1