target/hexagon: introduce idef-parser
Subsystems (2)
v7 cover target/hexagon: introduce idef-parser
This patchset introduces the idef-parser for target/hexagon.
It's the seventh iteration of the patchset and includes fixes suggested in previous iterations.
idef-parser is a build-time tool built using flex and bison. Its aim is to generate a large part of the tiny code generator frontend for Hexagon. The prototype of idef-parser has been presented at KVM Forum 2019 ("QEMU-Hexagon: Automatic Translation of the ISA Manual Pseudcode to Tiny Code Instructions"):
https://www.youtube.com/watch?v=3EpnTYBOXCI
target/hexagon/idef-parser/README.rst provides an overview of the parser and its inner working.
A couple of notes:
* Other than minor changes, tweaks, and cleanup, this patchset includes one change to the type system of idef-parser. Variables in the parser are no longer automatically typed, but we instead rely on declartions found inside fHIDE(int var;) macros in the input code.
* 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.
Last patch, we also introduced a commit to make sure containers produced by the developer Docker registry (as opposed to the official one) is used. Otherwise, the changes we made to the containers would not take effect.
However, as Daniel pointed out, our solution is a hack. Since this is a problem only for developers when introducing new dependencies for the containers, we might consider not merging the last patch at all. But it's required in order to get some success in testing on the CI it required.
Help on these matters is appreciated.
Alessandro Di Federico (5):
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
gitlab-ci: do not use qemu-project Docker registry
Anton Johansson (1):
target/hexagon: import parser for idef-parser
Niccolò Izzo (2):
target/hexagon: introduce new helper functions
target/hexagon: import additional tests
Paolo Montesel (5):
target/hexagon: make slot number an unsigned target/hexagon: make helper functions non-static target/hexagon: expose next PC in DisasContext target/hexagon: import flex/bison to docker files target/hexagon: import lexer for idef-parser
.gitlab-ci.d/container-cross.yml | 2 +- .gitlab-ci.d/container-template.yml | 4 +- .gitlab-ci.d/windows.yml | 2 + MAINTAINERS | 11 +- meson_options.txt | 3 + target/hexagon/README | 5 + target/hexagon/gen_helper_funcs.py | 16 +- target/hexagon/gen_helper_protos.py | 16 +- target/hexagon/gen_idef_parser_funcs.py | 123 + target/hexagon/gen_tcg_funcs.py | 39 +- target/hexagon/genptr.c | 229 +- target/hexagon/genptr.h | 44 + target/hexagon/helper.h | 2 + target/hexagon/hex_common.py | 10 + target/hexagon/idef-parser/README.rst | 722 +++++ target/hexagon/idef-parser/idef-parser.h | 259 ++ target/hexagon/idef-parser/idef-parser.lex | 571 ++++ target/hexagon/idef-parser/idef-parser.y | 1064 +++++++ target/hexagon/idef-parser/macros.inc | 140 + target/hexagon/idef-parser/parser-helpers.c | 2548 +++++++++++++++++ target/hexagon/idef-parser/parser-helpers.h | 379 +++ target/hexagon/idef-parser/prepare | 24 + target/hexagon/macros.h | 11 +- target/hexagon/meson.build | 137 +- target/hexagon/op_helper.c | 39 +- target/hexagon/op_helper.h | 37 + target/hexagon/translate.c | 3 +- target/hexagon/translate.h | 1 + tests/docker/dockerfiles/alpine.docker | 2 + tests/docker/dockerfiles/centos8.docker | 2 + 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 | 2 + tests/docker/dockerfiles/debian10.docker | 3 + .../dockerfiles/fedora-i386-cross.docker | 3 + .../dockerfiles/fedora-win32-cross.docker | 3 + .../dockerfiles/fedora-win64-cross.docker | 3 + tests/docker/dockerfiles/fedora.docker | 2 + tests/docker/dockerfiles/opensuse-leap.docker | 2 + tests/docker/dockerfiles/ubuntu.docker | 3 + tests/docker/dockerfiles/ubuntu1804.docker | 2 + tests/docker/dockerfiles/ubuntu2004.docker | 2 + tests/tcg/hexagon/Makefile.target | 30 +- tests/tcg/hexagon/crt.S | 26 + tests/tcg/hexagon/test_abs.S | 20 + tests/tcg/hexagon/test_bitcnt.S | 42 + tests/tcg/hexagon/test_bitsplit.S | 25 + tests/tcg/hexagon/test_call.S | 60 + tests/tcg/hexagon/test_clobber.S | 35 + tests/tcg/hexagon/test_cmp.S | 34 + tests/tcg/hexagon/test_cmpy.S | 31 + tests/tcg/hexagon/test_dotnew.S | 36 + tests/tcg/hexagon/test_ext.S | 16 + tests/tcg/hexagon/test_fibonacci.S | 33 + tests/tcg/hexagon/test_hl.S | 19 + tests/tcg/hexagon/test_hwloops.S | 22 + tests/tcg/hexagon/test_jmp.S | 25 + tests/tcg/hexagon/test_lsr.S | 39 + tests/tcg/hexagon/test_mpyi.S | 20 + tests/tcg/hexagon/test_overflow.S | 63 + tests/tcg/hexagon/test_packet.S | 26 + tests/tcg/hexagon/test_reorder.S | 29 + tests/tcg/hexagon/test_round.S | 31 + tests/tcg/hexagon/test_vavgw.S | 33 + tests/tcg/hexagon/test_vcmpb.S | 32 + tests/tcg/hexagon/test_vcmpw.S | 29 + tests/tcg/hexagon/test_vcmpy.S | 50 + tests/tcg/hexagon/test_vlsrw.S | 23 + tests/tcg/hexagon/test_vmaxh.S | 37 + tests/tcg/hexagon/test_vminh.S | 37 + tests/tcg/hexagon/test_vpmpyh.S | 30 + tests/tcg/hexagon/test_vspliceb.S | 33 + 73 files changed, 7353 insertions(+), 91 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_cmpy.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_overflow.S create mode 100644 tests/tcg/hexagon/test_packet.S create mode 100644 tests/tcg/hexagon/test_reorder.S create mode 100644 tests/tcg/hexagon/test_round.S create mode 100644 tests/tcg/hexagon/test_vavgw.S create mode 100644 tests/tcg/hexagon/test_vcmpb.S create mode 100644 tests/tcg/hexagon/test_vcmpw.S create mode 100644 tests/tcg/hexagon/test_vcmpy.S create mode 100644 tests/tcg/hexagon/test_vlsrw.S create mode 100644 tests/tcg/hexagon/test_vmaxh.S create mode 100644 tests/tcg/hexagon/test_vminh.S create mode 100644 tests/tcg/hexagon/test_vpmpyh.S create mode 100644 tests/tcg/hexagon/test_vspliceb.S
--
2.33.1
PATCH v7 1/13 target/hexagon: update MAINTAINERS for idef-parser
From: Alessandro Di Federico <[email protected]>
--- MAINTAINERS | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
MAINTAINERS +10 -1
@@ -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
@@ -2788,7 +2797,7 @@ R: Paolo Bonzini <[email protected]> R: Bandan Das <[email protected]> R: Stefan Hajnoczi <[email protected]> R: Thomas Huth <[email protected]> -R: Darren Kenny <[email protected]> +R: Darren Kenny <[email protected]> R: Qiuhao Li <[email protected]> S: Maintained F: tests/qtest/fuzz/
Signature · 1 line
2.33.1
RE: [PATCH v7 01/13] target/hexagon: update MAINTAINERS for idef-parser
Quoted 28 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 01/13] target/hexagon: updateMAINTAINERSfor idef- parserFrom: Alessandro Di Federico <[email protected]>
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Anton Johansson <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- MAINTAINERS | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)MAINTAINERS +0
-0
MAINTAINERS R: Paolo Bonzini <[email protected]> · line 2800
Quoted 5 lines
MAINTAINERS +1
-1@@ -2788,7 +2797,7 @@ R: Paolo Bonzini <[email protected]> R: Bandan Das <[email protected]> R: Stefan Hajnoczi <[email protected]> R: Thomas Huth <[email protected]> -R: Darren Kenny <[email protected]> +R: Darren Kenny <[email protected]>
This change looks spurious. Otherwise
PATCH v7 2/13 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.33.1
RE: [PATCH v7 02/13] target/hexagon: import README for idef-parser
Quoted 13 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 02/13] target/hexagon: import README for idef-parserFrom: Alessandro Di Federico <[email protected]>
Quoted 8 lines
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Anton Johansson <[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
PATCH v7 3/13 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.33.1
RE: [PATCH v7 03/13] target/hexagon: make slot number an unsigned
Quoted 11 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 03/13] target/hexagon: make slot number an unsigned
Quoted 8 lines
WARNING: This email originated from outside of Qualcomm. Please be wary of any links or attachments, and do not enable macros.
From: Paolo Montesel <[email protected]>
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Paolo Montesel <[email protected]>
PATCH v7 4/13 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.33.1
PATCH v7 5/13 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. "Helper" can here mean two things, a helper in the QEMU sense added to helper.h and op_helper.c, but also helper functions providing a manual TCG implementation of a certain features.
--- target/hexagon/genptr.c | 166 +++++++++++++++++++++++++++++++++++-- target/hexagon/genptr.h | 16 +++- target/hexagon/helper.h | 2 + target/hexagon/macros.h | 9 ++ target/hexagon/op_helper.c | 10 +++ 5 files changed, 195 insertions(+), 8 deletions(-)
target/hexagon/genptr.c +159 -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,152 @@ 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) +{ +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); +} + +void gen_set_usr_fieldi (int field,int x) +{ +TCGv val =tcg_const_tl (x); +gen_set_usr_field (field, val); +tcg_temp_free (val); +} + +void gen_write_new_pc (TCGv addr) +{ +/* If there are multiple branches in a packet, ignore the second one */ +TCGv zero =tcg_const_tl (0 ); +tcg_gen_movcond_tl (TCG_COND_NE , hex_next_PC, hex_branch_taken, zero, + hex_next_PC, addr); +tcg_gen_movi_tl (hex_branch_taken,1 ); +tcg_temp_free (zero); +} + +void gen_sat_i32 (TCGv dest,TCGv source,int width) +{ +TCGv max_val =tcg_const_tl ((1 << (width -1 )) -1 ); +TCGv min_val =tcg_const_tl (-(1 << (width -1 ))); +tcg_gen_smin_tl (dest, source, max_val); +tcg_gen_smax_tl (dest, dest, min_val); +tcg_temp_free (max_val); +tcg_temp_free (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_const_tl ((1 << width) -1 ); +tcg_gen_movcond_tl (TCG_COND_GTU , dest, source, max_val, max_val, source); +TCGv zero =tcg_const_tl (0 ); +tcg_gen_movcond_tl (TCG_COND_LT , dest, source, zero, zero, dest); +tcg_temp_free (max_val); +tcg_temp_free (zero); +} + +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_const_i64 ((1 << (width -1 )) -1 ); +TCGv_i64 min_val =tcg_const_i64 (-(1 << (width -1 ))); +tcg_gen_smin_i64 (dest, source, max_val); +tcg_gen_smax_i64 (dest, dest, min_val); +tcg_temp_free_i64 (max_val); +tcg_temp_free_i64 (min_val); +} + +void gen_sat_i64_ovfl (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width) +{ +gen_sat_i64 (dest, source, width); +TCGv_i64 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_const_i64 ((1 << width) -1 ); +tcg_gen_movcond_i64 (TCG_COND_GTU , dest, source, max_val, max_val, source); +TCGv_i64 zero =tcg_const_i64 (0 ); +tcg_gen_movcond_i64 (TCG_COND_LT , dest, source, zero, zero, dest); +tcg_temp_free_i64 (max_val); +tcg_temp_free_i64 (zero); +} + +void gen_satu_i64_ovfl (TCGv ovfl,TCGv_i64 dest,TCGv_i64 source,int width) +{ +gen_sat_i64 (dest, source, width); +TCGv_i64 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 (); +tcg_gen_add_i64 (sum, a, b); + +TCGv_i64 xor =tcg_temp_new_i64 (); +tcg_gen_xor_i64 (xor, a, b); + +TCGv_i64 mask =tcg_constant_i64 (0x8000000000000000ULL ); + +TCGv_i64 cond1 =tcg_temp_local_new_i64 (); +tcg_gen_and_i64 (cond1, xor, mask); +tcg_temp_free_i64 (xor); + +TCGv_i64 cond2 =tcg_temp_local_new_i64 (); +tcg_gen_xor_i64 (cond2, a, sum); +tcg_gen_and_i64 (cond2, cond2, mask); + +TCGLabel *no_ovfl_label =gen_new_label (); +TCGLabel *ovfl_label =gen_new_label (); +TCGLabel *ret_label =gen_new_label (); + +tcg_gen_brcondi_i64 (TCG_COND_NE , cond1,0 , no_ovfl_label); +tcg_temp_free_i64 (cond1); +tcg_gen_brcondi_i64 (TCG_COND_NE , cond2,0 , ovfl_label); +tcg_temp_free_i64 (cond2); +tcg_gen_br (no_ovfl_label); + +gen_set_label (no_ovfl_label); +tcg_gen_mov_i64 (ret, sum); +tcg_gen_br (ret_label); + +gen_set_label (ovfl_label); +TCGv_i64 cond3 =tcg_temp_new_i64 (); +tcg_gen_and_i64 (cond3, sum, mask); +tcg_temp_free_i64 (mask); +tcg_temp_free_i64 (sum); +TCGv_i64 max_pos =tcg_constant_i64 (0x7FFFFFFFFFFFFFFFLL ); +TCGv_i64 max_neg =tcg_constant_i64 (0x8000000000000000LL ); +TCGv_i64 zero =tcg_constant_i64 (0 ); +tcg_gen_movcond_i64 (TCG_COND_NE , ret, cond3, zero, max_pos, max_neg); +tcg_temp_free_i64 (max_pos); +tcg_temp_free_i64 (max_neg); +tcg_temp_free_i64 (zero); +tcg_temp_free_i64 (cond3); +SET_USR_FIELD (USR_OVF ,1 ); +tcg_gen_br (ret_label); + +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/helper.h +2 -0
@@ -27,6 +27,8 @@ DEF_HELPER_3(gather_store, void, env, i32, int) DEF_HELPER_1(commit_hvx_stores, void, env) DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32) DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32) +DEF_HELPER_FLAGS_1(fbrev_32, TCG_CALL_NO_RWG_SE, i32, i32) +DEF_HELPER_FLAGS_1(fbrev_64, TCG_CALL_NO_RWG_SE, i64, i64) DEF_HELPER_3(sfrecipa, i64, env, f32, f32) DEF_HELPER_2(sfinvsqrta, i64, env, f32)DEF_HELPER_4 (vacsh_val, s64, env, s64, s64, s64)
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)
target/hexagon/op_helper.c +10 -0
@@ -341,6 +341,16 @@ uint32_t HELPER(fbrev)(uint32_t addr)return deposit32 (addr,0 ,16 ,revbit16 (addr)); } +uint32_t HELPER (fbrev_32 )(uint32_t addr) +{ +return revbit32 (addr); +} + +uint64_t HELPER (fbrev_64 )(uint64_t addr) +{ +return revbit64 (addr); +} +static float32 build_float32 (uint8_t sign,uint32_t exp,uint32_t mant) { return make_float32(
Signature · 1 line
2.33.1
RE: [PATCH v7 05/13] target/hexagon: introduce new helper functions
Quoted 32 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 05/13] target/hexagon: introduce new helper functionsFrom: Niccolò Izzo <[email protected]>
These helpers will be employed by the idef-parser generated code. "Helper" can here mean two things, a helper in the QEMU sense added to
helper.handop_helper.c, but also helper functions providing a manual TCG implementation of a certain features.Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Niccolò Izzo <[email protected]>Signed-off-by Anton Johansson <[email protected]>--- target/hexagon/genptr.c | 166 +++++++++++++++++++++++++++++++++++-- target/hexagon/genptr.h | 16 +++- target/hexagon/helper.h | 2 + target/hexagon/macros.h | 9 ++ target/hexagon/op_helper.c | 10 +++ 5 files changed, 195 insertions(+), 8 deletions(-)target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +0
-0
ae798e921e..44a1ec9ccf100644
target/hexagon/genptr.c index
Quoted 3 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +3
-0+void gen_satu_i64_ovfl(TCGv ovfl, TCGv_i64 dest, TCGv_i64 source, int +width) { + gen_sat_i64(dest, source, width);
Should be gen_satu_i64 (unsigned)
Quoted 5 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +5
-0+ TCGv_i64 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); +}
RE: [PATCH v7 05/13] target/hexagon: introduce new helper functions
In reply to Anton Johansson viaQuoted 31 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 05/13] target/hexagon: introduce new helper functionsFrom: Niccolò Izzo <[email protected]>
These helpers will be employed by the idef-parser generated code. "Helper" can here mean two things, a helper in the QEMU sense added to
helper.handop_helper.c, but also helper functions providing a manual TCG implementation of a certain features.Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Niccolò Izzo <[email protected]>Signed-off-by Anton Johansson <[email protected]>--- target/hexagon/genptr.c | 166 +++++++++++++++++++++++++++++++++++-- target/hexagon/genptr.h | 16 +++- target/hexagon/helper.h | 2 + target/hexagon/macros.h | 9 ++ target/hexagon/op_helper.c | 10 +++ 5 files changed, 195 insertions(+), 8 deletions(-)
target/hexagon/genptr.c index
Quoted 4 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +3
-0+void gen_sat_i64(TCGv_i64 dest, TCGv_i64 source, int width) { + TCGv_i64 max_val = tcg_const_i64((1 << (width - 1)) - 1); + TCGv_i64 min_val = tcg_const_i64(-(1 << (width - 1)));
Doing those calculations as 32-bit numbers could be risky. Either do the calculations in 64-bits (1LL << (width -1) -1LL) or assert that width <= 32.
Also, consider changing all the tcg_const_* to tcg_constant_*. This is new in TCG and lets you avoid the tcg_temp_free at the end.
target/hexagon/genptr.c index
Quoted 8 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +8
-0+ tcg_gen_smin_i64(dest, source, max_val); + tcg_gen_smax_i64(dest, dest, min_val); + tcg_temp_free_i64(max_val); + tcg_temp_free_i64(min_val); +} + +void gen_satu_i64(TCGv_i64 dest, TCGv_i64 source, int width) { + TCGv_i64 max_val = tcg_const_i64((1 << width) - 1);
Same comment about this constant.
Quoted 3 lines
+ tcg_gen_movcond_i64(TCG_COND_GTU, dest, source,
max_val,max_val, source);
+TCGv_i64zero =tcg_const_i64(0);
QEMU coding conventions call for declarations to be at the top of the function, not in the middle.
target/hexagon/genptr.c index
Quoted 8 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +8
-0+ tcg_gen_movcond_i64(TCG_COND_LT, dest, source, zero, zero, dest); + tcg_temp_free_i64(max_val); + tcg_temp_free_i64(zero); +} + +void gen_satu_i64_ovfl(TCGv ovfl, TCGv_i64 dest, TCGv_i64 source, int +width) { + gen_sat_i64(dest, source, width);
gen_satu_i64
Quoted 7 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +7
-0+ TCGv_i64 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
target/hexagon/genptr.c index
Quoted 10 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +10
-0+gen_add_sat_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) { + TCGv_i64 sum = tcg_temp_local_new_i64(); + tcg_gen_add_i64(sum, a, b); + + TCGv_i64 xor = tcg_temp_new_i64(); + tcg_gen_xor_i64(xor, a, b); + + TCGv_i64 mask = tcg_constant_i64(0x8000000000000000ULL); + + TCGv_i64 cond1 = tcg_temp_local_new_i64();
This can be just tcg_temp_new_i64.
Quoted 6 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +6
-0+ tcg_gen_and_i64(cond1, xor, mask); + tcg_temp_free_i64(xor); + + TCGv_i64 cond2 = tcg_temp_local_new_i64(); + tcg_gen_xor_i64(cond2, a, sum); + tcg_gen_and_i64(cond2, cond2, mask);
target/hexagon/genptr.c index
Quoted 10 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +10
-0+ + TCGLabel *no_ovfl_label = gen_new_label(); + TCGLabel *ovfl_label = gen_new_label(); + TCGLabel *ret_label = gen_new_label(); + + tcg_gen_brcondi_i64(TCG_COND_NE, cond1, 0, no_ovfl_label); + tcg_temp_free_i64(cond1); + tcg_gen_brcondi_i64(TCG_COND_NE, cond2, 0, ovfl_label); + tcg_temp_free_i64(cond2); + tcg_gen_br(no_ovfl_label);
This is redundant since the label is just after the jump.
Quoted 15 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +14
-0+ + gen_set_label(no_ovfl_label); + tcg_gen_mov_i64(ret, sum); + tcg_gen_br(ret_label); + + gen_set_label(ovfl_label); + TCGv_i64 cond3 = tcg_temp_new_i64(); + tcg_gen_and_i64(cond3, sum, mask); + tcg_temp_free_i64(mask); + tcg_temp_free_i64(sum); + TCGv_i64 max_pos = tcg_constant_i64(0x7FFFFFFFFFFFFFFFLL); + TCGv_i64 max_neg = tcg_constant_i64(0x8000000000000000LL); + TCGv_i64 zero = tcg_constant_i64(0); + tcg_gen_movcond_i64(TCG_COND_NE, ret, cond3, zero, max_pos,
max_neg);
target/hexagon/genptr.c index
Quoted 6 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +6
-0+ tcg_temp_free_i64(max_pos); + tcg_temp_free_i64(max_neg); + tcg_temp_free_i64(zero); + tcg_temp_free_i64(cond3); + SET_USR_FIELD(USR_OVF, 1); + tcg_gen_br(ret_label);
This is also redundant.
Quoted 11 lines
target/hexagon/genptr.c index renamed from target/hexagon/genptr.c +4
-0+ + gen_set_label(ret_label); +} +target/hexagon/op_helper.c +0
-0
target/hexagon/op_helper.c uint32_t HELPER(fbrev)(uint32_t addr) · line 350
Quoted 10 lines
target/hexagon/op_helper.c +8
-0@@ -341,6 +341,16 @@ uint32_t HELPER(fbrev)(uint32_t addr)return deposit32 (addr,0 ,16 ,revbit16 (addr)); } +uint32_t HELPER (fbrev_32 )(uint32_t addr) { +return revbit32 (addr); +} + +uint64_t HELPER (fbrev_64 )(uint64_t addr) { +return revbit64 (addr); +} +
These are only used in a handful of instructions. It would be better to let those use the existing generator to create helpers for the full instruction.
Here are the instructions in question:Q6INSN(S2_brev, "Rd32=brev(Rs32)", ATTRIBS(A_ARCHV2), "Bit Reverse",{RdV = fBREV_4(RsV);})Q6INSN(S2_brevp,"Rdd32=brev(Rss32)", ATTRIBS(), "Bit Reverse",{RddV = fBREV_8(RssV);})
Q6INSN(S2_ct0, "Rd32=ct0(Rs32)", ATTRIBS(A_ARCHV2), "Count Trailing",{RdV = fCL1_4(~fBREV_4(RsV));})
Q6INSN(S2_ct1, "Rd32=ct1(Rs32)", ATTRIBS(A_ARCHV2), "Count Trailing",{RdV = fCL1_4(fBREV_4(RsV));})
Q6INSN(S2_ct0p, "Rd32=ct0(Rss32)", ATTRIBS(), "Count Trailing",{RdV = fCL1_8(~fBREV_8(RssV));})
Q6INSN(S2_ct1p, "Rd32=ct1(Rss32)", ATTRIBS(), "Count Trailing",{RdV = fCL1_8(fBREV_8(RssV));})
Q6INSN(A4_tlbmatch,"Pd4=tlbmatch(Rss32,Rt32)",ATTRIBS(A_NOTE_LATEPRED,A_RESTRICT_LATEPRED),
"Detect if a VA/ASID matches a TLB entry",
{
fHIDE(size4u_t TLBHI; size4u_t TLBLO; size4u_t MASK; size4u_t SIZE;)
MASK = 0x07ffffff;
TLBLO = fGETUWORD(0,RssV);
TLBHI = fGETUWORD(1,RssV);
SIZE = fMIN(6,fCL1_4(~fBREV_4(TLBLO)));
MASK &= (0xffffffff << 2*SIZE);
PdV = f8BITSOF(fGETBIT(31,TLBHI) && ((TLBHI & MASK) == (RtV & MASK)));
fHIDE(MARK_LATE_PRED_WRITE(PdN))
})PATCH v7 6/13 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.33.1
PATCH v7 7/13 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 | 123 +++++++++++++++++++++ target/hexagon/idef-parser/macros.inc | 140 ++++++++++++++++++++++++ target/hexagon/idef-parser/prepare | 24 ++++ target/hexagon/meson.build | 16 +++ 4 files changed, 303 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 +123 -0
@@ -0,0 +1,123 @@ +#!/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 other unsupported instructions + if ( tag.startswith('S2_cabacdecbin') ) : + continue + if ( tag.startswith('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 = [] + if hex_common.need_ea(tag): + arguments.append("EA") + + for regtype,regid,toss,numregs in regs: + prefix = "in " if hex_common.is_read(regid) else "" + + is_pair = hex_common.is_pair(regid) + is_single_old = (hex_common.is_single(regid) + and hex_common.is_old_val(regtype, regid, tag)) + is_single_new = (hex_common.is_single(regid) + and hex_common.is_new_val(regtype, regid, tag)) + + if is_pair or is_single_old: + arguments.append("%s%s%sV" % (prefix, regtype, regid)) + elif is_single_new: + arguments.append("%s%s%sN" % (prefix, regtype, regid)) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + + for immlett,bits,immshift in imms: + arguments.append(hex_common.imm_name(immlett)) + + f.write("%s(%s) {\n" % (tag, ", ".join(arguments))) + f.write(" %s\n" % hex_common.semdict[tag]) + f.write("}\n\n") + +if __name__ == "__main__": + main()
target/hexagon/idef-parser/macros.inc new file +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 library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +# + +set -e +set -o pipefail + +# Run the preprocessor and drop comments +cpp "$@"
target/hexagon/meson.build +16 -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,19 @@ 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@'], +) + +idef_parser_input_generated_prep = custom_target( + 'idef_parser_input.preprocessed.h.inc', + output: 'idef_parser_input.preprocessed.h.inc', + input: idef_parser_input_generated, + command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_dir, '-o', '@OUTPUT@'], +) + target_arch += {'hexagon': hexagon_ss}
Signature · 1 line
2.33.1
RE: [PATCH v7 07/13] target/hexagon: prepare input for the idef-parser
Quoted 31 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 07/13] 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]>--- target/hexagon/gen_idef_parser_funcs.py | 123 +++++++++++++++++++++ target/hexagon/idef-parser/macros.inc | 140 ++++++++++++++++++++++++ target/hexagon/idef-parser/prepare | 24 ++++ target/hexagon/meson.build | 16 +++ 4 files changed, 303 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 line 82
Quoted 5 lines
target/hexagon/gen_idef_parser_funcs.py new file +5
-0+ ## Skip other unsupported instructions + if ( tag.startswith('S2_cabacdecbin') ) : + continue + if ( tag.startswith('A5_ACS') ) : + continue
Not startswith, just
if (tag == 'S2_cabacdecbin' or tag == 'A5_ACS'):
continueQuoted 5 lines
target/hexagon/gen_idef_parser_funcs.py new file +5
-0+ if ( tag.startswith('Y') ) : + continue + if ( tag.startswith('V6_') ) : + continue + if ( tag.startswith('F') ) :
target/hexagon/gen_idef_parser_funcs.py line 97
Quoted 10 lines
target/hexagon/gen_idef_parser_funcs.py new file +10
-0+ continue + if ( tag.endswith('_locked') ) : + continue + + regs = tagregs[tag] + imms = tagimms[tag] + + arguments = [] + if hex_common.need_ea(tag): + arguments.append("EA")
It's a hack to add EA to the arguments list and then have special handling for it in the parser
/*
* The effective address EA is the only variable passed to
* function which needs to be "created".
*/
if (c->inst.EA) {
gen_varid_allocate(c, &@1, c->inst.EA, 32, SIGNED);
}Instead, put in a declaration inside the body - see below.
Quoted 12 lines
target/hexagon/gen_idef_parser_funcs.py new file +12
-0+ 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))
target/hexagon/gen_idef_parser_funcs.py line 118
Quoted 10 lines
target/hexagon/gen_idef_parser_funcs.py new file +10
-0+ 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)))
Put the declaration here inside the body.
if hex_common.need_ea(tag):
f.write(" size4u_t EA;\n")Quoted 29 lines
target/hexagon/gen_idef_parser_funcs.py new file +5
-0+ f.write(" %s\n" % hex_common.semdict[tag]) + f.write("}\n\n") + +if __name__ == "__main__": + main()target/hexagon/idef- renamed from target/hexagon/idef-parser/prepare +0
-0parser/prepare
new file mode 100755
index 0000000000..6377513dc5target/hexagon/idef-parser/prepare new file +13
-0@@ -0,0 +1,24 @@ +#!/bin/bash + +# +# Copyright(c) 2019-2021 rev.ng Labs Srl. All Rights Reserved. +# +# This library is free software; you can redistribute it and/or # +modify it under the terms of the GNU Lesser General Public # License as +published by the Free Software Foundation; either # version 2 of the +License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, # but +WITHOUT ANY WARRANTY; without even the implied warranty of # +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU#
target/hexagon/idef-parser/prepare
Quoted 5 lines
target/hexagon/idef-parser/prepare new file +5
-0+Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public # +License along with this library; if not, see <http://www.gnu.org/licenses/>. +#
I'm not a lawyer, but why are you marking this with LGPL?
Quoted 43 lines
target/hexagon/idef-parser/prepare new file +5
-0+ +set -e +set -o pipefail + +# Run the preprocessor and drop comments cpp "$@"target/hexagon/meson.build +18
-1@@ -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,19 @@ 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@'], +) + +idef_parser_input_generated_prep = custom_target( + 'idef_parser_input.preprocessed.h.inc', + output: 'idef_parser_input.preprocessed.h.inc', + input: idef_parser_input_generated, + command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + +idef_parser_dir, '-o', '@OUTPUT@'], +) + target_arch += {'hexagon': hexagon_ss} --2.33.1
RE: [PATCH v7 07/13] target/hexagon: prepare input for the idef-parser
In reply to Anton Johansson viaQuoted 25 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 07/13] 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]>target/hexagon/meson.build +0
-0
target/hexagon/meson.build hexagon_ss.add(files( · line 186
Quoted 7 lines
target/hexagon/meson.build +7
-0@@ -179,4 +180,19 @@ hexagon_ss.add(files( + +idef_parser_input_generated_prep = custom_target( + 'idef_parser_input.preprocessed.h.inc', + output: 'idef_parser_input.preprocessed.h.inc', + input: idef_parser_input_generated, + command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + +idef_parser_dir, '-o', '@OUTPUT@'],
This depends on macros.inc, but that is not indicated anywhere. So, a change to that file won't cause this file to be regenerated.
PATCH v7 8/13 target/hexagon: import flex/bison to docker files
In reply to Anton Johansson viaFrom: Paolo Montesel <[email protected]>
--- .gitlab-ci.d/windows.yml | 2 ++ tests/docker/dockerfiles/alpine.docker | 2 ++ tests/docker/dockerfiles/centos8.docker | 2 ++ 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 | 2 ++ 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 | 2 ++ tests/docker/dockerfiles/opensuse-leap.docker | 2 ++ tests/docker/dockerfiles/ubuntu.docker | 3 +++ tests/docker/dockerfiles/ubuntu1804.docker | 2 ++ tests/docker/dockerfiles/ubuntu2004.docker | 2 ++ 16 files changed, 39 insertions(+)
.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
tests/docker/dockerfiles/alpine.docker +2 -0
@@ -9,9 +9,11 @@ ENV PACKAGES \ alsa-lib-dev \ bash \ binutils \ + bison \ ccache \ coreutils \ curl-dev \ + flex \ g++ \ gcc \ git \
tests/docker/dockerfiles/centos8.docker +2 -0
@@ -5,6 +5,7 @@ ENV PACKAGES \ SDL2-devel \ alsa-lib-devel \ bc \ + bison \ brlapi-devel \ bzip2 \ bzip2-devel \
@@ -19,6 +20,7 @@ ENV PACKAGES \ device-mapper-multipath-devel \ diffutils \ findutils \ + flex \ gcc \ gcc-c++ \ genisoimage \
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 +2 -0
@@ -16,9 +16,11 @@ MAINTAINER Philippe Mathieu-Daudé <[email protected]> RUN apt update && \ DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \ DEBIAN_FRONTEND=noninteractive eatmydata apt install -yy \ + bison \ bzip2 \ ca-certificates \ ccache \ + flex \ g++ \ gcc \ git \
tests/docker/dockerfiles/debian10.docker +3 -0
@@ -17,16 +17,19 @@ RUN apt update && \ DEBIAN_FRONTEND=noninteractive apt install -yy eatmydata && \ DEBIAN_FRONTEND=noninteractive eatmydata \ apt install -y --no-install-recommends \ + bison \ bc \ 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
@@ -2,14 +2,17 @@ FROM registry.fedoraproject.org/fedora:33 # Please keep this list sorted alphabetically ENV PACKAGES \ + bison \ bc \ bzip2 \ ccache \ diffutils \ findutils \ + flex \ gcc \ gettext \ git \ + glib2-devel \ hostname \ make \ meson \
tests/docker/dockerfiles/fedora-win64-cross.docker +3 -0
@@ -2,13 +2,16 @@ FROM registry.fedoraproject.org/fedora:33 # Please keep this list sorted alphabetically ENV PACKAGES \ + bison \ bc \ bzip2 \ ccache \ diffutils \ findutils \ + flex \ gcc \ gettext \ + glib2-devel \ git \ hostname \ make \
tests/docker/dockerfiles/fedora.docker +2 -0
@@ -2,6 +2,7 @@ FROM registry.fedoraproject.org/fedora:33 # Please keep this list sorted alphabetically ENV PACKAGES \ + bison \ SDL2-devel \ SDL2_image-devel \ alsa-lib-devel \
@@ -20,6 +21,7 @@ ENV PACKAGES \ device-mapper-multipath-devel \ diffutils \ findutils \ + flex \ gcc \ gcc-c++ \ gcovr \
tests/docker/dockerfiles/opensuse-leap.docker +2 -0
@@ -5,6 +5,7 @@ ENV PACKAGES \ Mesa-devel \ alsa-lib-devel \ bc \ + bison \ brlapi-devel \ bzip2 \ ca-certificates \
@@ -15,6 +16,7 @@ ENV PACKAGES \ dbus-1 \ diffutils \ findutils \ + flex \ gcc \ gcc-c++ \ gcovr \
tests/docker/dockerfiles/ubuntu.docker +3 -0
@@ -11,9 +11,11 @@ FROM docker.io/library/ubuntu:20.04 ENV PACKAGES \ + bison \ ccache \ clang \ dbus \ + flex \ gcc \ gettext \ git \
@@ -30,6 +32,7 @@ ENV PACKAGES \ libfdt-dev \ libffi-dev \ libgbm-dev \ + libglib2.0-dev \ libgnutls28-dev \ libgtk-3-dev \ libibverbs-dev \
tests/docker/dockerfiles/ubuntu1804.docker +2 -0
@@ -1,6 +1,7 @@ FROM docker.io/library/ubuntu:18.04 ENV PACKAGES \ bc \ + bison \ bsdmainutils \ bzip2 \ ca-certificates \
@@ -11,6 +12,7 @@ ENV PACKAGES \ diffutils \ exuberant-ctags \ findutils \ + flex \ g++ \ gcc \ gcovr \
tests/docker/dockerfiles/ubuntu2004.docker +2 -0
@@ -1,5 +1,6 @@ FROM docker.io/library/ubuntu:20.04 ENV PACKAGES \ + bison \ bc \ bsdmainutils \ bzip2 \
@@ -11,6 +12,7 @@ ENV PACKAGES \ diffutils \ exuberant-ctags \ findutils \ + flex \ g++ \ gcc \ gcovr \
Signature · 1 line
2.33.1
PATCH v7 9/13 target/hexagon: import lexer for idef-parser
In reply to Anton Johansson viaFrom: Paolo Montesel <[email protected]>
--- target/hexagon/idef-parser/idef-parser.h | 259 ++++++++++ target/hexagon/idef-parser/idef-parser.lex | 571 +++++++++++++++++++++ target/hexagon/meson.build | 4 + 3 files changed, 834 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 +259 -0
@@ -0,0 +1,259 @@ +/* +* Copyright(c) 2019-2021 rev.ng Labs Srl. All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef IDEF_PARSER_H +#define IDEF_PARSER_H + +#include <inttypes.h> +#include <stdio.h> +#include <stdbool.h> +#include <glib.h> + +#define TCGV_NAME_SIZE 7 +#define MAX_WRITTEN_REGS 32 +#define OFFSET_STR_LEN 32 +#define ALLOC_LIST_LEN 32 +#define ALLOC_NAME_SIZE 32 +#define INIT_LIST_LEN 32 +#define OUT_BUF_LEN (1024 * 1024) +#define SIGNATURE_BUF_LEN (128 * 1024) +#define HEADER_BUF_LEN (128 * 1024) + +/* Variadic macros to wrap the buffer printing functions */ +#define EMIT (c, ...) \ + do { \ + g_string_append_printf((c)->out_str, __VA_ARGS__); \ + } while (0) + +#define EMIT_SIG (c, ...) \ + do { \ + g_string_append_printf((c)->signature_str, __VA_ARGS__); \ + } while (0) + +#define EMIT_HEAD (c, ...) \ + do { \ + g_string_append_printf((c)->header_str, __VA_ARGS__); \ + } while (0) + +/** +* Type of register, assigned to the HexReg.type field +*/ +typedef enum {GENERAL_PURPOSE ,CONTROL ,MODIFIER ,DOTNEW }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 { +int index;/**< Index of the TCGv temporary value */ +}HexTmp ; + +/** +* Enum of the possible immediated, an immediate is a value which is known +* at tinycode generation time, e.g. an integer value, not a TCGv +*/ +enum ImmUnionTag { +I , +VARIABLE , +VALUE , +QEMU_TMP , +IMM_PC , +IMM_NPC , +IMM_CONSTEXT , +}; + +/** +* Semantic record of the IMM token, identifying an immediate constant +*/ +typedef struct HexImm { +union { +char id;/**< Identifier of the immediate */ +uint64_t value;/**< Immediate value (for VALUE type immediates) */ +uint64_t index;/**< Index of the immediate (for int temp vars) */ + }; +enum ImmUnionTag type;/**< Type of the immediate */ +}HexImm ; + +/** +* Semantic record of the 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;/**< Set-overflow feature for the sat operator */ +HexSignedness signedness;/**< Unsigned flag for the saturate operator */ +}HexSat ; + +/** +* Semantic record of the CAST token, identifying the cast operator +*/ +typedef struct HexCast { +int bit_width;/**< Bit width of the cast operator */ +HexSignedness signedness;/**< Unsigned flag for the cast operator */ +}HexCast ; + +/** +* Semantic record of the EXTRACT token, identifying the cast operator +*/ +typedef struct HexExtract { +int bit_width;/**< Bit width of the extract operator */ +int storage_bit_width;/**< Actual bit width of the extract operator */ +HexSignedness signedness;/**< Unsigned flag for the extract operator */ +}HexExtract ; + +/** +* Semantic record of the MPY token, identifying the fMPY multiplication +* operator +*/ +typedef struct HexMpy { +/**< Bit width of the first operand of fMPY op */ +int first_bit_width; +/**< Bit width of the second operand of fMPY */ +int second_bit_width; +/**< Signedness flag for the first operand of fMPY */ +HexSignedness first_signedness; +/**< Signedness flag for second operand of fMPY */ +HexSignedness second_signedness; +}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 */ +int tmp_count;/**< Index of the last declared TCGv temp */ +int qemu_tmp_count;/**< Index of the last declared int temp */ +int if_count;/**< Index of the last declared if label */ +int error_count;/**< Number of generated errors */ +HexValue *EA;/**< Effective Address (EA) */ +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 */ +int total_insn;/**< Number of instructions in input file */ +int implemented_insn;/**< Instruction compiled without errors */ +Inst inst;/**< Parsing data of the current inst */ +}Context ; + +#endif /* IDEF_PARSER_H */
target/hexagon/idef-parser/idef-parser.lex new file +571 -0
571 lines not on this page · raw message
target/hexagon/meson.build +4 -0
@@ -195,4 +195,8 @@ idef_parser_input_generated_prep = 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.33.1
RE: [PATCH v7 09/13] target/hexagon: import lexer for idef-parser
Quoted 31 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 09/13] 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]>--- target/hexagon/idef-parser/idef-parser.h | 259 ++++++++++ target/hexagon/idef-parser/idef-parser.lex | 571 +++++++++++++++++++++ target/hexagon/meson.build | 4 + 3 files changed, 834 insertions(+) create mode 100644 target/hexagon/idef-parser/idef-parser.h create mode 100644 target/hexagon/idef-parser/idef-parser.lextarget/hexagon/idef-parser/idef-parser.lex new file +0
-0
target/hexagon/idef-parser/idef-parser.lex line 211
Quoted 7 lines
target/hexagon/idef-parser/idef-parser.lex new file +7
-0+"fSATN" { yylval->sat.set_overflow = true; + yylval->sat.signedness = SIGNED; + return SAT; } +"fVSATN" { yylval->sat.set_overflow = false; + yylval->sat.signedness = SIGNED; + return SAT; } +"fSATUN" { yylval->sat.set_overflow = false;
This should be true, just like fSATN. Take a look at the satuh and satub instructions.
I tried changing it to true to make satuh and satub work. However, the vaddubs, vadduhs, vsatub, vsatwuh, vsububs, and other instructions don't work. I've attached a test case that demonstrates this problem.
When the value is set to false, the test case prints ERROR at line 71: 0x00000000 != 0x00000001 ERROR at line 75: 0x00000000 != 0x00000001 ERROR at line 106: 0x00000000 != 0x00000001 FAIL
When the value is set to true, the test case prints ERROR at line 105: 0x000000000000007f != 0x00000000000000ff ERROR at line 106: 0x00000000 != 0x00000001
FAIL
Without your changes, the test case prints
PASS
target/hexagon/idef-parser/idef-parser.lex line 213
Quoted 2 lines
target/hexagon/idef-parser/idef-parser.lex new file +2
-0+ yylval->sat.signedness = UNSIGNED; + return SAT; }
/*
* 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/>.
*/
#include <stdio.h>
#include <stdint.h>
int err;
static void __check32(int line, int val, int expect)
{
if (val != expect) {
printf("ERROR at line %d: 0x%08x != 0x%08x\n", line, val, expect);
err++;
}
}#define check32(RES, EXP) __check32(__LINE__, RES, EXP)
static void __check64(int line, long long val, long long expect)
{
if (val != expect) {
printf("ERROR at line %d: 0x%016llx != 0x%016llx\n", line, val, expect);
err++;
}
}#define check64(RES, EXP) __check64(__LINE__, RES, EXP)
static uint32_t satub(uint32_t src, int *ovf_result)
{
uint32_t result;
uint32_t usr;
/*
* This instruction can set bit 0 (OVF/overflow) in usr
* Clear the bit first, then return that bit to the caller
*/
asm volatile("r2 = usr\n\t"
"r2 = clrbit(r2, #0)\n\t" /* clear overflow bit */
"usr = r2\n\t"
"%0 = satub(%2)\n\t"
"%1 = usr\n\t"
: "=r"(result), "=r"(usr)
: "r"(src)
: "r2", "usr");
*ovf_result = (usr & 1);
return result;
}static void test_satub(void)
{
uint32_t result;
int ovf_result;
result = satub(0xfff, &ovf_result);
check32(result, 0xff);
check32(ovf_result, 1);
result = satub(-1, &ovf_result);
check32(result, 0);
check32(ovf_result, 1);
}static uint64_t vaddubs(uint64_t src1, uint64_t src2, int *ovf_result)
{
uint64_t result;
uint32_t usr;
/*
* This instruction can set bit 0 (OVF/overflow) in usr
* Clear the bit first, then return that bit to the caller
*/
asm volatile("r2 = usr\n\t"
"r2 = clrbit(r2, #0)\n\t" /* clear overflow bit */
"usr = r2\n\t"
"%0 = vaddub(%2, %3):sat\n\t"
"%1 = usr\n\t"
: "=r"(result), "=r"(usr)
: "r"(src1), "r"(src2)
: "r2", "usr");
*ovf_result = (usr & 1);
return result;
}static void test_vaddubs(void)
{
uint64_t result;
int ovf_result;
result = vaddubs(0xffLL, 0xffLL, &ovf_result);
check64(result, 0xffLL);
check32(ovf_result, 1);
}int main()
{
test_satub();
test_vaddubs();
puts(err ? "FAIL" : "PASS");
return err;
}PATCH v7 10/13 target/hexagon: import parser for idef-parser
In reply to Anton Johansson via--- target/hexagon/idef-parser/idef-parser.y | 1064 ++++++++ target/hexagon/idef-parser/parser-helpers.c | 2548 +++++++++++++++++++ target/hexagon/idef-parser/parser-helpers.h | 379 +++ target/hexagon/meson.build | 27 +- 4 files changed, 4017 insertions(+), 1 deletion(-) 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 +1064 -0
@@ -0,0 +1,1064 @@ +%{ +/* + * Copyright(c) 2019-2021 rev.ng Labs Srl. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "idef-parser.h" +#include "parser-helpers.h" +#include "idef-parser.tab.h" +#include "idef-parser.yy.h" + +/* Uncomment this to disable yyasserts */ +/* #define NDEBUG */ + +#define ERR_LINE_CONTEXT 40 + +%} + +%lex-param {void *scanner} +%parse-param {void *scanner} +%parse-param {Context *c} + +%define parse.error verbose +%define parse.lac full +%define api.pure full + +%locations + +%union { + GString *string; + HexValue rvalue; + HexSat sat; + HexCast cast; + HexExtract extract; + HexMpy mpy; + 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 BREV_4 BREV_8 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"); + + /* + * The effective address EA is the only variable passed to + * function which needs to be "created". + */ + if (c->inst.EA) { + gen_varid_allocate(c, &@1, c->inst.EA, 32, SIGNED); + } + } + 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); + } + | var + { + yyassert(c, &@1, !strcmp($1.var.name->str, "EA"), + "Unknown argument variable!"); + /* The instruction take EA, so set it */ + c->inst.EA = &$1; + } + ; + +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); + } + | BREV_4 '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_fbrev_4(c, &@1, &$3); + } + | BREV_8 '(' rvalue ')' + { + @1.last_column = @4.last_column; + $$ = gen_fbrev_8(c, &@1, &$3); + } + | ROTL '(' rvalue ',' rvalue ')' + { + @1.last_column = @6.last_column; + $$ = gen_rotl(c, &@1, &$3, &$5); + } + | SETOVF '(' ')' + { + @1.last_column = @3.last_column; + HexValue ovfl = gen_imm_value(c, &@1, 1, 32, 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 +2548 -0
1,936 lines not on this page · raw message
target/hexagon/idef-parser/parser-helpers.h new file +379 -0
379 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.33.1
Part of the diff is not shown here. View the raw message.
PATCH v7 11/13 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 | 16 ++++- target/hexagon/gen_helper_protos.py | 16 ++++- target/hexagon/gen_tcg_funcs.py | 39 +++++++++++- target/hexagon/hex_common.py | 10 ++++ target/hexagon/meson.build | 92 +++++++++++++++++++---------- 6 files changed, 142 insertions(+), 34 deletions(-)
meson_options.txt +3 -0
@@ -206,3 +206,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 +15 -1
@@ -287,11 +287,23 @@ 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. + if len(sys.argv) > 6: + 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 +320,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 +15 -1
@@ -136,11 +136,23 @@ 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. + if len(sys.argv) > 6: + 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 +170,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 +37 -2
@@ -610,7 +610,29 @@ def gen_tcg_func(f, tag, regs, imms): if (hex_common.is_read(regid)): genptr_src_read_opn(f,regtype,regid,tag) - if ( hex_common.skip_qemu_helper(tag) ): + if hex_common.is_idef_parser_enabled(tag): + declared = [] + ## Handle registers + for regtype,regid,toss,numregs in regs: + if (hex_common.is_pair(regid) + or (hex_common.is_single(regid) + and hex_common.is_old_val(regtype, regid, tag))): + declared.append("%s%sV" % (regtype, regid)) + if regtype == "M": + declared.append("%s%sN" % (regtype, regid)) + elif hex_common.is_new_val(regtype, regid, tag): + declared.append("%s%sN" % (regtype,regid)) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + + ## Handle immediates + for immlett,bits,immshift in imms: + declared.append(hex_common.imm_name(immlett)) + + arguments = ", ".join(["ctx", "insn", "pkt"] + declared) + f.write(" emit_%s(%s);\n" % (tag, arguments)) + + elif ( hex_common.skip_qemu_helper(tag) ): f.write(" fGEN_TCG_%s(%s);\n" % (tag, hex_common.semdict[tag])) else: ## Generate the call to the helper
@@ -677,12 +699,25 @@ def main(): hex_common.read_overrides_file(sys.argv[3]) hex_common.read_overrides_file(sys.argv[4]) hex_common.calculate_attribs() + ## 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. + if len(sys.argv) > 6: + hex_common.read_idef_parser_enabled_file(sys.argv[5]) 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: f.write("#ifndef HEXAGON_TCG_FUNCS_H\n") f.write("#define HEXAGON_TCG_FUNCS_H\n\n") + f.write("#include \"idef-generated-emitter.h.inc\"\n\n") for tag in hex_common.tags: ## Skip the priv instructions
target/hexagon/hex_common.py +10 -0
@@ -28,6 +28,7 @@ attribinfo = {} # Register information and misc tags = [] # list of all tags overrides = {} # tags with helper overrides +idef_parser_enabled = {} # tags enabled for idef-parser # We should do this as a hash for performance, # but to keep order let's keep it as a list.
@@ -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.33.1
RE: [PATCH v7 11/13] target/hexagon: call idef-parser functions
Quoted 37 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 11/13] target/hexagon: call idef-parser functionsFrom: Alessandro Di Federico <[email protected]>
Extend
gen_tcg_funcs.pyin order to emit calls to the functions emitted by the idef-parser, if available. An option is also added to fully disable the output of the idef-parser, which is useful for debugging purposes.Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Anton Johansson <[email protected]>Reviewed-by Taylor Simpson <[email protected]>(quoted diff) +0
-0
b/target/hexagon/gen_tcg_funcs.pyindex1fd9de95d5..0ea89d1ed7100755target/hexagon/gen_tcg_funcs.py +10
-0hex_common.calculate_attribs() + ## 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. + if len(sys.argv) > 6:
target/hexagon/gen_tcg_funcs.py def main(): · line 720
Quoted 10 lines
target/hexagon/gen_tcg_funcs.py +4
-1+ hex_common.read_idef_parser_enabled_file(sys.argv[5]) 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: f.write("#ifndef HEXAGON_TCG_FUNCS_H\n") f.write("#define HEXAGON_TCG_FUNCS_H\n\n") + f.write("#include \"idef-generated-emitter.h.inc\"\n\n")
This should be conditional on the number of arguments to this script
PATCH v7 12/13 target/hexagon: import additional tests
In reply to Anton Johansson viaFrom: Niccolò Izzo <[email protected]>
--- tests/tcg/hexagon/Makefile.target | 30 +++++++++++++- tests/tcg/hexagon/crt.S | 26 ++++++++++++ tests/tcg/hexagon/test_abs.S | 20 ++++++++++ tests/tcg/hexagon/test_bitcnt.S | 42 ++++++++++++++++++++ tests/tcg/hexagon/test_bitsplit.S | 25 ++++++++++++ tests/tcg/hexagon/test_call.S | 60 ++++++++++++++++++++++++++++ tests/tcg/hexagon/test_clobber.S | 35 +++++++++++++++++ tests/tcg/hexagon/test_cmp.S | 34 ++++++++++++++++ tests/tcg/hexagon/test_cmpy.S | 31 +++++++++++++++ tests/tcg/hexagon/test_dotnew.S | 36 +++++++++++++++++ tests/tcg/hexagon/test_ext.S | 16 ++++++++ tests/tcg/hexagon/test_fibonacci.S | 33 ++++++++++++++++ tests/tcg/hexagon/test_hl.S | 19 +++++++++ tests/tcg/hexagon/test_hwloops.S | 22 +++++++++++ tests/tcg/hexagon/test_jmp.S | 25 ++++++++++++ tests/tcg/hexagon/test_lsr.S | 39 ++++++++++++++++++ tests/tcg/hexagon/test_mpyi.S | 20 ++++++++++ tests/tcg/hexagon/test_overflow.S | 63 ++++++++++++++++++++++++++++++ tests/tcg/hexagon/test_packet.S | 26 ++++++++++++ tests/tcg/hexagon/test_reorder.S | 29 ++++++++++++++ tests/tcg/hexagon/test_round.S | 31 +++++++++++++++ tests/tcg/hexagon/test_vavgw.S | 33 ++++++++++++++++ tests/tcg/hexagon/test_vcmpb.S | 32 +++++++++++++++ tests/tcg/hexagon/test_vcmpw.S | 29 ++++++++++++++ tests/tcg/hexagon/test_vcmpy.S | 50 ++++++++++++++++++++++++ tests/tcg/hexagon/test_vlsrw.S | 23 +++++++++++ tests/tcg/hexagon/test_vmaxh.S | 37 ++++++++++++++++++ tests/tcg/hexagon/test_vminh.S | 37 ++++++++++++++++++ tests/tcg/hexagon/test_vpmpyh.S | 30 ++++++++++++++ tests/tcg/hexagon/test_vspliceb.S | 33 ++++++++++++++++ 30 files changed, 965 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_cmpy.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_overflow.S create mode 100644 tests/tcg/hexagon/test_packet.S create mode 100644 tests/tcg/hexagon/test_reorder.S create mode 100644 tests/tcg/hexagon/test_round.S create mode 100644 tests/tcg/hexagon/test_vavgw.S create mode 100644 tests/tcg/hexagon/test_vcmpb.S create mode 100644 tests/tcg/hexagon/test_vcmpw.S create mode 100644 tests/tcg/hexagon/test_vcmpy.S create mode 100644 tests/tcg/hexagon/test_vlsrw.S create mode 100644 tests/tcg/hexagon/test_vmaxh.S create mode 100644 tests/tcg/hexagon/test_vminh.S create mode 100644 tests/tcg/hexagon/test_vpmpyh.S create mode 100644 tests/tcg/hexagon/test_vspliceb.S
tests/tcg/hexagon/Makefile.target +29 -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,32 @@ HEX_TESTS += atomics HEX_TESTS += fpstuff HEX_TESTS += overflow +HEX_TESTS += test_abs +HEX_TESTS += test_bitcnt +HEX_TESTS += test_bitsplit +HEX_TESTS += test_clobber +HEX_TESTS += test_cmp +HEX_TESTS += test_cmpy +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_overflow +HEX_TESTS += test_packet +HEX_TESTS += test_reorder +HEX_TESTS += test_round +HEX_TESTS += test_vavgw +HEX_TESTS += test_vcmpb +HEX_TESTS += test_vcmpw +HEX_TESTS += test_vcmpy +HEX_TESTS += test_vlsrw +HEX_TESTS += test_vmaxh +HEX_TESTS += test_vminh +HEX_TESTS += test_vpmpyh +HEX_TESTS += test_vspliceb + TESTS += $(HEX_TESTS)
tests/tcg/hexagon/crt.S new file +26 -0
@@ -0,0 +1,26 @@ +#define SYS_exit_group 94 + + .text + .globl init +init: + { + allocframe(r29,#0):raw + } + { + r0=#256 + } + { + dealloc_return + } + + .globl pass +pass: + r0 = #0 + r6 = #SYS_exit_group + trap0(#1) + + .globl fail +fail: + r0 = #1 + r6 = #SYS_exit_group + trap0(#1)
tests/tcg/hexagon/test_abs.S new file +20 -0
@@ -0,0 +1,20 @@ +/* Purpose: test example, verify the soundness of the abs operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#-2 + r2=#2 + } + { + r3=abs(r1) + } + { + p0 = cmp.eq(r3, r2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_bitcnt.S new file +42 -0
42 lines not on this page · raw message
tests/tcg/hexagon/test_bitsplit.S new file +25 -0
@@ -0,0 +1,25 @@ +/* Purpose: test example, verify the soundness of the bitsplit operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#187 + } + { + r3:2=bitsplit(r1, #3) + } + { + p0 = cmp.eq(r2, #3); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r3, #23); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_call.S new file +60 -0
60 lines not on this page · raw message
tests/tcg/hexagon/test_clobber.S new file +35 -0
@@ -0,0 +1,35 @@ +/* Purpose: demonstrate the succesful operation of the register save mechanism, + * in which the caller saves the registers that will be clobbered, and restores + * them after the call. + */ + + .text + .globl _start + +_start: + { + call init + } + { + r16=#47 + r17=#155 + } + { + memd(r29+#-16)=r17:16; allocframe(#8) + } + { + r16=#255 + r17=#42 + } + { + r17:16=memd(r29+#0); deallocframe + } + { + r3=add(r16,r17) + } + { + p0 = cmp.eq(r3, #202); if (p0.new) jump:t pass + } + { + jump fail + }
tests/tcg/hexagon/test_cmp.S new file +34 -0
@@ -0,0 +1,34 @@ +/* Purpose: test a signed and unsigned comparison */ + + .text + .globl _start + +_start: + { + call init + } + { + jump signed + } + + .globl signed +signed: + { + r0=#-2 + r1=#0 + } + { + p0 = cmp.lt(r0, r1); if (p0.new) jump:t unsigned + jump fail + } + + .globl unsigned +unsigned: + { + r0=#-2 + r1=#0 + } + { + p0 = cmp.gtu(r0, r1); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_cmpy.S new file +31 -0
@@ -0,0 +1,31 @@ +/* Purpose: test example, verify the soundness of the cmpy operation + * + * 3j+5 * 2j+4 = 22j+14 + * + * the complex multiply between 0x00030005 and 0x00020004 is 0x000000160000000e + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#196613 + r1=#131076 + } + { + r3:2=cmpy(r0, r1):sat + } + { + p0 = cmp.eq(r2, #14); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r3, #22); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_dotnew.S new file +36 -0
@@ -0,0 +1,36 @@ +/* Purpose: test the .new operator while performing memory stores. */ + .text + .globl _start + +_start: + { + call init + } + { + r0=#1 + memw(sp+#0)=r0.new + } + { + r1=#2 + memw(sp+#4)=r1.new + } + { + r2=#3 + memw(sp+#8)=r2.new + } + { + r0=memw(sp+#8) + } + { + r1=memw(sp+#4) + } + { + r2=memw(sp+#0) + } + { + r3=mpyi(r1,r2) + } + { + p0 = cmp.eq(r3, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_ext.S new file +16 -0
@@ -0,0 +1,16 @@ +/* Purpose: test immediate extender instructions. */ + + .text + .globl _start + +_start: + { + call init + } + { + r2=##-559038737 + } + { + p0 = cmp.eq(r2, ##-559038737); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_fibonacci.S new file +33 -0
@@ -0,0 +1,33 @@ +/* Purpose: computes the Fibonacci series up to a constant number. */ + + .text + .globl _start + +_start: + { + call init + } + { + r2=#100 + } + { + p0=cmp.gt(r2,#0); if (!p0.new) jump:nt .LBB0_3 + } + { + r3=#0 + r4=#1 + } +.LBB0_2: + { + r5=r4 + } + { + p0=cmp.gt(r2,r5); if (p0.new) jump:nt .LBB0_2 + r4=add(r3,r4) + r3=r5 + } +.LBB0_3: + { + p0 = cmp.eq(r3, #144); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_hl.S new file +19 -0
@@ -0,0 +1,19 @@ +/* Purpose: test example, verify the soundness of the high/low assignment */ + + .text + .globl _start + +_start: + { + call init + } + { + r0.H=#42 + } + { + r0.L=#69 + } + { + p0 = cmp.eq(r0, #2752581); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_hwloops.S new file +22 -0
@@ -0,0 +1,22 @@ +/* Purpose: simple C Program to test hardware loops. */ + + .text + .globl _start + +_start: + { + call init + } + { + 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 +25 -0
@@ -0,0 +1,25 @@ +/* Purpose: test example, verify the soundness of the add operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#0 + r2=#0 + } + { + r3=add(r1,r2) + } + { + p0 = cmp.eq(r3, #0) + } + { + if (p0) jump:t pass + } + { + jump fail + }
tests/tcg/hexagon/test_lsr.S new file +39 -0
@@ -0,0 +1,39 @@ +/* Purpose: test the soundness of the lsr operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#-56984 + r1=#2147483647 + } + { + r2=#0x19 + } + { + r0&=lsr(r1, r2) + } + { + p0 = cmp.eq(r0, #0x28); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r0=#0x0000000a + r1=#0x00000000 + } + { + r2=#-1 + } + { + r1:0=lsl(r1:0, r2) + } + { + p0 = cmp.eq(r0, #0x5); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_mpyi.S new file +20 -0
@@ -0,0 +1,20 @@ +/* Purpose: test a simple multiplication operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#4 + r2=#6 + } + { + r3=mpyi(r1,r2) + } + { + p0 = cmp.eq(r3, #24); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_overflow.S new file +63 -0
63 lines not on this page · raw message
tests/tcg/hexagon/test_packet.S new file +26 -0
@@ -0,0 +1,26 @@ +/* Purpose: test that writes of a register in a packet are performed only after + * that packet has finished its execution. + */ + + .text + .globl _start + +_start: + { + call init + } + { + r2=#4 + r3=#6 + } + { + memw(sp+#0)=r2 + } + { + r3=memw(sp+#0) + r0=add(r2,r3) + } + { + p0 = cmp.eq(r0, #10); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_reorder.S new file +29 -0
@@ -0,0 +1,29 @@ +/* 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: + { + call init + } + { r2=#-559038737 } + { r4=#1 } + { + if (p0.new) jump:nt skip + p0=r4; + } + +fallthrough: + { r2=#0 } + +skip: + { + p0 = cmp.eq(r2, #-559038737); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_round.S new file +31 -0
@@ -0,0 +1,31 @@ +/* Purpose: test example, verify the soundness of the cround operation + * 106 = 0b1101010 with the comma at third digit is 12.5 which is crounded to 12 + * but rounded to 13 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r1=#200 + } + { + r2=round(r1, #4) + } + { + p0 = cmp.eq(r2, #13); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + r2=cround(r1, #4) + } + { + p0 = cmp.eq(r2, #12); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vavgw.S new file +33 -0
@@ -0,0 +1,33 @@ +/* Purpose: test example, verify the soundness of the vavgw operation + * + * 0x00030001 averaged with 0x00010003 results 0x00020002 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#3 + r1=#1 + } + { + r2=#1 + r3=#3 + } + { + r1:0=vavgw(r1:0, r3:2):crnd + } + { + p0 = cmp.eq(r0, #2); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #2); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpb.S new file +32 -0
@@ -0,0 +1,32 @@ +/* Purpose: test example, verify the soundness of the vector compare bytes + * operation + * + * Vector word comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0x11110000 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#305419896 + r1=#-2023406815 + } + { + r2=#305419896 + r3=#0 + } + { + p2=vcmpb.eq(r1:0, r3:2) + } + { + r4=p2 + } + { + p0 = cmp.eq(r4, #15); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpw.S new file +29 -0
@@ -0,0 +1,29 @@ +/* Purpose: test example, verify the soundness of the vector compare words + * operation + * + * Vector word comparison between 0x1234567887654321 and 0x1234567800000000 + * should result in 0x11110000 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#305419896 + r1=#-2023406815 + } + { + r2=#305419896 + r3=#0 + } + { + p2=vcmpw.eq(r1:0, r3:2) + } + { + if (p2) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vcmpy.S new file +50 -0
50 lines not on this page · raw message
tests/tcg/hexagon/test_vlsrw.S new file +23 -0
@@ -0,0 +1,23 @@ +/* Purpose: test the soundness of the vlsrw operation */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#0x00000001 + r1=#0x00000001 + } + { + r1:0=vlsrw(r1:0, #1) + } + { + r0 = add(r0, r1) + } + { + p0 = cmp.eq(r0, #0); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vmaxh.S new file +37 -0
@@ -0,0 +1,37 @@ +/* Purpose: test example, verify the soundness of the vrmaxh operation + * + * the maximum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007. + * + * r1=0x00010003 r0=0x00010005 r3=0x00030002 r2=0x00020007 + * result: r1=0x00030003 r0=0x00020007 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#65541 + r1=#65539 + } + { + r2=#131079 + r3=#196610 + } + { + r1:0=vmaxh(r1:0, r3:2) + } + { + p0 = cmp.eq(r0, #131079); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #196611); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vminh.S new file +37 -0
@@ -0,0 +1,37 @@ +/* Purpose: test example, verify the soundness of the vrmaxh operation + * + * the minimum between 0x0002000300010005 and 0x0003000200020007 is + * 0x0003000300020007 + * + * r1=0x00010003 r0=0x00010005 r3=0x00030002 r2=0x00020007 + * result: r1=0x00010002 r0=0x00010005 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#65541 + r1=#65539 + } + { + r2=#131079 + r3=#196610 + } + { + r1:0=vminh(r1:0, r3:2) + } + { + p0 = cmp.eq(r0, #65541); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #65538); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vpmpyh.S new file +30 -0
@@ -0,0 +1,30 @@ +/* Purpose: test example, verify the soundness of the vpmpyh operator + * + * 0x01020304 vector polynomial multiplied with 0x04030201 results + * 0x000400060b060b04 + */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#16909060 + r1=#67305985 + } + { + r1:0=vpmpyh(r0, r1) + } + { + p0 = cmp.eq(r0, #184945412); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r1, #262150); if (p0.new) jump:t pass + jump fail + }
tests/tcg/hexagon/test_vspliceb.S new file +33 -0
@@ -0,0 +1,33 @@ +/* Purpose: test example, verify the soundness of the vspliceb operation + * the operation is a binary splice of two 64bit operators + * + * vspliceb(0xffffffffffffffff,0x0000000000000000,5) = 0x000000000000001f + */ + .text + .globl _start + +_start: + { + call init + } + { + r0=#-1 + r1=#-1 + } + { + r2=#0 + r3=#0 + } + { + r5:4=vspliceb(r1:0, r3:2, #5) + } + { + p0 = cmp.eq(r4, #-1); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r5, #255); if (p0.new) jump:t pass + jump fail + }
Signature · 1 line
2.33.1
RE: [PATCH v7 12/13] target/hexagon: import additional tests
Quoted 29 lines
-----Original Message-----
From: Anton Johansson <[email protected]>
Sent: Friday, December 17, 2021 2:01 AM
To: [email protected]
Cc: [email protected]; Taylor Simpson <[email protected]>; Brian Cain <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH v7 12/13] target/hexagon: import additional testsFrom: Niccolò Izzo <[email protected]>
Signed-off-by Alessandro Di Federico <[email protected]>Signed-off-by Niccolò Izzo <[email protected]>tests/tcg/hexagon/Makefile.target +0
-0@@ -24,7 +24,7 @@ CFLAGS += -fno-unroll-loopsHEX_SRC=$(SRC_PATH)/tests/tcg/hexagon
VPATH += $(HEX_SRC)tests/tcg/hexagon/Makefile.target +1
-1-first: $(HEX_SRC)/first.S +%: $(HEX_SRC)/%.S $(HEX_SRC)/crt.S $(CC) -static -mv67 -nostdlib $^ -o $@ HEX_TESTS = first
tests/tcg/hexagon/Makefile.target HEX_TESTS += atomics · line 48
Quoted 7 lines
tests/tcg/hexagon/Makefile.target +4
-0@@ -42,4 +42,32 @@ HEX_TESTS += atomics HEX_TESTS += fpstuff HEX_TESTS += overflow +HEX_TESTS += test_abs +HEX_TESTS += test_bitcnt +HEX_TESTS += test_bitsplit +HEX_TESTS += test_clobber
You forgot to add test_call to this list.
Quoted 13 lines
tests/tcg/hexagon/Makefile.target +2
-0+HEX_TESTS += test_cmp +HEX_TESTS += test_cmpytests/tcg/hexagon/test_call.S new file +4
-0@@ -0,0 +1,60 @@ +/* Purpose: test function calls and duplex instructions. + * The string "Hello there, I'm a test string!" with the first letter +replaced + * with a capital L should be printed out.
tests/tcg/hexagon/test_call.S line 14
Quoted 10 lines
tests/tcg/hexagon/test_call.S new file +10
-0+ */ + { + call write + } + { + jump pass + } + { + r31:30=deallocframe(r30):raw + }
The jump to pass will never return, so the deallocframe is unreachable.
tests/tcg/hexagon/test_call.S line 24
Quoted 10 lines
tests/tcg/hexagon/test_call.S new file +10
-0+.Lfunc_end1: +.Ltmp1: + .size _start, .Ltmp1-_start +write: + { + r0=##dummy_buffer + } + { + r1=#256 + }
Were you intending to make a system call here? If so, the sequence would be (see first.S for #define's)
r6 = #SYS_write r0 = #FD_STDOUT r1 = ##dummy_buffer r2 = #33 trap0(#1)
Quoted 22 lines
tests/tcg/hexagon/test_call.S new file +3
-0+ { + jumpr r31 + }(quoted diff) +0
-0
b/tests/tcg/hexagon/test_cmpy.Snew file mode 100644 index 0000000000..0b3dfb95detests/tcg/hexagon/test_cmpy.S new file +11
-0@@ -0,0 +1,31 @@ +/* Purpose: test example, verify the soundness of the cmpy operation + * + * 3j+5 * 2j+4 = 22j+14 + * + * the complex multiply between 0x00030005 and 0x00020004 is +0x000000160000000e */ + + .text + .globl _start + +_start:
tests/tcg/hexagon/test_cmpy.S line 21
Quoted 10 lines
tests/tcg/hexagon/test_cmpy.S new file +10
-0+ { + call init + } + { + r0=#196613 + r1=#131076 + } + { + r3:2=cmpy(r0, r1):sat + }
You should also check the overflow bit in USR from the :sat.
Also, have one set of inputs that overflows and one that doesn't in order to verify the proper USR behavior.
Quoted 18 lines
tests/tcg/hexagon/test_cmpy.S new file +10
-0+ { + p0 = cmp.eq(r2, #14); if (p0.new) jump:t test2 + jump fail + } + +test2: + { + p0 = cmp.eq(r3, #22); if (p0.new) jump:t pass + jump fail + }(quoted diff) +0
-0
b/tests/tcg/hexagon/test_dotnew.Snew file mode 100644 index 0000000000..70886d9483tests/tcg/hexagon/test_dotnew.S new file +2
-0@@ -0,0 +1,36 @@ +/* Purpose: test the .new operator while performing memory stores. */ + .text
tests/tcg/hexagon/test_dotnew.S line 12
Quoted 10 lines
tests/tcg/hexagon/test_dotnew.S new file +10
-0+ .globl _start + +_start: + { + call init + } + { + r0=#1 + memw(sp+#0)=r0.new + }
You should allocframe before writing to the stack.
tests/tcg/hexagon/test_jmp.S line 1
Quoted 6 lines
tests/tcg/hexagon/test_jmp.S new file +1
-0@@ -0,0 +1,25 @@ +/* Purpose: test example, verify the soundness of the add operation */
This test is named test_jmp.S, but you are testing add?
tests/tcg/hexagon/test_overflow.S new file +15 -0
@@ -0,0 +1,63 @@ +// Purpose: test example, verify the soundness of the overflow bit // +// a right shift with negative amount should make r0 saturate, setting +the // overflow bit + + .text + .globl _start + +_start: + { + call init + } + { + r0=#0x10000000 + r1=#-2 + }
You should clear bit 0 in USR before doing the asr(r0,r1):sat.
Also, do this for the other places in this review that mention USR.
+ {
+ r2=asr(r0, r1):sat
+ }
+ {
+ r4=USR
+ }
+ {
+ r5=and(r4,#1)
+ }
Quoted 15 lines
(quoted diff) +0
-0
b/tests/tcg/hexagon/test_packet.Snew file mode 100644 index 0000000000..d26e284be9tests/tcg/hexagon/test_packet.S new file +9
-0@@ -0,0 +1,26 @@ +/* Purpose: test that writes of a register in a packet are performed +only after + * that packet has finished its execution. + */ + + .text + .globl _start + +_start:
tests/tcg/hexagon/test_packet.S line 19
Quoted 10 lines
tests/tcg/hexagon/test_packet.S new file +10
-0+ { + call init + } + { + r2=#4 + r3=#6 + } + { + memw(sp+#0)=r2 + }
Need allocframe first
tests/tcg/hexagon/test_packet.S
Quoted 8 lines
tests/tcg/hexagon/test_packet.S new file +8
-0+ { + r3=memw(sp+#0) + r0=add(r2,r3) + } + { + p0 = cmp.eq(r0, #10); if (p0.new) jump:t pass + jump fail + }
Also check that r3 == 4
tests/tcg/hexagon/test_vcmpb.S line 7
Quoted 13 lines
(quoted diff) +0
-0
b/tests/tcg/hexagon/test_vcmpb.Snew file mode 100644 index 0000000000..3c6700a63atests/tcg/hexagon/test_vcmpb.S new file +7
-0@@ -0,0 +1,32 @@ +/* Purpose: test example, verify the soundness of the vector compare +bytes + * operation + * + * Vector word comparison between 0x1234567887654321 and +0x1234567800000000 + * should result in 0x11110000
Comment is incorrect - should be Vector byte comparison.
tests/tcg/hexagon/test_vcmpw.S line 7
Quoted 13 lines
(quoted diff) +0
-0
b/tests/tcg/hexagon/test_vcmpw.Snew file mode 100644 index 0000000000..112f08c92ftests/tcg/hexagon/test_vcmpw.S new file +7
-0@@ -0,0 +1,29 @@ +/* Purpose: test example, verify the soundness of the vector compare +words + * operation + * + * Vector word comparison between 0x1234567887654321 and +0x1234567800000000 + * should result in 0x11110000
That's the expected result in binary, not hex.
Quoted 12 lines
tests/tcg/hexagon/test_vcmpw.S new file +12
-0+ */ + + .text + .globl _start + +_start: + { + call init + } + { + r0=#305419896 + r1=#-2023406815
tests/tcg/hexagon/test_vcmpw.S line 29
Quoted 10 lines
tests/tcg/hexagon/test_vcmpw.S new file +10
-0+ } + { + r2=#305419896 + r3=#0 + } + { + p2=vcmpw.eq(r1:0, r3:2) + } + { + if (p2) jump:t pass
Check for the actual expected value, not just LSB.
Also, this doesn't match the comment above. You're actually comparing
0x8765432112345678
0x0000000012345678So, p2 will have 0xf, not 0xf0.
In other words, the assignments to r0/r1 and r2/r3 are swapped.
Go ahead and swap them and check that p2 gets 0xf0.
tests/tcg/hexagon/test_vcmpy.S
Quoted 9 lines
(quoted diff) +0
-0
b/tests/tcg/hexagon/test_vcmpy.Snew file mode 100644 index 0000000000..df379f9186tests/tcg/hexagon/test_vcmpy.S new file +4
-0+ { + r5:4=vcmpyr(r1:0, r3:2):sat + r7:6=vcmpyi(r1:0, r3:2):sat + }
Create some inputs that will saturate and check for overflow in USR.
tests/tcg/hexagon/test_vspliceb.S line 6
Quoted 13 lines
tests/tcg/hexagon/test_vspliceb.S new file +6
-0@@ -0,0 +1,33 @@ +/* Purpose: test example, verify the soundness of the vspliceb +operation + * the operation is a binary splice of two 64bit operators + * + * vspliceb(0xffffffffffffffff,0x0000000000000000,5) = +0x000000000000001f */
The comment is incorrect. The result is 0x000000ffffffffff.
The test is correct, though.
PATCH v7 13/13 gitlab-ci: do not use qemu-project Docker registry
In reply to Anton Johansson viaFrom: Alessandro Di Federico <[email protected]>
This commit is necessary in order to use container built by the current run of the CI. If we don't do this, we use official containers which are not affected by the additional dependencies we're introducing.
This should be considered as a temporary solution in order to test this patchset.
--- .gitlab-ci.d/container-cross.yml | 2 +- .gitlab-ci.d/container-template.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
.gitlab-ci.d/container-cross.yml +1 -1
@@ -63,7 +63,7 @@ hexagon-cross-container: - docker:dind before_script: - export TAG="$CI_REGISTRY_IMAGE/qemu/$NAME:latest" - - export COMMON_TAG="$CI_REGISTRY/qemu-project/qemu/qemu/$NAME:latest" + - export COMMON_TAG="$CI_REGISTRY_IMAGE/qemu/$NAME:latest" - docker info - docker login $CI_REGISTRY -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" script:
.gitlab-ci.d/container-template.yml +2 -2
@@ -5,7 +5,7 @@ - docker:dind before_script: - export TAG="$CI_REGISTRY_IMAGE/qemu/$NAME:latest" - - export COMMON_TAG="$CI_REGISTRY/qemu-project/qemu/$NAME:latest" + - export COMMON_TAG="$CI_REGISTRY_IMAGE/qemu/$NAME:latest" - apk add python3 - docker info - docker login $CI_REGISTRY -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
@@ -14,7 +14,7 @@ - echo "COMMON_TAG:$COMMON_TAG" - ./tests/docker/docker.py --engine docker build -t "qemu/$NAME" -f "tests/docker/dockerfiles/$NAME.docker" - -r $CI_REGISTRY/qemu-project/qemu + -r $CI_REGISTRY_IMAGE - docker tag "qemu/$NAME" "$TAG" - docker push "$TAG" after_script:
Signature · 1 line
2.33.1