target/hexagon: introduce idef-parser
Subsystems (2)
v8 cover target/hexagon: introduce idef-parser
This patchset introduces the idef-parser for target/hexagon.
It's the eight 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 Pseudocode 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:
* These commits build successfully on the CI (including using clang), with one notable exception. Presently, the build-user-hexagon job fails due to not being able to find flex. We believe this to be caused by debian-hexagon-cross not being built by the CI.
As such the debian-hexagon-cross container will have to be manually rebuilt before merging.
* The eight patch, which introduces flex and bison as new build pre- requisites using libvirt-ci currently points to a fork, not yet merged upstream. This will have to be corrected before the final version of the patchset.
Alessandro Di Federico (4):
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
Anton Johansson (2):
target/hexagon: import flex/bison to docker files target/hexagon: import parser for idef-parser
Niccolò Izzo (2):
target/hexagon: introduce new helper functions
target/hexagon: import additional tests
Paolo Montesel (4):
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
.gitlab-ci.d/cirrus/freebsd-12.vars | 2 +- .gitlab-ci.d/cirrus/freebsd-13.vars | 2 +- .gitlab-ci.d/windows.yml | 2 + .gitmodules | 3 +- MAINTAINERS | 9 + meson_options.txt | 3 + target/hexagon/README | 5 + target/hexagon/gen_helper_funcs.py | 17 +- target/hexagon/gen_helper_protos.py | 17 +- target/hexagon/gen_idef_parser_funcs.py | 125 + target/hexagon/gen_tcg_funcs.py | 41 +- target/hexagon/genptr.c | 230 +- target/hexagon/genptr.h | 44 + target/hexagon/hex_common.py | 10 + target/hexagon/idef-parser/README.rst | 722 +++++ target/hexagon/idef-parser/idef-parser.h | 254 ++ target/hexagon/idef-parser/idef-parser.lex | 566 ++++ target/hexagon/idef-parser/idef-parser.y | 1039 +++++++ target/hexagon/idef-parser/macros.inc | 140 + target/hexagon/idef-parser/parser-helpers.c | 2551 +++++++++++++++++ target/hexagon/idef-parser/parser-helpers.h | 375 +++ target/hexagon/idef-parser/prepare | 24 + target/hexagon/macros.h | 11 +- target/hexagon/meson.build | 138 +- target/hexagon/op_helper.c | 29 +- target/hexagon/op_helper.h | 37 + target/hexagon/translate.c | 3 +- target/hexagon/translate.h | 1 + tests/docker/dockerfiles/alpine.docker | 5 +- tests/docker/dockerfiles/centos8.docker | 7 +- tests/docker/dockerfiles/debian-amd64.docker | 2 + tests/docker/dockerfiles/debian-native.docker | 3 + .../dockerfiles/debian-riscv64-cross.docker | 3 + .../dockerfiles/debian-tricore-cross.docker | 1 + 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 | 5 +- tests/docker/dockerfiles/opensuse-leap.docker | 7 +- tests/docker/dockerfiles/ubuntu1804.docker | 7 +- tests/docker/dockerfiles/ubuntu2004.docker | 7 +- tests/lcitool/libvirt-ci | 2 +- tests/lcitool/projects/qemu.yml | 2 + tests/lcitool/refresh | 2 +- tests/tcg/hexagon/Makefile.target | 28 +- tests/tcg/hexagon/crt.S | 14 + tests/tcg/hexagon/test_abs.S | 17 + tests/tcg/hexagon/test_bitcnt.S | 40 + tests/tcg/hexagon/test_bitsplit.S | 22 + tests/tcg/hexagon/test_call.S | 64 + tests/tcg/hexagon/test_clobber.S | 29 + tests/tcg/hexagon/test_cmp.S | 31 + tests/tcg/hexagon/test_dotnew.S | 38 + tests/tcg/hexagon/test_ext.S | 13 + tests/tcg/hexagon/test_fibonacci.S | 30 + tests/tcg/hexagon/test_hl.S | 16 + tests/tcg/hexagon/test_hwloops.S | 19 + tests/tcg/hexagon/test_jmp.S | 22 + tests/tcg/hexagon/test_lsr.S | 36 + tests/tcg/hexagon/test_mpyi.S | 17 + tests/tcg/hexagon/test_packet.S | 29 + tests/tcg/hexagon/test_reorder.S | 33 + tests/tcg/hexagon/test_round.S | 29 + tests/tcg/hexagon/test_vavgw.S | 31 + tests/tcg/hexagon/test_vcmpb.S | 30 + tests/tcg/hexagon/test_vcmpw.S | 30 + tests/tcg/hexagon/test_vlsrw.S | 20 + tests/tcg/hexagon/test_vmaxh.S | 35 + tests/tcg/hexagon/test_vminh.S | 35 + tests/tcg/hexagon/test_vpmpyh.S | 28 + tests/tcg/hexagon/test_vspliceb.S | 31 + 72 files changed, 7125 insertions(+), 107 deletions(-) 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 target/hexagon/op_helper.h create mode 100644 tests/tcg/hexagon/crt.S create mode 100644 tests/tcg/hexagon/test_abs.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_dotnew.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_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_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_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.34.1
PATCH v8 1/12 target/hexagon: update MAINTAINERS for idef-parser
From: Alessandro Di Federico <[email protected]>
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -200,6 +200,8 @@ 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
@@ -207,6 +209,13 @@ F: configs/targets/hexagon-linux-user/default.mak F: docker/dockerfiles/debian-hexagon-cross.docker F: docker/dockerfiles/debian-hexagon-cross.docker.d/build-toolchain.sh +Hexagon idef-parser +M: Alessandro Di Federico <[email protected]> +M: Anton Johansson <[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.34.1
PATCH v8 2/12 target/hexagon: import README for idef-parser
In reply to Anton Johansson viaFrom: Alessandro Di Federico <[email protected]>
--- target/hexagon/README | 5 + target/hexagon/idef-parser/README.rst | 722 ++++++++++++++++++++++++++ 2 files changed, 727 insertions(+) create mode 100644 target/hexagon/idef-parser/README.rst
target/hexagon/README +5 -0
@@ -27,6 +27,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
@@ -47,6 +51,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 +722 -0
722 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 3/12 target/hexagon: make slot number an unsigned
In reply to Anton Johansson viaFrom: Paolo Montesel <[email protected]>
--- target/hexagon/genptr.c | 24 +++++++++++++----------- target/hexagon/macros.h | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-)
target/hexagon/genptr.c +13 -11
@@ -30,7 +30,8 @@#include "gen_tcg.h" #include "gen_tcg_hvx.h" -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, +uint32_t slot) {TCGv zero =tcg_constant_tl (0 );TCGv slot_mask =tcg_temp_new ();
@@ -62,7 +63,8 @@ static inline void gen_log_reg_write(int rnum, TCGv val) } } -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, +uint32_t slot) {TCGv val32 =tcg_temp_new ();TCGv zero =tcg_constant_tl (0 );
@@ -390,7 +392,7 @@ static inline void gen_store_conditional8(DisasContext *ctx,tcg_gen_movi_tl (hex_llsc_addr, ~0 ); } -static inline void gen_store32 (TCGv vaddr,TCGv src,int width,int slot) +static inline void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot) {tcg_gen_mov_tl (hex_store_addr[slot], vaddr);tcg_gen_movi_tl (hex_store_width[slot], width);
@@ -398,49 +400,49 @@ static inline void gen_store32(TCGv vaddr, TCGv src, int width, int slot) }static inline void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {gen_store32 (vaddr, src,1 , slot); ctx->store_width[slot] =1 ; }static inline void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store1 (cpu_env, vaddr, tmp, ctx, slot); }static inline void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {gen_store32 (vaddr, src,2 , slot); ctx->store_width[slot] =2 ; }static inline void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store2 (cpu_env, vaddr, tmp, ctx, slot); }static inline void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {gen_store32 (vaddr, src,4 , slot); ctx->store_width[slot] =4 ; }static inline void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store4 (cpu_env, vaddr, tmp, ctx, slot); }static inline void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {tcg_gen_mov_tl (hex_store_addr[slot], vaddr);tcg_gen_movi_tl (hex_store_width[slot],8 );
@@ -449,7 +451,7 @@ static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src, }static inline void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src, -DisasContext *ctx,int slot) +DisasContext *ctx,uint32_t slot) {TCGv_i64 tmp =tcg_constant_i64 (src);gen_store8 (cpu_env, vaddr, tmp, ctx, slot);
target/hexagon/macros.h +1 -1
@@ -185,7 +185,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,uint32_t slot_num) {TCGv slot_mask =tcg_temp_new ();TCGv tmp =tcg_temp_new ();
Signature · 1 line
2.34.1
PATCH v8 4/12 target/hexagon: make helper functions non-static
In reply to Anton Johansson 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.
This commit also makes some op_helper.c non-static in order to avoid having them marked as unused when using the idef-parser generated code.
--- target/hexagon/genptr.c | 59 +++++++++++++++++++++----------------- target/hexagon/genptr.h | 30 +++++++++++++++++++ target/hexagon/op_helper.c | 29 +++++++++---------- target/hexagon/op_helper.h | 37 ++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 42 deletions(-) create mode 100644 target/hexagon/op_helper.h
target/hexagon/genptr.c +33 -26
@@ -29,6 +29,13 @@#undef QEMU_GENERATE#include "gen_tcg.h" #include "gen_tcg_hvx.h" +#include "genptr.h" + +TCGv gen_read_preg (TCGv pred,uint8_t num) +{ +tcg_gen_mov_tl (pred, hex_pred[num]); +return pred; +}static inline void gen_log_predicated_reg_write (int rnum,TCGv val,uint32_t slot)
@@ -54,7 +61,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 ) {
@@ -116,7 +123,7 @@ static void gen_log_reg_write_pair(int rnum, TCGv_i64 val) } } -static inline void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val) +void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val) {TCGv base_val =tcg_temp_new ();
@@ -270,7 +277,7 @@ static inline void gen_write_ctrl_reg_pair(DisasContext *ctx, int reg_num, } } -static TCGv gen_get_byte (TCGv result,int N ,TCGv src,bool sign) +TCGv gen_get_byte (TCGv result,int N ,TCGv src,bool sign) {if (sign) {tcg_gen_sextract_tl (result, src,N *8 ,8 );
@@ -280,7 +287,7 @@ static TCGv gen_get_byte(TCGv result, int N, TCGv src, bool sign)return result; } -static TCGv gen_get_byte_i64 (TCGv result,int N ,TCGv_i64 src,bool sign) +TCGv gen_get_byte_i64 (TCGv result,int N ,TCGv_i64 src,bool sign) {TCGv_i64 res64 =tcg_temp_new_i64 ();if (sign) {
@@ -294,7 +301,7 @@ static TCGv gen_get_byte_i64(TCGv result, int N, TCGv_i64 src, bool sign)return result; } -static inline TCGv gen_get_half (TCGv result,int N ,TCGv src,bool sign) +TCGv gen_get_half (TCGv result,int N ,TCGv src,bool sign) {if (sign) {tcg_gen_sextract_tl (result, src,N *16 ,16 );
@@ -304,12 +311,12 @@ static inline TCGv gen_get_half(TCGv result, int N, TCGv src, bool sign)return result; } -static inline void gen_set_half (int N ,TCGv result,TCGv src) +void gen_set_half (int N ,TCGv result,TCGv src) {tcg_gen_deposit_tl (result, result, src,N *16 ,16 ); } -static inline void gen_set_half_i64 (int N ,TCGv_i64 result,TCGv src) +void gen_set_half_i64 (int N ,TCGv_i64 result,TCGv src) {TCGv_i64 src64 =tcg_temp_new_i64 ();tcg_gen_extu_i32_i64 (src64, src);
@@ -317,7 +324,7 @@ static inline void gen_set_half_i64(int N, TCGv_i64 result, TCGv src)tcg_temp_free_i64 (src64); } -static void gen_set_byte_i64 (int N ,TCGv_i64 result,TCGv src) +void gen_set_byte_i64 (int N ,TCGv_i64 result,TCGv src) {TCGv_i64 src64 =tcg_temp_new_i64 ();tcg_gen_extu_i32_i64 (src64, src);
@@ -392,57 +399,57 @@ static inline void gen_store_conditional8(DisasContext *ctx,tcg_gen_movi_tl (hex_llsc_addr, ~0 ); } -static inline void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot) +void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t 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); } -static inline void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src, -DisasContext *ctx,uint32_t slot) +void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +uint32_t slot) {gen_store32 (vaddr, src,1 , slot); ctx->store_width[slot] =1 ; } -static inline void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src, -DisasContext *ctx,uint32_t slot) +void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src,DisasContext *ctx, +uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store1 (cpu_env, vaddr, tmp, ctx, slot); } -static inline void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src, -DisasContext *ctx,uint32_t slot) +void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +uint32_t slot) {gen_store32 (vaddr, src,2 , slot); ctx->store_width[slot] =2 ; } -static inline void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src, -DisasContext *ctx,uint32_t slot) +void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,DisasContext *ctx, +uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store2 (cpu_env, vaddr, tmp, ctx, slot); } -static inline void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src, -DisasContext *ctx,uint32_t slot) +void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +uint32_t slot) {gen_store32 (vaddr, src,4 , slot); ctx->store_width[slot] =4 ; } -static inline void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src, -DisasContext *ctx,uint32_t slot) +void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,DisasContext *ctx, +uint32_t slot) {TCGv tmp =tcg_constant_tl (src);gen_store4 (cpu_env, vaddr, tmp, ctx, slot); } -static inline void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src, -DisasContext *ctx,uint32_t slot) +void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,DisasContext *ctx, +uint32_t slot) {tcg_gen_mov_tl (hex_store_addr[slot], vaddr);tcg_gen_movi_tl (hex_store_width[slot],8 );
@@ -450,14 +457,14 @@ static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src, ctx->store_width[slot] =8 ; } -static inline void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src, -DisasContext *ctx,uint32_t slot) +void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,DisasContext *ctx, +uint32_t slot) {TCGv_i64 tmp =tcg_constant_i64 (src);gen_store8 (cpu_env, vaddr, tmp, ctx, slot); } -static TCGv gen_8bitsof (TCGv result,TCGv value) +TCGv gen_8bitsof (TCGv result,TCGv value) {TCGv zero =tcg_constant_tl (0 );TCGv ones =tcg_constant_tl (0xff );
target/hexagon/genptr.h +30 -0
@@ -19,7 +19,37 @@#define HEXAGON_GENPTR_H #include "insn.h" +#include "tcg/tcg.h" +#include "translate.h" extern const SemanticInsn opcode_genptr[]; +void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot); +void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +uint32_t slot); +void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +uint32_t slot); +void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx, +uint32_t slot); +void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src,DisasContext *ctx, +uint32_t slot); +void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src,DisasContext *ctx, +uint32_t slot); +void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src,DisasContext *ctx, +uint32_t slot); +void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src,DisasContext *ctx, +uint32_t slot); +void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src,DisasContext *ctx, +uint32_t slot); +TCGv gen_read_preg (TCGv pred,uint8_t num); +void gen_log_reg_write (int rnum,TCGv val); +void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val); +TCGv gen_8bitsof (TCGv result,TCGv value); +void gen_set_byte_i64 (int N ,TCGv_i64 result,TCGv src); +TCGv gen_get_byte (TCGv result,int N ,TCGv src,bool sign); +TCGv gen_get_byte_i64 (TCGv result,int N ,TCGv_i64 src,bool sign); +TCGv gen_get_half (TCGv result,int N ,TCGv src,bool sign); +void gen_set_half (int N ,TCGv result,TCGv src); +void gen_set_half_i64 (int N ,TCGv_i64 result,TCGv src); +#endif
target/hexagon/op_helper.c +13 -16
@@ -29,6 +29,7 @@#include "fma_emu.h" #include "mmvec/mmvec.h" #include "mmvec/macros.h" +#include "op_helper.h" #define SF_BIAS 127#define SF_MANTBITS 23
@@ -49,8 +50,8 @@ void QEMU_NORETURN HELPER(raise_exception)(CPUHexagonState *env, uint32_t excp)do_raise_exception_err (env, excp,0 ); } -static void log_reg_write (CPUHexagonState *env,int rnum, -target_ulong val,uint32_t slot) +void log_reg_write (CPUHexagonState *env,int rnum,target_ulong val, +uint32_t slot) {HEX_DEBUG_LOG ("log_reg_write[%d] = " TARGET_FMT_ld" (0x" TARGET_FMT_lx")" , rnum, val, val);
@@ -81,8 +82,8 @@ static void log_pred_write(CPUHexagonState *env, int pnum, target_ulong val) } } -static void log_store32 (CPUHexagonState *env,target_ulong addr, -target_ulong val,int width,int slot) +void log_store32 (CPUHexagonState *env,target_ulong addr,target_ulong val, +int width,int slot) { HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", %" PRId32 " [0x08%" PRIx32 "])\n",
@@ -92,8 +93,8 @@ static void log_store32(CPUHexagonState *env, target_ulong addr, env->mem_log_stores[slot].data32 = val; } -static void log_store64 (CPUHexagonState *env,target_ulong addr, -int64_t val,int width,int slot) +void log_store64 (CPUHexagonState *env,target_ulong addr,int64_t val, +int width,int slot) { HEX_DEBUG_LOG("log_store%d(0x" TARGET_FMT_lx ", %" PRId64 " [0x016%" PRIx64 "])\n",
@@ -103,7 +104,7 @@ static void log_store64(CPUHexagonState *env, target_ulong addr, env->mem_log_stores[slot].data64 = val; } -static void write_new_pc (CPUHexagonState *env,target_ulong addr) +void write_new_pc (CPUHexagonState *env,target_ulong addr) {HEX_DEBUG_LOG ("write_new_pc(0x" TARGET_FMT_lx")\n" , addr);
@@ -521,32 +522,28 @@ static void check_noshuf(CPUHexagonState *env, uint32_t slot) } } -static uint8_t mem_load1 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint8_t mem_load1 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot);return cpu_ldub_data_ra (env, vaddr, ra); } -static uint16_t mem_load2 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint16_t mem_load2 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot);return cpu_lduw_data_ra (env, vaddr, ra); } -static uint32_t mem_load4 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint32_t mem_load4 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot);return cpu_ldl_data_ra (env, vaddr, ra); } -static uint64_t mem_load8 (CPUHexagonState *env,uint32_t slot, -target_ulong vaddr) +uint64_t mem_load8 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr) {uintptr_t ra =GETPC ();check_noshuf (env, slot);
@@ -1459,7 +1456,7 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV) } } -static void cancel_slot (CPUHexagonState *env,uint32_t slot) +void cancel_slot (CPUHexagonState *env,uint32_t slot) {HEX_DEBUG_LOG ("Slot %d cancelled\n" , slot); env->slot_cancelled |= (1 << slot);
target/hexagon/op_helper.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. 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/>. +*/ + +#ifndef HEXAGON_OP_HELPER_H +#define HEXAGON_OP_HELPER_H + +/* Misc functions */ +void cancel_slot (CPUHexagonState *env,uint32_t slot); +void write_new_pc (CPUHexagonState *env,target_ulong addr); + +uint8_t mem_load1 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); +uint16_t mem_load2 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); +uint32_t mem_load4 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); +uint64_t mem_load8 (CPUHexagonState *env,uint32_t slot,target_ulong vaddr); + +void log_reg_write (CPUHexagonState *env,int rnum,target_ulong val, +uint32_t slot); +void log_store64 (CPUHexagonState *env,target_ulong addr,int64_t val, +int width,int slot); +void log_store32 (CPUHexagonState *env,target_ulong addr,target_ulong val, +int width,int slot); + +#endif
Signature · 1 line
2.34.1
PATCH v8 5/12 target/hexagon: introduce new helper functions
In reply to Anton Johansson viaFrom: Niccolò Izzo <[email protected]>
These helpers will be employed by the idef-parser generated code, to correctly implement instruction semantics. "Helper" functions, in the context of this patch, refers to functions which provide a manual TCG implementation of certain features.
--- target/hexagon/genptr.c | 167 ++++++++++++++++++++++++++++++++++++++-- target/hexagon/genptr.h | 16 +++- target/hexagon/macros.h | 9 +++ 3 files changed, 184 insertions(+), 8 deletions(-)
target/hexagon/genptr.c +160 -7
@@ -31,6 +31,12 @@#include "gen_tcg_hvx.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]);
@@ -399,18 +405,19 @@ static inline void gen_store_conditional8(DisasContext *ctx,tcg_gen_movi_tl (hex_llsc_addr, ~0 ); } -void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot) +void gen_store32 (DisasContext *ctx,TCGv vaddr,TCGv src,tcg_target_long width, +uint32_t 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); + ctx->store_width[slot] = width; }void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx,uint32_t slot) { -gen_store32 (vaddr, src,1 , slot); - ctx->store_width[slot] =1 ; +gen_store32 (ctx, vaddr, src,1 , slot); } void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src, DisasContext *ctx,
@@ -423,8 +430,7 @@ void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src, DisasContext *ctx,void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx,uint32_t slot) { -gen_store32 (vaddr, src,2 , slot); - ctx->store_width[slot] =2 ; +gen_store32 (ctx, vaddr, src,2 , slot); } void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src, DisasContext *ctx,
@@ -437,8 +443,7 @@ void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src, DisasContext *ctx,void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx,uint32_t slot) { -gen_store32 (vaddr, src,4 , slot); - ctx->store_width[slot] =4 ; +gen_store32 (ctx, vaddr, src,4 , slot); } void gen_store4i(TCGv_env cpu_env, TCGv vaddr, int32_t src, DisasContext *ctx,
@@ -643,5 +648,153 @@ static void vec_to_qvec(size_t size, intptr_t dstoff, intptr_t srcoff)tcg_temp_free_i64 (mask); } +void gen_set_usr_field (int field,TCGv val) +{ +/* +* Apparently tcg_gen_deposit_i32/64 doesn't OR the input value +* with the previously present one, as deposit32/64 in bitops.h +* does. We therefore copy the old value to `old_usr` to later +* OR with it to replicate this behavior. +*/ +TCGv_i32 old_usr =tcg_temp_new_i32 (); +tcg_gen_mov_i32 (old_usr, hex_new_value[HEX_REG_USR ]); +tcg_gen_deposit_tl (hex_new_value[HEX_REG_USR ], hex_new_value[HEX_REG_USR ], + val, + reg_field_info[field].offset, + reg_field_info[field].width); +tcg_gen_or_i32 (hex_new_value[HEX_REG_USR ], + old_usr, + hex_new_value[HEX_REG_USR ]); +tcg_temp_free (old_usr); +} + +void gen_set_usr_fieldi (int field,int x) +{ +TCGv val =tcg_constant_tl (x); +gen_set_usr_field (field, val); +} + +void gen_write_new_pc (TCGv addr) +{ +/* If there are multiple branches in a packet, ignore the second one */ +TCGv zero =tcg_constant_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 ); +} + +void gen_sat_i32 (TCGv dest,TCGv source,int width) +{ +TCGv max_val =tcg_constant_tl ((1 << (width -1 )) -1 ); +TCGv min_val =tcg_constant_tl (-(1 << (width -1 ))); +tcg_gen_smin_tl (dest, source, max_val); +tcg_gen_smax_tl (dest, dest, min_val); +} + +void gen_sat_i32_ovfl (TCGv ovfl,TCGv dest,TCGv source,int width) +{ +gen_sat_i32 (dest, source, width); +tcg_gen_setcond_tl (TCG_COND_NE , ovfl, source, dest); +} + +void gen_satu_i32 (TCGv dest,TCGv source,int width) +{ +TCGv max_val =tcg_constant_tl ((1 << width) -1 ); +TCGv zero =tcg_constant_tl (0 ); +tcg_gen_movcond_tl (TCG_COND_GTU , dest, source, max_val, max_val, source); +tcg_gen_movcond_tl (TCG_COND_LT , dest, source, zero, zero, dest); +} + +void gen_satu_i32_ovfl (TCGv ovfl,TCGv dest,TCGv source,int width) +{ +gen_satu_i32 (dest, source, width); +tcg_gen_setcond_tl (TCG_COND_NE , ovfl, source, dest); +} + +void gen_sat_i64 (TCGv_i64 dest,TCGv_i64 source,int width) +{ +TCGv_i64 max_val =tcg_constant_i64 ((1LL << (width -1 )) -1LL ); +TCGv_i64 min_val =tcg_constant_i64 (-(1LL << (width -1 ))); +tcg_gen_smin_i64 (dest, source, max_val); +tcg_gen_smax_i64 (dest, dest, min_val); +} + +void gen_sat_i64_ovfl (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width) +{ +TCGv_i64 ovfl_64; +gen_sat_i64 (dest, source, width); + ovfl_64 =tcg_temp_new_i64 (); +tcg_gen_setcond_i64 (TCG_COND_NE , ovfl_64, dest, source); +tcg_gen_trunc_i64_tl (ovfl, ovfl_64); +tcg_temp_free_i64 (ovfl_64); +} + +void gen_satu_i64 (TCGv_i64 dest,TCGv_i64 source,int width) +{ +TCGv_i64 max_val =tcg_constant_i64 ((1LL << width) -1LL ); +TCGv_i64 zero =tcg_constant_i64 (0 ); +tcg_gen_movcond_i64 (TCG_COND_GTU , dest, source, max_val, max_val, source); +tcg_gen_movcond_i64 (TCG_COND_LT , dest, source, zero, zero, dest); +} + +void gen_satu_i64_ovfl (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width) +{ +TCGv_i64 ovfl_64; +gen_satu_i64 (dest, source, width); + ovfl_64 =tcg_temp_new_i64 (); +tcg_gen_setcond_i64 (TCG_COND_NE , ovfl_64, dest, source); +tcg_gen_trunc_i64_tl (ovfl, ovfl_64); +tcg_temp_free_i64 (ovfl_64); +} + +/* Implements the fADDSAT64 macro in TCG */ +void gen_add_sat_i64 (TCGv_i64 ret,TCGv_i64 a,TCGv_i64 b) +{ +TCGv_i64 sum =tcg_temp_local_new_i64 (); +TCGv_i64 xor =tcg_temp_new_i64 (); +TCGv_i64 cond1 =tcg_temp_new_i64 (); +TCGv_i64 cond2 =tcg_temp_local_new_i64 (); +TCGv_i64 cond3 =tcg_temp_new_i64 (); +TCGv_i64 mask =tcg_constant_i64 (0x8000000000000000ULL ); +TCGv_i64 max_pos =tcg_constant_i64 (0x7FFFFFFFFFFFFFFFLL ); +TCGv_i64 max_neg =tcg_constant_i64 (0x8000000000000000LL ); +TCGv_i64 zero =tcg_constant_i64 (0 ); +TCGLabel *no_ovfl_label =gen_new_label (); +TCGLabel *ovfl_label =gen_new_label (); +TCGLabel *ret_label =gen_new_label (); + +tcg_gen_add_i64 (sum, a, b); +tcg_gen_xor_i64 (xor, a, b); + +/* if (xor & mask) */ +tcg_gen_and_i64 (cond1, xor, mask); +tcg_temp_free_i64 (xor); +tcg_gen_brcondi_i64 (TCG_COND_NE , cond1,0 , no_ovfl_label); +tcg_temp_free_i64 (cond1); + +/* else if ((a ^ sum) & mask) */ +tcg_gen_xor_i64 (cond2, a, sum); +tcg_gen_and_i64 (cond2, cond2, mask); +tcg_gen_brcondi_i64 (TCG_COND_NE , cond2,0 , ovfl_label); +tcg_temp_free_i64 (cond2); +/* fallthrough to no_ovfl_label branch */ + +/* if branch */ +gen_set_label (no_ovfl_label); +tcg_gen_mov_i64 (ret, sum); +tcg_gen_br (ret_label); + +/* else if branch */ +gen_set_label (ovfl_label); +tcg_gen_and_i64 (cond3, sum, mask); +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (sum); +tcg_gen_movcond_i64 (TCG_COND_NE , ret, cond3, zero, max_pos, max_neg); +tcg_temp_free_i64 (cond3); +SET_USR_FIELD (USR_OVF ,1 ); + +gen_set_label (ret_label); +} +#include "tcg_funcs_generated.c.inc" #include "tcg_func_table_generated.c.inc"
target/hexagon/genptr.h +15 -1
@@ -24,7 +24,8 @@extern const SemanticInsn opcode_genptr[]; -void gen_store32 (TCGv vaddr,TCGv src,int width,uint32_t slot); +void gen_store32 (DisasContext *ctx,TCGv vaddr,TCGv src,tcg_target_long width, +uint32_t slot);void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,DisasContext *ctx,uint32_t slot); void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src, DisasContext *ctx,
@@ -44,6 +45,18 @@ void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src, DisasContext *ctx,TCGv gen_read_preg (TCGv pred,uint8_t num);void gen_log_reg_write (int rnum,TCGv val);void gen_log_pred_write (DisasContext *ctx,int pnum,TCGv val); +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_ovfl (TCGv ovfl,TCGv dest,TCGv source,int width); +void gen_satu_i32 (TCGv dest,TCGv source,int width); +void gen_satu_i32_ovfl (TCGv ovfl,TCGv dest,TCGv source,int width); +void gen_sat_i64 (TCGv_i64 dest,TCGv_i64 source,int width); +void gen_sat_i64_ovfl (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_ovfl (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width); +void gen_add_sat_i64 (TCGv_i64 ret,TCGv_i64 a,TCGv_i64 b);TCGv gen_8bitsof (TCGv result,TCGv value);void gen_set_byte_i64 (int N ,TCGv_i64 result,TCGv src);TCGv gen_get_byte (TCGv result,int N ,TCGv src,bool sign);
@@ -51,5 +64,6 @@ TCGv gen_get_byte_i64(TCGv result, int N, TCGv_i64 src, bool sign);TCGv gen_get_half (TCGv result,int N ,TCGv src,bool sign);void gen_set_half (int N ,TCGv result,TCGv src);void gen_set_half_i64 (int N ,TCGv_i64 result,TCGv src); +TCGv gen_read_reg (TCGv result,int num);#endif
target/hexagon/macros.h +9 -0
@@ -180,7 +180,16 @@#define MEM_STORE8 (VA ,DATA ,SLOT ) log_store64(env, VA, DATA, 8, SLOT)#endif +#ifdef QEMU_GENERATE +static inline void gen_cancel (uint32_t 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.34.1
RE: [PATCH v8 05/12] target/hexagon: introduce new helper functions
Quoted 21 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Wednesday, February 9, 2022 11:03 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v8 05/12] target/hexagon: introduce new helper functionsFrom: Niccolò Izzo <[email protected]>
These helpers will be employed by the idef-parser generated code, to correctly implement instruction semantics. "Helper" functions, in the context of this patch, refers to functions which provide a manual TCG implementation of certain features.
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Niccolò Izzo <[email protected]>Signed-off-by Anton Johansson <[email protected]>
Quoted 6 lines
--- target/hexagon/genptr.c | 167 ++++++++++++++++++++++++++++++++++++++-- target/hexagon/genptr.h | 16 +++- target/hexagon/macros.h | 9 +++ 3 files changed, 184 insertions(+), 8 deletions(-)
PATCH v8 6/12 target/hexagon: expose next PC in DisasContext
In reply to Anton Johansson 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
@@ -741,11 +741,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 (env, ctx, &pkt); - ctx->base.pc_next += pkt.encod_pkt_size_in_bytes; + ctx->base.pc_next = ctx->npc; }else {gen_exception_end_tb (ctx,HEX_EXCP_INVALID_PACKET ); }
target/hexagon/translate.h +1 -0
@@ -52,6 +52,7 @@ typedef struct DisasContext {bool qreg_is_predicated[NUM_QREGS ];int qreg_log_idx;bool pre_commit; +uint32_t npc; } DisasContext;static inline void ctx_log_reg_write (DisasContext *ctx,int rnum)
Signature · 1 line
2.34.1
PATCH v8 7/12 target/hexagon: prepare input for the idef-parser
In reply to Anton Johansson 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 | 125 +++++++++++++++++++++ target/hexagon/idef-parser/macros.inc | 140 ++++++++++++++++++++++++ target/hexagon/idef-parser/prepare | 24 ++++ target/hexagon/meson.build | 17 +++ 4 files changed, 306 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 +125 -0
@@ -0,0 +1,125 @@ +#!/usr/bin/env python3 + +## +## Copyright(c) 2019-2021 rev.ng Labs Srl. 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.calculate_attribs() + tagregs = hex_common.get_tagregs() + tagimms = hex_common.get_tagimms() + + with open(sys.argv[3], '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 + if ( tag in {'M7_wcmpyrw', 'M7_wcmpyrwc', + 'M7_wcmpyiw', 'M7_wcmpyiwc', + 'M7_wcmpyrw_rnd', 'M7_wcmpyrwc_rnd', + 'M7_wcmpyiw_rnd', 'M7_wcmpyiwc_rnd'} ) : + continue + ## Skip interleave/deinterleave instructions + if ( tag in {'S2_interleave', 'S2_deinterleave'} ) : + continue + ## Skip instructions using bit reverse + if ( tag in {'S2_brev', 'S2_brevp', 'S2_ct0', 'S2_ct1', + 'S2_ct0p', 'S2_ct1p', 'A4_tlbmatch'} ) : + continue + ## Skip other unsupported instructions + if ( tag == 'S2_cabacdecbin' or tag == 'A5_ACS' ) : + 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 = [] + 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(" "); + if hex_common.need_ea(tag): + f.write("size4u_t EA; "); + f.write("%s\n" % hex_common.semdict[tag]) + f.write("}\n\n") + +if __name__ == "__main__": + main()
target/hexagon/idef-parser/macros.inc new file +140 -0
140 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 Labs Srl. 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/>. +# + +set -e +set -o pipefail + +# Run the preprocessor and drop comments +cpp "$@"
target/hexagon/meson.build +17 -0
@@ -21,6 +21,7 @@ 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' gen_tcg_hvx_h = meson.current_source_dir() / 'gen_tcg_hvx.h' +idef_parser_dir = meson.current_source_dir() / 'idef-parser' # # Step 1
@@ -179,4 +180,20 @@ hexagon_ss.add(files( 'mmvec/system_ext_mmvec.c', )) +idef_parser_input_generated = custom_target( + 'idef_parser_input.h.inc', + output: 'idef_parser_input.h.inc', + depends: [semantics_generated], + depend_files: [hex_common_py], + command: [python, files('gen_idef_parser_funcs.py'), semantics_generated, attribs_def, '@OUTPUT@'], +) + +preprocessed_idef_parser_input_generated = custom_target( + 'idef_parser_input.preprocessed.h.inc', + output: 'idef_parser_input.preprocessed.h.inc', + input: idef_parser_input_generated, + depend_files: [idef_parser_dir / 'macros.inc'], + command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'], +) + target_arch += {'hexagon': hexagon_ss}
Signature · 1 line
2.34.1
RE: [PATCH v8 07/12] target/hexagon: prepare input for the idef-parser
Quoted 18 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Wednesday, February 9, 2022 11:03 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v8 07/12] target/hexagon: prepare input for the idef-parserFrom: Alessandro Di Federico <[email protected]>
Introduce infrastructure necessary to produce a file suitable for being parsed by the idef-parser.
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Anton Johansson <[email protected]>
Quoted 11 lines
--- target/hexagon/gen_idef_parser_funcs.py | 125 +++++++++++++++++++++ target/hexagon/idef-parser/macros.inc | 140 ++++++++++++++++++++++++ target/hexagon/idef-parser/prepare | 24 ++++ target/hexagon/meson.build | 17 +++ 4 files changed, 306 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
PATCH v8 8/12 target/hexagon: import flex/bison to docker files
In reply to Anton Johansson viaNote: In this version of the patchset tests/lcitool/libvirt-ci points to a fork of libvirt-ci that includes flex/bison. This fork has not been merged upstream yet, and can be found at
https://gitlab.com/AntonJohansson/libvirt-ci/-/tree/mapping-flex-bison
This patch will have to be modified to point to the upstreamed version before pulling.
--- .gitlab-ci.d/cirrus/freebsd-12.vars | 2 +- .gitlab-ci.d/cirrus/freebsd-13.vars | 2 +- .gitlab-ci.d/windows.yml | 2 ++ .gitmodules | 3 ++- tests/docker/dockerfiles/alpine.docker | 5 ++++- tests/docker/dockerfiles/centos8.docker | 7 ++++--- tests/docker/dockerfiles/debian-amd64.docker | 2 ++ tests/docker/dockerfiles/debian-native.docker | 3 +++ tests/docker/dockerfiles/debian-riscv64-cross.docker | 3 +++ tests/docker/dockerfiles/debian-tricore-cross.docker | 1 + tests/docker/dockerfiles/debian10.docker | 3 +++ tests/docker/dockerfiles/fedora-i386-cross.docker | 3 +++ tests/docker/dockerfiles/fedora-win32-cross.docker | 3 +++ tests/docker/dockerfiles/fedora-win64-cross.docker | 3 +++ tests/docker/dockerfiles/fedora.docker | 5 +++-- tests/docker/dockerfiles/opensuse-leap.docker | 7 ++++--- tests/docker/dockerfiles/ubuntu1804.docker | 7 ++++--- tests/docker/dockerfiles/ubuntu2004.docker | 7 ++++--- tests/lcitool/libvirt-ci | 2 +- tests/lcitool/projects/qemu.yml | 2 ++ tests/lcitool/refresh | 2 +- 21 files changed, 54 insertions(+), 20 deletions(-)
.gitlab-ci.d/cirrus/freebsd-12.vars +1 -1
@@ -11,6 +11,6 @@ MAKE='/usr/local/bin/gmake' NINJA='/usr/local/bin/ninja' PACKAGING_COMMAND='pkg' PIP3='/usr/local/bin/pip-3.8' -PKGS='alsa-lib bash bzip2 ca_root_nss capstone4 ccache cdrkit-genisoimage ctags curl cyrus-sasl dbus diffutils dtc gettext git glib gmake gnutls gsed gtk3 libepoxy libffi libgcrypt libjpeg-turbo libnfs libspice-server libssh libtasn1 libxml2 llvm lttng-ust lzo2 meson ncurses nettle ninja opencv p5-Test-Harness perl5 pixman pkgconf png py38-numpy py38-pillow py38-pip py38-sphinx py38-sphinx_rtd_theme py38-virtualenv py38-yaml python3 rpm2cpio sdl2 sdl2_image snappy spice-protocol tesseract texinfo usbredir virglrenderer vte3 zstd' +PKGS='alsa-lib bash bzip2 ca_root_nss capstone4 ccache cdrkit-genisoimage ctags curl cyrus-sasl dbus diffutils dtc gettext git glib gmake gnutls gsed gtk3 libepoxy libffi libgcrypt libjpeg-turbo libnfs libspice-server libssh libtasn1 libxml2 llvm lzo2 meson ncurses nettle ninja opencv p5-Test-Harness perl5 pixman pkgconf png py38-numpy py38-pillow py38-pip py38-sphinx py38-sphinx_rtd_theme py38-virtualenv py38-yaml python3 rpm2cpio sdl2 sdl2_image snappy spice-protocol tesseract texinfo usbredir virglrenderer vte3 zstd' PYPI_PKGS='' PYTHON='/usr/local/bin/python3'
.gitlab-ci.d/cirrus/freebsd-13.vars +1 -1
@@ -11,6 +11,6 @@ MAKE='/usr/local/bin/gmake' NINJA='/usr/local/bin/ninja' PACKAGING_COMMAND='pkg' PIP3='/usr/local/bin/pip-3.8' -PKGS='alsa-lib bash bzip2 ca_root_nss capstone4 ccache cdrkit-genisoimage ctags curl cyrus-sasl dbus diffutils dtc gettext git glib gmake gnutls gsed gtk3 libepoxy libffi libgcrypt libjpeg-turbo libnfs libspice-server libssh libtasn1 libxml2 llvm lttng-ust lzo2 meson ncurses nettle ninja opencv p5-Test-Harness perl5 pixman pkgconf png py38-numpy py38-pillow py38-pip py38-sphinx py38-sphinx_rtd_theme py38-virtualenv py38-yaml python3 rpm2cpio sdl2 sdl2_image snappy spice-protocol tesseract texinfo usbredir virglrenderer vte3 zstd' +PKGS='alsa-lib bash bzip2 ca_root_nss capstone4 ccache cdrkit-genisoimage ctags curl cyrus-sasl dbus diffutils dtc gettext git glib gmake gnutls gsed gtk3 libepoxy libffi libgcrypt libjpeg-turbo libnfs libspice-server libssh libtasn1 libxml2 llvm lzo2 meson ncurses nettle ninja opencv p5-Test-Harness perl5 pixman pkgconf png py38-numpy py38-pillow py38-pip py38-sphinx py38-sphinx_rtd_theme py38-virtualenv py38-yaml python3 rpm2cpio sdl2 sdl2_image snappy spice-protocol tesseract texinfo usbredir virglrenderer vte3 zstd' PYPI_PKGS='' PYTHON='/usr/local/bin/python3'
.gitlab-ci.d/windows.yml +2 -0
@@ -33,6 +33,7 @@ msys2-64bit: script: - .\msys64\usr\bin\bash -lc "pacman -Sy --noconfirm --needed diffutils git grep make sed + flex bison mingw-w64-x86_64-capstone mingw-w64-x86_64-curl mingw-w64-x86_64-cyrus-sasl
@@ -68,6 +69,7 @@ msys2-32bit: script: - .\msys64\usr\bin\bash -lc "pacman -Sy --noconfirm --needed diffutils git grep make sed + flex bison mingw-w64-i686-capstone mingw-w64-i686-curl mingw-w64-i686-cyrus-sasl
.gitmodules +2 -1
@@ -66,4 +66,5 @@ url = https://gitlab.com/qemu-project/vbootrom.git [submodule "tests/lcitool/libvirt-ci"] path = tests/lcitool/libvirt-ci - url = http://gitlab.com/libvirt/libvirt-ci + url = http://gitlab.com/AntonJohansson/libvirt-ci + branch = mapping-flex-bison
tests/docker/dockerfiles/alpine.docker +4 -1
@@ -1,6 +1,6 @@ # THIS FILE WAS AUTO-GENERATED # -# $ lcitool dockerfile alpine-edge qemu +# $ lcitool dockerfile --layers all alpine-edge qemu # # https://gitlab.com/libvirt/libvirt-ci
@@ -13,6 +13,7 @@ RUN apk update && \ attr-dev \ bash \ bc \ + bison \ bzip2 \ bzip2-dev \ ca-certificates \
@@ -29,6 +30,7 @@ RUN apk update && \ dtc-dev \ eudev-dev \ findutils \ + flex \ fuse3-dev \ g++ \ gcc \
@@ -109,6 +111,7 @@ RUN apk update && \ zlib-dev \ zlib-static \ zstd-dev && \ + apk list | sort > /packages.txt && \ mkdir -p /usr/libexec/ccache-wrappers && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/c++ && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/cc && \
tests/docker/dockerfiles/centos8.docker +4 -3
@@ -1,10 +1,10 @@ # THIS FILE WAS AUTO-GENERATED # -# $ lcitool dockerfile centos-8 qemu +# $ lcitool dockerfile --layers all almalinux-8 qemu # # https://gitlab.com/libvirt/libvirt-ci -FROM docker.io/library/centos:8 +FROM docker.io/library/almalinux:8 RUN dnf update -y && \ dnf install 'dnf-command(config-manager)' -y && \
@@ -16,6 +16,7 @@ RUN dnf update -y && \ alsa-lib-devel \ bash \ bc \ + bison \ brlapi-devel \ bzip2 \ bzip2-devel \
@@ -30,6 +31,7 @@ RUN dnf update -y && \ device-mapper-multipath-devel \ diffutils \ findutils \ + flex \ fuse3-devel \ gcc \ gcc-c++ \
@@ -69,7 +71,6 @@ RUN dnf update -y && \ libssh-devel \ libtasn1-devel \ libubsan \ - libudev-devel \ liburing-devel \ libusbx-devel \ libxml2-devel \
tests/docker/dockerfiles/debian-amd64.docker +2 -0
@@ -14,9 +14,11 @@ RUN apt update && \ RUN apt update && \ DEBIAN_FRONTEND=noninteractive eatmydata \ apt install -y --no-install-recommends \ + bison \ cscope \ genisoimage \ exuberant-ctags \ + flex \ global \ libbz2-dev \ liblzo2-dev \
tests/docker/dockerfiles/debian-native.docker +3 -0
@@ -26,13 +26,16 @@ RUN apt update && \ RUN apt update && \ DEBIAN_FRONTEND=noninteractive eatmydata \ apt install -y --no-install-recommends \ + bison \ cscope \ genisoimage \ exuberant-ctags \ + flex \ global \ libbz2-dev \ liblzo2-dev \ libgcrypt20-dev \ + libglib2.0-dev \ libfdt-dev \ librdmacm-dev \ libsasl2-dev \
tests/docker/dockerfiles/debian-riscv64-cross.docker +3 -0
@@ -17,12 +17,15 @@ RUN apt update && \ # Install common build utilities RUN DEBIAN_FRONTEND=noninteractive eatmydata apt install -yy \ bc \ + bison \ build-essential \ ca-certificates \ debian-ports-archive-keyring \ dpkg-dev \ + flex \ gettext \ git \ + libglib2.0-dev \ ninja-build \ pkg-config \ python3
tests/docker/dockerfiles/debian-tricore-cross.docker +1 -0
@@ -20,6 +20,7 @@ RUN apt update && \ bzip2 \ ca-certificates \ ccache \ + flex \ g++ \ gcc \ git \
tests/docker/dockerfiles/debian10.docker +3 -0
@@ -18,15 +18,18 @@ RUN apt update && \ DEBIAN_FRONTEND=noninteractive eatmydata \ apt install -y --no-install-recommends \ bc \ + bison \ build-essential \ ca-certificates \ ccache \ clang \ dbus \ + flex \ gdb-multiarch \ gettext \ git \ libffi-dev \ + libglib2.0-dev \ libncurses5-dev \ ninja-build \ pkg-config \
tests/docker/dockerfiles/fedora-i386-cross.docker +3 -0
@@ -1,12 +1,15 @@ FROM registry.fedoraproject.org/fedora:34 ENV PACKAGES \ + bison \ bzip2 \ ccache \ diffutils \ findutils \ + flex \ gcc \ git \ + glib2-devel \ libffi-devel.i686 \ libselinux-devel.i686 \ libtasn1-devel.i686 \
tests/docker/dockerfiles/fedora-win32-cross.docker +3 -0
@@ -3,13 +3,16 @@ FROM registry.fedoraproject.org/fedora:33 # Please keep this list sorted alphabetically ENV PACKAGES \ bc \ + bison \ bzip2 \ ccache \ diffutils \ findutils \ + flex \ gcc \ gettext \ git \ + glib2-devel \ hostname \ make \ meson \
tests/docker/dockerfiles/fedora-win64-cross.docker +3 -0
@@ -3,12 +3,15 @@ FROM registry.fedoraproject.org/fedora:33 # Please keep this list sorted alphabetically ENV PACKAGES \ bc \ + bison \ bzip2 \ ccache \ diffutils \ findutils \ + flex \ gcc \ gettext \ + glib2-devel \ git \ hostname \ make \
tests/docker/dockerfiles/fedora.docker +3 -2
@@ -1,6 +1,6 @@ # THIS FILE WAS AUTO-GENERATED # -# $ lcitool dockerfile fedora-35 qemu +# $ lcitool dockerfile --layers all fedora-35 qemu # # https://gitlab.com/libvirt/libvirt-ci
@@ -23,6 +23,7 @@ exec "$@"' > /usr/bin/nosync && \ alsa-lib-devel \ bash \ bc \ + bison \ brlapi-devel \ bzip2 \ bzip2-devel \
@@ -37,6 +38,7 @@ exec "$@"' > /usr/bin/nosync && \ device-mapper-multipath-devel \ diffutils \ findutils \ + flex \ fuse3-devel \ gcc \ gcc-c++ \
@@ -77,7 +79,6 @@ exec "$@"' > /usr/bin/nosync && \ libssh-devel \ libtasn1-devel \ libubsan \ - libudev-devel \ liburing-devel \ libusbx-devel \ libxml2-devel \
tests/docker/dockerfiles/opensuse-leap.docker +4 -3
@@ -1,6 +1,6 @@ # THIS FILE WAS AUTO-GENERATED # -# $ lcitool dockerfile opensuse-leap-152 qemu +# $ lcitool dockerfile --layers all opensuse-leap-152 qemu # # https://gitlab.com/libvirt/libvirt-ci
@@ -12,6 +12,7 @@ RUN zypper update -y && \ alsa-lib-devel \ bash \ bc \ + bison \ brlapi-devel \ bzip2 \ ca-certificates \
@@ -22,6 +23,7 @@ RUN zypper update -y && \ dbus-1 \ diffutils \ findutils \ + flex \ fuse3-devel \ gcc \ gcc-c++ \
@@ -128,8 +130,7 @@ RUN zypper update -y && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc -RUN pip3 install \ - meson==0.56.0 +RUN pip3 install meson==0.56.0 ENV LANG "en_US.UTF-8" ENV MAKE "/usr/bin/make"
tests/docker/dockerfiles/ubuntu1804.docker +4 -3
@@ -1,6 +1,6 @@ # THIS FILE WAS AUTO-GENERATED # -# $ lcitool dockerfile ubuntu-1804 qemu +# $ lcitool dockerfile --layers all ubuntu-1804 qemu # # https://gitlab.com/libvirt/libvirt-ci
@@ -13,6 +13,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ eatmydata apt-get install --no-install-recommends -y \ bash \ bc \ + bison \ bsdmainutils \ bzip2 \ ca-certificates \
@@ -23,6 +24,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ diffutils \ exuberant-ctags \ findutils \ + flex \ g++ \ gcc \ gcovr \
@@ -134,8 +136,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc -RUN pip3 install \ - meson==0.56.0 +RUN pip3 install meson==0.56.0 ENV LANG "en_US.UTF-8" ENV MAKE "/usr/bin/make"
tests/docker/dockerfiles/ubuntu2004.docker +4 -3
@@ -1,6 +1,6 @@ # THIS FILE WAS AUTO-GENERATED # -# $ lcitool dockerfile ubuntu-2004 qemu +# $ lcitool dockerfile --layers all ubuntu-2004 qemu # # https://gitlab.com/libvirt/libvirt-ci
@@ -13,6 +13,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ eatmydata apt-get install --no-install-recommends -y \ bash \ bc \ + bison \ bsdmainutils \ bzip2 \ ca-certificates \
@@ -23,6 +24,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ diffutils \ exuberant-ctags \ findutils \ + flex \ g++ \ gcc \ gcovr \
@@ -136,8 +138,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/g++ && \ ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/gcc -RUN pip3 install \ - meson==0.56.0 +RUN pip3 install meson==0.56.0 ENV LANG "en_US.UTF-8" ENV MAKE "/usr/bin/make"
tests/lcitool/libvirt-ci +1 -1
@@ -1 +1 @@ -Subproject commit 29cec2153b9a4dbb2e66f1cbc9866a4eff519cfd +Subproject commit 22a88ac73197e6c6b8a319eb92cdbd2ac06eb44a
tests/lcitool/projects/qemu.yml +2 -0
@@ -3,6 +3,7 @@ packages: - alsa - bash - bc + - bison - brlapi - bzip2 - bzip2-libs
@@ -18,6 +19,7 @@ packages: - diffutils - dtrace - findutils + - flex - fuse3 - g++ - gcc
tests/lcitool/refresh +1 -1
@@ -77,7 +77,7 @@ ubuntu2004_tsanhack = [ ] try: - generate_dockerfile("centos8", "centos-8") + generate_dockerfile("centos8", "almalinux-8") generate_dockerfile("fedora", "fedora-35") generate_dockerfile("ubuntu1804", "ubuntu-1804", trailer="".join(ubuntu1804_skipssh))
Signature · 1 line
2.34.1
PATCH v8 9/12 target/hexagon: import lexer for idef-parser
In reply to Anton Johansson viaFrom: Paolo Montesel <[email protected]>
--- target/hexagon/idef-parser/idef-parser.h | 254 +++++++++ target/hexagon/idef-parser/idef-parser.lex | 566 +++++++++++++++++++++ target/hexagon/meson.build | 4 + 3 files changed, 824 insertions(+) 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 Labs Srl. 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/>. +*/ + +#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 }HexRegType ; + +typedef enum {UNKNOWN_SIGNEDNESS ,SIGNED ,UNSIGNED }HexSignedness ; + +/** +* Semantic record of the REG tokens, identifying registers +*/ +typedef struct HexReg { +uint8_t id;/**< Identifier of the register */ +HexRegType 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 { +unsigned 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_NPC , +IMM_CONSTEXT , +}; + +/** +* Semantic record of the IMM token, identifying an immediate constant +*/ +typedef struct HexImm { +union { +char id;/**< Identifier, used when type is VARIABLE */ +uint64_t value;/**< Immediate value, used when type is VALUE */ +uint64_t index;/**< Index, used when type is QEMU_TMP */ + }; +enum ImmUnionTag type;/**< Type of the immediate */ +}HexImm ; + +/** +* Semantic record of the PRED token, identifying a predicate +*/ +typedef struct HexPred { +char id;/**< Identifier of the predicate */ +}HexPred ; + +/** +* Semantic record of the SAT token, identifying the saturate operator +*/ +typedef struct HexSat { +bool set_overflow;/**< Should the sat. op. set overflow? */ +HexSignedness signedness;/**< Signedness of the sat. op. */ +}HexSat ; + +/** +* Semantic record of the CAST token, identifying the cast operator +*/ +typedef struct HexCast { +unsigned bit_width;/**< Bit width of the cast operator */ +HexSignedness signedness;/**< Unsigned flag for the cast operator */ +}HexCast ; + +/** +* Semantic record of the EXTRACT token, identifying the cast operator +*/ +typedef struct HexExtract { +unsigned bit_width;/**< Bit width of the extract operator */ +unsigned storage_bit_width;/**< Actual bit width of the extract operator */ +HexSignedness signedness;/**< Unsigned flag for the extract operator */ +}HexExtract ; + +/** +* Semantic record of the MPY token, identifying the fMPY multiplication +* operator +*/ +typedef struct HexMpy { +unsigned first_bit_width;/**< Bit width of 1st operand of fMPY */ +unsigned second_bit_width;/**< Bit width of 2nd operand of fMPY */ +HexSignedness first_signedness;/**< Signedness of 1st operand of fMPY */ +HexSignedness second_signedness;/**< Signedness of 2nd operand of fMPY */ +}HexMpy ; + +/** +* Semantic record of the VARID token, identifying declared variables +* of the input language +*/ +typedef struct HexVar { +GString *name;/**< Name of the VARID variable */ +}HexVar ; + +/** +* Data structure uniquely identifying a declared 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 variable */ +uint8_t bit_width;/**< Bit width of the VARID variable */ +HexSignedness signedness;/**< Unsigned flag for the VARID var */ +}Var ; + +/** +* Enum of the possible rvalue types, used in the HexValue.type field +*/ +typedef enum RvalueUnionTag { +REGISTER ,REGISTER_ARG ,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 */ +HexPred pred;/**< rvalue of predicate type */ +HexVar var;/**< rvalue of declared variable type */ + }; +RvalueUnionTag type;/**< Type of the rvalue */ +unsigned bit_width;/**< Bit width of the rvalue */ +HexSignedness signedness;/**< 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 */ +unsigned tmp_count;/**< Index of the last declared TCGv temp */ +unsigned qemu_tmp_count;/**< Index of the last declared int temp */ +unsigned if_count;/**< Index of the last declared if label */ +unsigned error_count;/**< Number of generated errors */ +GArray *allocated;/**< Allocated declaredVARID 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 header 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 */ +unsigned total_insn;/**< Number of instructions in input file */ +unsigned 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 +566 -0
566 lines not on this page · raw message
target/hexagon/meson.build +4 -0
@@ -196,4 +196,8 @@ preprocessed_idef_parser_input_generated = custom_target( command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'], ) +flex = generator(find_program('flex'), + output: ['@[email protected]', '@[email protected]'], + arguments: ['-o', '@OUTPUT0@', '--header-file=@OUTPUT1@', '@INPUT@']) + target_arch += {'hexagon': hexagon_ss}
Signature · 1 line
2.34.1
RE: [PATCH v8 09/12] target/hexagon: import lexer for idef-parser
Quoted 16 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Wednesday, February 9, 2022 11:03 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v8 09/12] target/hexagon: import lexer for idef-parserFrom: Paolo Montesel <[email protected]>
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Paolo Montesel <[email protected]>Signed-off-by Anton Johansson <[email protected]>
Quoted 8 lines
--- target/hexagon/idef-parser/idef-parser.h | 254 +++++++++ target/hexagon/idef-parser/idef-parser.lex | 566 +++++++++++++++++++++ target/hexagon/meson.build | 4 + 3 files changed, 824 insertions(+) create mode 100644 target/hexagon/idef-parser/idef-parser.h create mode 100644 target/hexagon/idef-parser/idef-parser.lex
PATCH v8 10/12 target/hexagon: import parser for idef-parser
In reply to Anton Johansson via--- target/hexagon/idef-parser/idef-parser.y | 1039 ++++++++ target/hexagon/idef-parser/parser-helpers.c | 2551 +++++++++++++++++++ target/hexagon/idef-parser/parser-helpers.h | 375 +++ target/hexagon/meson.build | 25 + 4 files changed, 3990 insertions(+) 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 +1039 -0
@@ -0,0 +1,1039 @@ +%{ +/* + * Copyright(c) 2019-2021 rev.ng Labs Srl. 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/>. + */ + +#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; + HexSignedness signedness; + int index; +} + +/* Tokens */ +%start input + +%expect 1 + +%token IN INAME VAR +%token ABS CROUND ROUND CIRCADD COUNTONES INC DEC ANDA ORA XORA PLUSPLUS ASL +%token ASR LSR EQ NEQ LTE GTE MIN MAX ANDL FOR ICIRC IF MUN FSCR FCHK SXT +%token ZXT CONSTEXT LOCNT BREV SIGN LOAD STORE PC NPC LPCFG +%token CANCEL IDENTITY PART1 ROTL INSBITS SETBITS EXTBITS EXTRANGE +%token CAST4_8U SETOVF FAIL CARRY_FROM_ADD ADDSAT64 LSBNEW +%token TYPE_SIZE_T TYPE_INT TYPE_SIGNED TYPE_UNSIGNED TYPE_LONG + +%token <rvalue> REG IMM PRED +%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 var_decl var_type +%type <rvalue> FAIL +%type <rvalue> TYPE_SIGNED TYPE_UNSIGNED TYPE_INT TYPE_LONG TYPE_SIZE_T +%type <index> if_stmt IF +%type <signedness> SIGN + +/* Operator Precedences */ +%left MIN MAX +%left '(' +%left ',' +%left '=' +%right CIRCADD +%right INC DEC ANDA ORA XORA +%left '?' ':' +%left ANDL +%left '|' +%left '^' ANDOR +%left '&' +%left EQ NEQ +%left '<' '>' LTE GTE +%left ASL ASR LSR +%right ABS +%left '-' '+' +%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 + { + EMIT_SIG(c, ")"); + EMIT_HEAD(c, "{\n"); + } + code + { + gen_inst_code(c, &@1); + } + | error /* Recover gracefully after instruction compilation error */ + { + free_instruction(c); + } + ; + +arguments : '(' ')' + | '(' argument_list ')'; + +argument_list : argument_decl ',' argument_list + | argument_decl + ; + +var : VAR + { + track_string(c, $1.var.name); + $$ = $1; + } + ; + +/* + * Here the integer types are defined from valid combinations of + * "signed", "unsigned", "int", and "long" tokens. The "signed" + * and "unsigned" tokens are here assumed to always be placed + * first in the type declaration, which is not the case in + * normal C. Similarly, "int" is assumed to be placed in the type. + */ +type_int : TYPE_INT + | TYPE_SIGNED + | TYPE_SIGNED TYPE_INT; +type_uint : TYPE_UNSIGNED + | TYPE_UNSIGNED TYPE_INT; +type_long : TYPE_LONG + | TYPE_LONG TYPE_INT + | TYPE_SIGNED TYPE_LONG + | TYPE_SIGNED TYPE_LONG TYPE_INT; +type_ulong : TYPE_UNSIGNED TYPE_LONG + | TYPE_UNSIGNED TYPE_LONG TYPE_INT; +type_longlong : TYPE_LONG TYPE_LONG + | TYPE_LONG TYPE_LONG TYPE_INT + | TYPE_SIGNED TYPE_LONG TYPE_LONG + | TYPE_SIGNED TYPE_LONG TYPE_LONG TYPE_INT; +type_ulonglong : TYPE_UNSIGNED TYPE_LONG TYPE_LONG + | TYPE_UNSIGNED TYPE_LONG TYPE_LONG TYPE_INT; + +/* + * Here the various valid int types defined above specify + * their `signedness` and `bit_width`. The LP64 convention + * is assumed where longs are 64-bit, long longs are then + * assumed to also be 64-bit.abvove + */ +var_type : TYPE_SIZE_T + { + yyassert(c, &@1, $1.bit_width <= 64, + "Variables with size > 64-bit are not supported!"); + $$ = $1; + } + | type_int + { + $$.signedness = SIGNED; + $$.bit_width = 32; + } + | type_uint + { + $$.signedness = UNSIGNED; + $$.bit_width = 32; + } + | type_long + { + $$.signedness = SIGNED; + $$.bit_width = 64; + } + | type_ulong + { + $$.signedness = UNSIGNED; + $$.bit_width = 64; + } + | type_longlong + { + $$.signedness = SIGNED; + $$.bit_width = 64; + } + | type_ulonglong + { + $$.signedness = UNSIGNED; + $$.bit_width = 64; + } + ; + +/* Rule to capture declarations of VARs */ +var_decl : var_type IMM + { + /* + * Rule to capture "int i;" declarations since "i" is special + * and assumed to be always be IMM. Moreover, "i" is only + * assumed to be used in for-loops. + * + * Therefore we want to NOP these declarations. + */ + yyassert(c, &@2, $2.imm.type == I, + "Variable declaration with immedaties only allowed" + " for the loop induction variable \"i\""); + $$ = $2; + } + | var_type var + { + /* + * Allocate new variable, this checks that it hasn't aldready + * been declared. + */ + gen_varid_allocate(c, &@1, &$2, $1.bit_width, $1.signedness); + /* Copy var for variable name */ + $$ = $2; + /* Copy type info from var_type */ + $$.signedness = $1.signedness; + $$.bit_width = $1.bit_width; + } + ; + +/* Return the modified registers list */ +code : '{' statements '}' + { + c->inst.code_begin = c->input_buffer + @2.first_column - 1; + c->inst.code_end = c->input_buffer + @2.last_column - 1; + } + | '{' + { + /* Nop */ + } + '}' + ; + +argument_decl : REG + { + emit_arg(c, &@1, &$1); + /* Enqueue register into initialization list */ + g_array_append_val(c->inst.init_list, $1); + } + | PRED + { + emit_arg(c, &@1, &$1); + /* Enqueue predicate into initialization list */ + g_array_append_val(c->inst.init_list, $1); + } + | IN REG + { + emit_arg(c, &@2, &$2); + } + | IN PRED + { + emit_arg(c, &@2, &$2); + } + | IMM + { + EMIT_SIG(c, ", int %ciV", $1.imm.id); + } + ; + +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 + | var_decl ';' + | rvalue ';' + { + gen_rvalue_free(c, &@1, &$1); + } + | code_block + | ';' + ; + +assign_statement : lvalue '=' rvalue + { + @1.last_column = @3.last_column; + gen_assign(c, &@1, &$1, &$3); + $$ = $1; + } + | var_decl '=' 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; + } + | PRED '=' rvalue + { + @1.last_column = @3.last_column; + gen_pred_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 = gen_rvalue_truncate(c, &@1, &$3); + $3 = rvalue_materialize(c, &@1, &$3); + OUT(c, &@1, "gen_write_new_pc(", &$3, ");\n"); + gen_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!"); + yyassert(c, &@1, $3.imm.value == 1, + "LOAD of arrays not supported!"); + gen_load(c, &@1, &$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!"); + yyassert(c, &@1, $3.imm.value == 1, + "STORE of arrays not supported!"); + gen_store(c, &@1, &$5, &$7, &$9); + } + | LPCFG '=' rvalue + { + @1.last_column = @3.last_column; + yyassert(c, &@1, c->ternary->len == 0, + "Assignment side-effect not modeled!"); + $3 = gen_rvalue_truncate(c, &@1, &$3); + $3 = rvalue_materialize(c, &@1, &$3); + OUT(c, &@1, "SET_USR_FIELD(USR_LPCFG, ", &$3, ");\n"); + gen_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 ')' ';' + { + gen_rvalue_free(c, &@1, &$3); + gen_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 ')' + { + yyassert(c, &@3, + $3.imm.type == I && + $7.imm.type == I && + $11.imm.type == I, + "Loop induction variable must be \"i\""); + @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 ')' + { + yyassert(c, &@3, + $3.imm.type == I && + $7.imm.type == I && + $11.imm.type == I, + "Loop induction variable must be \"i\""); + @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.type == REGISTER_ARG) { + $$ = gen_read_reg(c, &@1, &$1); + } else { + $$ = $1; + } + } + | IMM + { + $$ = $1; + } + | PRED + { + $$ = gen_rvalue_pred(c, &@1, &$1); + } + | PC + { + /* Read PC from the CR */ + HexValue rvalue; + memset(&rvalue, 0, sizeof(HexValue)); + rvalue.type = IMMEDIATE; + rvalue.imm.type = IMM_PC; + rvalue.bit_width = 32; + rvalue.signedness = UNSIGNED; + $$ = rvalue; + } + | NPC + { + /* + * NPC is only read from CALLs, so we can hardcode it + * at translation time + */ + HexValue rvalue; + memset(&rvalue, 0, sizeof(HexValue)); + rvalue.type = IMMEDIATE; + rvalue.imm.type = IMM_NPC; + rvalue.bit_width = 32; + rvalue.signedness = UNSIGNED; + $$ = rvalue; + } + | CONSTEXT + { + HexValue rvalue; + memset(&rvalue, 0, sizeof(HexValue)); + rvalue.type = IMMEDIATE; + rvalue.imm.type = IMM_CONSTEXT; + rvalue.signedness = UNSIGNED; + 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 '%' 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; + assert_signedness(c, &@1, $1.signedness); + if ($1.signedness == UNSIGNED) { + $$ = gen_bin_op(c, &@1, LSR_OP, &$1, &$3); + } else if ($1.signedness == SIGNED) { + $$ = 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.signedness = $1.signedness; + $$ = gen_cast_op(c, &@1, &$2, $1.bit_width, $1.signedness); + } + | 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; + + assert_signedness(c, &@1, $1.signedness); + assert_signedness(c, &@1, $3.signedness); + if ($1.signedness == UNSIGNED || $3.signedness == 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; + + assert_signedness(c, &@1, $1.signedness); + assert_signedness(c, &@1, $3.signedness); + if ($1.signedness == UNSIGNED || $3.signedness == 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; + + assert_signedness(c, &@1, $1.signedness); + assert_signedness(c, &@1, $3.signedness); + if ($1.signedness == UNSIGNED || $3.signedness == 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; + + assert_signedness(c, &@1, $1.signedness); + assert_signedness(c, &@1, $3.signedness); + if ($1.signedness == UNSIGNED || $3.signedness == 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"); + $$ = gen_extend_op(c, &@1, &$3, $5.imm.value, &$7, SIGNED); + } + | 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.imm.value, &$7, UNSIGNED); + } + | '(' 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, UNSIGNED); + OUT(c, &@1, "gen_read_ireg(", &$$, ", ", &$3, ", ", &$6, ");\n"); + gen_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, UNSIGNED); + OUT(c, &@1, "GET_USR_FIELD(USR_LPCFG, ", &$$, ");\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; + $$ = gen_rvalue_truncate(c, &@1, &$3); + $$.signedness = UNSIGNED; + $$ = rvalue_materialize(c, &@1, &$$); + $$ = gen_rvalue_extend(c, &@1, &$$); + } + | BREV '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_rvalue_brev(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, UNSIGNED); + 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, UNSIGNED); + gen_set_overflow(c, &@1, &ovfl); + $$ = $3; + } + | ADDSAT64 '(' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + gen_addsat64(c, &@1, &$3, &$5, &$7); + } + | CARRY_FROM_ADD '(' rvalue ',' rvalue ',' rvalue ')' + { + @1.last_column = @8.last_column; + $$ = gen_carry_from_add(c, &@1, &$3, &$5, &$7); + } + | LSBNEW '(' rvalue ')' + { + @1.last_column = @4.last_column; + HexValue one = gen_imm_value(c, &@1, 1, 32, UNSIGNED); + $$ = gen_bin_op(c, &@1, ANDB_OP, &$3, &one); + } + ; + +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 != (size_t) 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 +2551 -0
1,961 lines not on this page · raw message
target/hexagon/idef-parser/parser-helpers.h new file +375 -0
375 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
RE: [PATCH v8 10/12] target/hexagon: import parser for idef-parser
Quoted 31 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Wednesday, February 9, 2022 11:03 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v8 10/12] target/hexagon: import parser for idef-parserSigned-off-by Alessandro Di Federico <[email protected]>Signed-off-by Paolo Montesel <[email protected]>Signed-off-by Anton Johansson <[email protected]>target/hexagon/idef-parser/parser-helpers.c new file +8
-0+void gen_set_overflow (Context *c,YYLTYPE *locp,HexValue *value) +{ +HexValue value_m = *value; + +if (is_inside_ternary (c)) { +/* Inside ternary operator, need to take care of the side-effect */ +HexValue cond =get_ternary_cond (c, locp); + HexValue zero = gen_constant(c, locp, "0", cond.bit_width,UNSIGNED);
target/hexagon/idef-parser/parser-helpers.c line 2327
Quoted 9 lines
target/hexagon/idef-parser/parser-helpers.c new file +9
-0+bool is_64bit = cond.bit_width ==64 ; +unsigned bit_width = cond.bit_width; + value_m =rvalue_materialize (c, locp, &value_m); +if (is_64bit) { + value_m =gen_rvalue_extend (c, locp, &value_m); + } +OUT (c, locp,"tcg_gen_movcond_i" , &bit_width, +"(TCG_COND_NE, " , &value_m,", " , &cond); +OUT (c, locp,", " , &zero,", " , &value_m,", " , &zero,");\n" );
You shouldn't write zero when the condition is false - you should do nothing. Try a test where OVF is already set. You can't overwrite the bit with zero when the current instruction doesn't overflow.
Quoted 9 lines
target/hexagon/idef-parser/parser-helpers.c new file +9
-0+if (is_64bit) { + value_m =gen_rvalue_truncate (c, locp, &value_m); + } +gen_rvalue_free (c, locp, &cond); + } + +OUT (c, locp,"SET_USR_FIELD(USR_OVF, " , &value_m,");\n" ); +gen_rvalue_free (c, locp, &value_m); +}
Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parser
Very nice catch, this is the bug that plagued us a few weeks ago when rebasing, it has since been fixed. Actually the gen_set_overflow fucntion has been removed completely as it was only called when we handled asl/asr_r_r_sat.
Current way we handle overflow:
Overflow is now only set by saturates, this assumption holds for the instructions we parse in phase 1. In the parser, all saturates call gen_rvalue_sat which emits a call to gen_set_usr_field_if in genptr.c to set USR_OVF only if the value is non-zero. It does this via OR'ing with the previous value.
See here <https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/idef-parser/parser-helpers.c#L2109> for gen_rvalue_sat and here <https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/genptr.c#L669> for gen_set_usr_field_if
Quoted 50 lines
Quoted 28 lines
-----Original Message-----
From: Anton Johansson<[email protected]>
Sent: Wednesday, February 9, 2022 11:03 AM To:[email protected]
Cc:[email protected]; Taylor Simpson<[email protected]>; Brian Cain <[email protected]>; Michael Lambert<[email protected]>; [email protected];[email protected];[email protected]
Subject: [PATCH v8 10/12] target/hexagon: import parser for idef-parserSigned-off-by Alessandro Di Federico<[email protected]>Signed-off-by Paolo Montesel<[email protected]>Signed-off-by Anton Johansson<[email protected]>target/hexagon/idef-parser/parser-helpers.c new file +8
-0+void gen_set_overflow (Context *c,YYLTYPE *locp,HexValue *value) +{ +HexValue value_m = *value; + +if (is_inside_ternary (c)) { +/* Inside ternary operator, need to take care of the side-effect */ +HexValue cond =get_ternary_cond (c, locp); + HexValue zero = gen_constant(c, locp, "0", cond.bit_width,UNSIGNED);
target/hexagon/idef-parser/parser-helpers.c line 2327
Quoted 9 lines
target/hexagon/idef-parser/parser-helpers.c new file +9
-0+bool is_64bit = cond.bit_width ==64 ; +unsigned bit_width = cond.bit_width; + value_m =rvalue_materialize (c, locp, &value_m); +if (is_64bit) { + value_m =gen_rvalue_extend (c, locp, &value_m); + } +OUT (c, locp,"tcg_gen_movcond_i" , &bit_width, +"(TCG_COND_NE, " , &value_m,", " , &cond); +OUT (c, locp,", " , &zero,", " , &value_m,", " , &zero,");\n" );You shouldn't write zero when the condition is false - you should do nothing. Try a test where OVF is already set. You can't overwrite the bit with zero when the current instruction doesn't overflow.
Quoted 9 lines
target/hexagon/idef-parser/parser-helpers.c new file +9
-0+if (is_64bit) { + value_m =gen_rvalue_truncate (c, locp, &value_m); + } +gen_rvalue_free (c, locp, &cond); + } + +OUT (c, locp,"SET_USR_FIELD(USR_OVF, " , &value_m,");\n" ); +gen_rvalue_free (c, locp, &value_m); +}
RE: [PATCH v8 10/12] target/hexagon: import parser for idef-parser
Quoted 13 lines
From: Anton Johansson <[email protected]>
Sent: Tuesday, April 12, 2022 10:11 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parserVery nice catch, this is the bug that plagued us a few weeks ago when rebasing, it has since been fixed. Actually the
gen_set_overflowfucntion has been removed completely as it was only called when we handledasl/asr_r_r_sat. Current way we handle overflow:
Quoted 7 lines
Overflow is now only set by saturates, this assumption holds for the instructions we parse in phase 1. In the parser, all saturates call
gen_rvalue_satwhich emits a call togen_set_usr_field_ifingenptr.cto setUSR_OVFonly if the value is non-zero. It does this via OR'ing with the previous value.See https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/idef-parser/parser-helpers.c#L2109 for
gen_rvalue_satand https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/genptr.c#L669 forgen_set_usr_field_if
Your implementation of gen_set_usr_field_if is not correct. Don't extract the bits from the value based on the reg_field_info. The easiest thing to do is compare val with zero and jump over a call to gen_set_usr_field. If you are determined to do an "or", you have to assert that ref_field_info[field].width == 1. Then, you can extract 1 bit from val starting at offset zero and shift the result left by ref_field_info[field].offset and then "or" with USR.
Thanks,
Taylor
Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parser
Here's an updated version of gen_set_usr_field_If
https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/genptr.c#L673
If this looks alright and we have your "reviewed-by" on this patch, I'll go ahead and submit the new patchset! :)
Signature · 2 lines
Anton Johansson, rev.ng Labs Srl.
Quoted 23 lines
Quoted 12 lines
From: Anton Johansson <[email protected]>
Sent: Tuesday, April 12, 2022 10:11 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parserVery nice catch, this is the bug that plagued us a few weeks ago when rebasing, it has since been fixed. Actually the
gen_set_overflowfucntion has been removed completely as it was only called when we handledasl/asr_r_r_sat. Current way we handle overflow:Quoted 7 lines
Overflow is now only set by saturates, this assumption holds for the instructions we parse in phase 1. In the parser, all saturates call
gen_rvalue_satwhich emits a call togen_set_usr_field_ifingenptr.cto setUSR_OVFonly if the value is non-zero. It does this via OR'ing with the previous value.See https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/idef-parser/parser-helpers.c#L2109 for
gen_rvalue_satand https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/genptr.c#L669 forgen_set_usr_field_ifYour implementation of
gen_set_usr_field_ifis not correct. Don't extract the bits from the value based on thereg_field_info. The easiest thing to do is compare val with zero and jump over a call togen_set_usr_field. If you are determined to do an "or", you have to assert that ref_field_info[field].width == 1. Then, you can extract 1 bit from val starting at offset zero and shift the result left by ref_field_info[field].offset and then "or" with USR.Thanks,
Taylor
Taylor Simpson
Reviewed-byRE: [PATCH v8 10/12] target/hexagon: import parser for idef-parser
Quoted 20 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Thursday, April 21, 2022 6:51 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parserHere's an updated version of
gen_set_usr_field_Ifhttps://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-
parser/target/hexagon/genptr.c#L673If this looks alright and we have your "reviewed-by" on this patch, I'll go ahead and submit the new patchset! :)
Quoted 8 lines
/*
* Note: Since this function might branch,valis
* required to be atcg_temp_local.
*/
voidgen_set_usr_field_if(int field, TCGv val){ /* Sets the USR field if `val` is non-zero */ if (false && reg_field_info[field].width == 1) {
Remove the "false &&"
Otherwise
Quoted 14 lines
TCGv tmp = tcg_temp_new();
tcg_gen_extract_tl(tmp, val, 0, reg_field_info[field].width);
tcg_gen_shli_tl(tmp, tmp, reg_field_info[field].offset);
tcg_gen_or_tl(hex_new_value[HEX_REG_USR],
hex_new_value[HEX_REG_USR],
tmp);
tcg_temp_free(tmp);
} else {
TCGLabel *skip_label = gen_new_label();
tcg_gen_brcondi_tl(TCG_COND_EQ, val, 0, skip_label);
gen_set_usr_field(field, val);
gen_set_label(skip_label);
}
}Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parser
Quoted 27 lines
Quoted 24 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Thursday, April 21, 2022 6:51 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parserHere's an updated version of
gen_set_usr_field_Ifhttps://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-
parser/target/hexagon/genptr.c#L673If this looks alright and we have your "reviewed-by" on this patch, I'll go ahead and submit the new patchset! :)
/*
* Note: Since this function might branch,valis
* required to be atcg_temp_local.
*/
voidgen_set_usr_field_if(int field, TCGv val)Quoted 3 lines
{ /* Sets the USR field if `val` is non-zero */ if (false && reg_field_info[field].width == 1) {
Quoted 4 lines
Remove the "false &&"
Otherwise
Reviewed-by Taylor Simpson <[email protected]>
Ah ofc! Remnant of testing. Fixed.
I'll rebase and run the usual pre-submit tests once again.
Quoted 16 lines
Quoted 16 lines
TCGv tmp = tcg_temp_new(); tcg_gen_extract_tl(tmp, val, 0, reg_field_info[field].width); tcg_gen_shli_tl(tmp, tmp, reg_field_info[field].offset); tcg_gen_or_tl(hex_new_value[HEX_REG_USR], hex_new_value[HEX_REG_USR], tmp); tcg_temp_free(tmp); } else { TCGLabel *skip_label = gen_new_label(); tcg_gen_brcondi_tl(TCG_COND_EQ, val, 0, skip_label); gen_set_usr_field(field, val); gen_set_label(skip_label); } }
PATCH v8 11/12 target/hexagon: call idef-parser functions
In reply to Anton Johansson 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. An option is also added to fully disable the output of the idef-parser, which is useful for debugging purposes.
--- meson_options.txt | 3 + target/hexagon/gen_helper_funcs.py | 17 +++++- target/hexagon/gen_helper_protos.py | 17 +++++- target/hexagon/gen_tcg_funcs.py | 41 ++++++++++++- target/hexagon/hex_common.py | 10 ++++ target/hexagon/meson.build | 92 +++++++++++++++++++---------- 6 files changed, 146 insertions(+), 34 deletions(-)
meson_options.txt +3 -0
@@ -208,3 +208,6 @@ option('fdt', type: 'combo', value: 'auto', option('selinux', type: 'feature', value: 'auto', description: 'SELinux support in qemu-nbd') + +option('hexagon_idef_parser_enabled', type : 'boolean', value : true, + description: 'Whether idef-parser should be used to automatically generate TCG code for the Hexagon frontend')
target/hexagon/gen_helper_funcs.py +16 -1
@@ -287,11 +287,24 @@ def main(): hex_common.read_attribs_file(sys.argv[2]) hex_common.read_overrides_file(sys.argv[3]) hex_common.read_overrides_file(sys.argv[4]) + ## Whether or not idef-parser is enabled is + ## determined by the number of arguments to + ## this script: + ## + ## 5 args. -> not enabled, + ## 6 args. -> idef-parser enabled. + ## + ## The 6:th arg. then holds a list of the successfully + ## parsed instructions. + is_idef_parser_enabled = len(sys.argv) > 6 + if is_idef_parser_enabled: + hex_common.read_idef_parser_enabled_file(sys.argv[5]) hex_common.calculate_attribs() tagregs = hex_common.get_tagregs() tagimms = hex_common.get_tagimms() - with open(sys.argv[5], 'w') as f: + output_file = sys.argv[-1] + with open(output_file, 'w') as f: for tag in hex_common.tags: ## Skip the priv instructions if ( "A_PRIV" in hex_common.attribdict[tag] ) :
@@ -308,6 +321,8 @@ def main(): continue if ( hex_common.skip_qemu_helper(tag) ): continue + if ( hex_common.is_idef_parser_enabled(tag) ): + continue gen_helper_function(f, tag, tagregs, tagimms)
target/hexagon/gen_helper_protos.py +16 -1
@@ -136,11 +136,24 @@ def main(): hex_common.read_attribs_file(sys.argv[2]) hex_common.read_overrides_file(sys.argv[3]) hex_common.read_overrides_file(sys.argv[4]) + ## Whether or not idef-parser is enabled is + ## determined by the number of arguments to + ## this script: + ## + ## 5 args. -> not enabled, + ## 6 args. -> idef-parser enabled. + ## + ## The 6:th arg. then holds a list of the successfully + ## parsed instructions. + is_idef_parser_enabled = len(sys.argv) > 6 + if is_idef_parser_enabled: + hex_common.read_idef_parser_enabled_file(sys.argv[5]) hex_common.calculate_attribs() tagregs = hex_common.get_tagregs() tagimms = hex_common.get_tagimms() - with open(sys.argv[5], 'w') as f: + output_file = sys.argv[-1] + with open(output_file, 'w') as f: for tag in hex_common.tags: ## Skip the priv instructions if ( "A_PRIV" in hex_common.attribdict[tag] ) :
@@ -158,6 +171,8 @@ def main(): if ( hex_common.skip_qemu_helper(tag) ): continue + if ( hex_common.is_idef_parser_enabled(tag) ): + continue gen_helper_prototype(f, tag, tagregs, tagimms)
target/hexagon/gen_tcg_funcs.py +39 -2
58 lines not on this page · raw message
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.
@@ -216,6 +217,9 @@ def is_tmp_result(tag): def is_new_result(tag): return ('A_CVI_NEW' in attribdict[tag]) +def is_idef_parser_enabled(tag): + return tag in idef_parser_enabled + def imm_name(immlett): return "%siV" % immlett
@@ -247,3 +251,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 +62 -30
121 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v8 12/12 target/hexagon: import additional tests
In reply to Anton Johansson viaFrom: Niccolò Izzo <[email protected]>
--- tests/tcg/hexagon/Makefile.target | 28 ++++++++++++- tests/tcg/hexagon/crt.S | 14 +++++++ tests/tcg/hexagon/test_abs.S | 17 ++++++++ tests/tcg/hexagon/test_bitcnt.S | 40 +++++++++++++++++++ tests/tcg/hexagon/test_bitsplit.S | 22 ++++++++++ tests/tcg/hexagon/test_call.S | 64 ++++++++++++++++++++++++++++++ tests/tcg/hexagon/test_clobber.S | 29 ++++++++++++++ tests/tcg/hexagon/test_cmp.S | 31 +++++++++++++++ tests/tcg/hexagon/test_dotnew.S | 38 ++++++++++++++++++ tests/tcg/hexagon/test_ext.S | 13 ++++++ tests/tcg/hexagon/test_fibonacci.S | 30 ++++++++++++++ tests/tcg/hexagon/test_hl.S | 16 ++++++++ tests/tcg/hexagon/test_hwloops.S | 19 +++++++++ tests/tcg/hexagon/test_jmp.S | 22 ++++++++++ tests/tcg/hexagon/test_lsr.S | 36 +++++++++++++++++ tests/tcg/hexagon/test_mpyi.S | 17 ++++++++ tests/tcg/hexagon/test_packet.S | 29 ++++++++++++++ tests/tcg/hexagon/test_reorder.S | 33 +++++++++++++++ tests/tcg/hexagon/test_round.S | 29 ++++++++++++++ tests/tcg/hexagon/test_vavgw.S | 31 +++++++++++++++ tests/tcg/hexagon/test_vcmpb.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vcmpw.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vlsrw.S | 20 ++++++++++ tests/tcg/hexagon/test_vmaxh.S | 35 ++++++++++++++++ tests/tcg/hexagon/test_vminh.S | 35 ++++++++++++++++ tests/tcg/hexagon/test_vpmpyh.S | 28 +++++++++++++ tests/tcg/hexagon/test_vspliceb.S | 31 +++++++++++++++ 27 files changed, 766 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_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_dotnew.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_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_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_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 +27 -1
@@ -24,7 +24,7 @@ CFLAGS += -fno-unroll-loops 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
@@ -42,4 +42,30 @@ HEX_TESTS += atomics HEX_TESTS += fpstuff HEX_TESTS += overflow +HEX_TESTS += test_abs +HEX_TESTS += test_bitcnt +HEX_TESTS += test_bitsplit +HEX_TESTS += test_call +HEX_TESTS += test_clobber +HEX_TESTS += test_cmp +HEX_TESTS += test_dotnew +HEX_TESTS += test_ext +HEX_TESTS += test_fibonacci +HEX_TESTS += test_hl +HEX_TESTS += test_hwloops +HEX_TESTS += test_jmp +HEX_TESTS += test_lsr +HEX_TESTS += test_mpyi +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_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 +14 -0
@@ -0,0 +1,14 @@ +#define SYS_exit_group 94 + + .text + .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 +17 -0
@@ -0,0 +1,17 @@ +/* Purpose: test example, verify the soundness of the abs operation */ + + .text + .globl _start + +_start: + { + r1 = #-2 + r2 = #2 + } + { + r3 = abs(r1) + } + { + p0 = cmp.eq(r3, r2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_bitcnt.S new file +40 -0
@@ -0,0 +1,40 @@ +/* + * Purpose: test example, verify the soundness of the cl[01] operations. + * + * The number 0x000001aa has 23 leading zeroes + * they become 55 when considered as 64 bit register + * and it has 1 trailing zero. + */ + .text + .globl _start + +_start: + { + r0 = #426 + r1 = #0 + } + { + r2 = cl0(r0) + } + { + p0 = cmp.eq(r2, #23); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r2 = cl0(r1:0) + } + { + p0 = cmp.eq(r2, #55); if (p0.new) jump:t test3 + jump fail + } + +test3: + { + r2 = ct0(r0) + } + { + p0 = cmp.eq(r2, #1); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_bitsplit.S new file +22 -0
@@ -0,0 +1,22 @@ +/* Purpose: test example, verify the soundness of the bitsplit operation */ + + .text + .globl _start + +_start: + { + 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 +64 -0
64 lines not on this page · raw message
tests/tcg/hexagon/test_clobber.S new file +29 -0
@@ -0,0 +1,29 @@ +/* + * 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: + allocframe(#8) + { + r16 = #47 + r17 = #155 + } + memd(sp+#0) = r17:16 + { + r16 = #255 + r17 = #42 + } + { + deallocframe + r17:16 = memd(sp+#0) + } + { + p0 = cmp.eq(r16, #47) + p0 = cmp.eq(r17, #155); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_cmp.S new file +31 -0
@@ -0,0 +1,31 @@ +/* Purpose: test a signed and unsigned comparison */ + + .text + .globl _start + +_start: + { + 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_dotnew.S new file +38 -0
@@ -0,0 +1,38 @@ +/* Purpose: test the .new operator while performing memory stores. */ + + .text + .globl _start + +_start: + { + allocframe(#16) + } + { + 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) + } + { + deallocframe + p0 = cmp.eq(r3, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_ext.S new file +13 -0
@@ -0,0 +1,13 @@ +/* Purpose: test immediate extender instructions. */ + + .text + .globl _start + +_start: + { + r2 = ##-559038737 + } + { + p0 = cmp.eq(r2, ##-559038737); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_fibonacci.S new file +30 -0
@@ -0,0 +1,30 @@ +/* Purpose: computes the Fibonacci series up to a constant number. */ + + .text + .globl _start + +_start: + { + 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_hl.S new file +16 -0
@@ -0,0 +1,16 @@ +/* Purpose: test example, verify the soundness of the high/low assignment */ + + .text + .globl _start + +_start: + { + 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 +19 -0
@@ -0,0 +1,19 @@ +/* Purpose: simple C Program to test hardware loops. */ + + .text + .globl _start + +_start: + { + loop0(.LBB0_1, #10) + r2 = #0 + } +.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 +22 -0
@@ -0,0 +1,22 @@ +/* Purpose: test example, verify the soundness of the jump operation */ + +#define SYS_exit_group 94 + + .text + .globl _start + +_start: + { + jump pass + } + /* + * Inlined fail label in crt.S so we can fail without + * having a functioning jump + */ + { + r0 = #1 + r6 = #SYS_exit_group + } + { + trap0(#1) + }
tests/tcg/hexagon/test_lsr.S new file +36 -0
@@ -0,0 +1,36 @@ +/* Purpose: test the soundness of the lsr operation */ + + .text + .globl _start + +_start: + { + 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 +17 -0
@@ -0,0 +1,17 @@ +/* Purpose: test a simple multiplication operation */ + + .text + .globl _start + +_start: + { + 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_packet.S new file +29 -0
@@ -0,0 +1,29 @@ +/* + * Purpose: test that writes of a register in a packet are performed only after + * that packet has finished its execution. + */ + + .text + .globl _start + +_start: + { + allocframe(#8) + } + { + r2 = #4 + r3 = #6 + } + { + memw(sp+#0) = r2 + } + { + r3 = memw(sp+#0) + r0 = add(r2, r3) + } + { + deallocframe + p0 = cmp.eq(r3, #4) + p0 = cmp.eq(r0, #10); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_reorder.S new file +33 -0
@@ -0,0 +1,33 @@ +/* + * 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. + */ + + .text + .globl _start + +_start: + { + 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 +29 -0
@@ -0,0 +1,29 @@ +/* + * 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: + { + 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 +31 -0
@@ -0,0 +1,31 @@ +/* + * Purpose: test example, verify the soundness of the vavgw operation. + * + * 0x00030001 averaged with 0x00010003 results 0x00020002. + */ + + .text + .globl _start + +_start: + { + 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 +30 -0
@@ -0,0 +1,30 @@ +/* + * Purpose: test example, verify the soundness of the vector compare bytes + * operation. + * + * Vector byte comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0b11110000 in binary, or 0xf0 in hex. + */ + + .text + .globl _start + +_start: + { + r0 = #0x87654321 + r1 = #0x12345678 + } + { + r2 = #0x00000000 + r3 = #0x12345678 + } + { + p2 = vcmpb.eq(r1:0, r3:2) + } + { + r4 = p2 + } + { + p0 = cmp.eq(r4, #0xf0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpw.S new file +30 -0
@@ -0,0 +1,30 @@ +/* + * Purpose: test example, verify the soundness of the vector compare words + * operation. + * + * Vector word comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0b11110000 in binary, or 0xf0 in hex. + */ + + .text + .globl _start + +_start: + { + r0 = #0x87654321 + r1 = #0x12345678 + } + { + r2 = #0x00000000 + r3 = #0x12345678 + } + { + p2 = vcmpw.eq(r1:0, r3:2) + } + { + r4 = p2 + } + { + p0 = cmp.eq(r4, #0xf0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vlsrw.S new file +20 -0
@@ -0,0 +1,20 @@ +/* Purpose: test the soundness of the vlsrw operation */ + + .text + .globl _start + +_start: + { + 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 +35 -0
@@ -0,0 +1,35 @@ +/* + * Purpose: test example, verify the soundness of the vrmaxh operation. + * + * The maximum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007. + * + * input: r1 = 0x00010003 r0 = 0x00010005 r3 = 0x00030002 r2 = 0x00020007 + * output: r1 = 0x00030003 r0 = 0x00020007 + */ + + .text + .globl _start + +_start: + { + 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 +35 -0
@@ -0,0 +1,35 @@ +/* + * Purpose: test example, verify the soundness of the vrmaxh operation. + * + * The minimum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007. + * + * input: r1 = 0x00010003 r0 = 0x00010005 r3 = 0x00030002 r2 = 0x00020007 + * output: r1 = 0x00010002 r0 = 0x00010005 + */ + + .text + .globl _start + +_start: + { + 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 +28 -0
@@ -0,0 +1,28 @@ +/* + * Purpose: test example, verify the soundness of the vpmpyh operator. + * + * 0x01020304 vector polynomial multiplied with 0x04030201 results + * 0x000400060b060b04. + */ + + .text + .globl _start + +_start: + { + 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 +31 -0
@@ -0,0 +1,31 @@ +/* + * Purpose: test example, verify the soundness of the vspliceb operation + * the operation is a binary splice of two 64bit operators. + * + * vspliceb(0xffffffffffffffff,0x0000000000000000,5) = 0x000000ffffffffff. + */ + .text + .globl _start + +_start: + { + 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.34.1
RE: [PATCH v8 12/12] target/hexagon: import additional tests
Quoted 68 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Wednesday, February 9, 2022 11:03 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; Michael Lambert <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v8 12/12] target/hexagon: import additional testsFrom: Niccolò Izzo <[email protected]>
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Niccolò Izzo <[email protected]>Signed-off-by Anton Johansson <[email protected]>--- tests/tcg/hexagon/Makefile.target | 28 ++++++++++++- tests/tcg/hexagon/crt.S | 14 +++++++ tests/tcg/hexagon/test_abs.S | 17 ++++++++ tests/tcg/hexagon/test_bitcnt.S | 40 +++++++++++++++++++ tests/tcg/hexagon/test_bitsplit.S | 22 ++++++++++ tests/tcg/hexagon/test_call.S | 64 ++++++++++++++++++++++++++++++ tests/tcg/hexagon/test_clobber.S | 29 ++++++++++++++ tests/tcg/hexagon/test_cmp.S | 31 +++++++++++++++ tests/tcg/hexagon/test_dotnew.S | 38 ++++++++++++++++++ tests/tcg/hexagon/test_ext.S | 13 ++++++ tests/tcg/hexagon/test_fibonacci.S | 30 ++++++++++++++ tests/tcg/hexagon/test_hl.S | 16 ++++++++ tests/tcg/hexagon/test_hwloops.S | 19 +++++++++ tests/tcg/hexagon/test_jmp.S | 22 ++++++++++ tests/tcg/hexagon/test_lsr.S | 36 +++++++++++++++++ tests/tcg/hexagon/test_mpyi.S | 17 ++++++++ tests/tcg/hexagon/test_packet.S | 29 ++++++++++++++ tests/tcg/hexagon/test_reorder.S | 33 +++++++++++++++ tests/tcg/hexagon/test_round.S | 29 ++++++++++++++ tests/tcg/hexagon/test_vavgw.S | 31 +++++++++++++++ tests/tcg/hexagon/test_vcmpb.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vcmpw.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vlsrw.S | 20 ++++++++++ tests/tcg/hexagon/test_vmaxh.S | 35 ++++++++++++++++ tests/tcg/hexagon/test_vminh.S | 35 ++++++++++++++++ tests/tcg/hexagon/test_vpmpyh.S | 28 +++++++++++++ tests/tcg/hexagon/test_vspliceb.S | 31 +++++++++++++++ 27 files changed, 766 insertions(+), 1 deletion(-) create mode 100644
tests/tcg/hexagon/crt.Screate mode 100644tests/tcg/hexagon/test_abs.Screate mode 100644tests/tcg/hexagon/test_bitcnt.Screate mode 100644tests/tcg/hexagon/test_bitsplit.Screate mode 100644tests/tcg/hexagon/test_call.Screate mode 100644tests/tcg/hexagon/test_clobber.Screate mode 100644tests/tcg/hexagon/test_cmp.Screate mode 100644tests/tcg/hexagon/test_dotnew.Screate mode 100644tests/tcg/hexagon/test_ext.Screate mode 100644tests/tcg/hexagon/test_fibonacci.Screate mode 100644 tests/tcg/hexagon/test_hl.S create mode 100644
tests/tcg/hexagon/test_hwloops.Screate mode 100644tests/tcg/hexagon/test_jmp.Screate mode 100644tests/tcg/hexagon/test_lsr.Screate mode 100644tests/tcg/hexagon/test_mpyi.Screate mode 100644tests/tcg/hexagon/test_packet.Screate mode 100644tests/tcg/hexagon/test_reorder.Screate mode 100644tests/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_vlsrw.S create mode 100644 tests/tcg/hexagon/test_vmaxh.S create mode 100644 tests/tcg/hexagon/test_vminh.S create mode 100644
Quoted 2 lines
tests/tcg/hexagon/test_vpmpyh.Screate mode 100644tests/tcg/hexagon/test_vspliceb.S