From b5341700aa1101ce4aedd80ac1a68b6ee65b83c7 Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Tue, 13 Aug 2024 08:55:14 +0200 Subject: [PATCH] updates template and adds braces when using conditions --- gen_input/templates/asmjit/CORENAME.cpp.gtl | 13 ++++++-- src/vm/asmjit/vm_tgc5c.cpp | 33 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/gen_input/templates/asmjit/CORENAME.cpp.gtl b/gen_input/templates/asmjit/CORENAME.cpp.gtl index 87ab923..ad21cb8 100644 --- a/gen_input/templates/asmjit/CORENAME.cpp.gtl +++ b/gen_input/templates/asmjit/CORENAME.cpp.gtl @@ -38,7 +38,9 @@ #include #include #include - +<%def fcsr = registers.find {it.name=='FCSR'} +if(fcsr != null) {%> +#include <%}%> #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY #endif @@ -100,7 +102,9 @@ protected: void gen_block_prologue(jit_holder& jh) override; void gen_block_epilogue(jit_holder& jh) override; inline const char *name(size_t index){return traits::reg_aliases.at(index);} - +<%if(fcsr != null) {%> + inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";} +<%}%> void gen_instr_prologue(jit_holder& jh); void gen_instr_epilogue(jit_holder& jh); inline void gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t cause); @@ -112,7 +116,10 @@ protected: auto mask = (1ULL< + ${it}<%}%> +<%}%> private: /**************************************************************************** * start opcode definitions diff --git a/src/vm/asmjit/vm_tgc5c.cpp b/src/vm/asmjit/vm_tgc5c.cpp index eb13809..7f394d8 100644 --- a/src/vm/asmjit/vm_tgc5c.cpp +++ b/src/vm/asmjit/vm_tgc5c.cpp @@ -112,7 +112,8 @@ protected: auto mask = (1ULL<(imm)) ), addr_mask) ), 32, true); + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, urem, new_pc, static_cast(traits::INSTR_ALIGNMENT)) ,0); @@ -521,6 +523,7 @@ private: mov(cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast(UNKNOWN_JUMP)); } cc.bind(label_merge); + } } auto returnValue = BRANCH; @@ -566,6 +569,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) ,0); @@ -583,6 +587,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = BRANCH; @@ -628,6 +633,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) ,0); @@ -645,6 +651,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = BRANCH; @@ -690,6 +697,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, lt, gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs1), 32, false), gen_ext(cc, @@ -709,6 +717,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = BRANCH; @@ -754,6 +763,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, gte, gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs1), 32, false), gen_ext(cc, @@ -773,6 +783,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = BRANCH; @@ -818,6 +829,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, ltu, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) ,0); @@ -835,6 +847,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = BRANCH; @@ -880,6 +893,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, gteu, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) ,0); @@ -897,6 +911,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = BRANCH; @@ -3116,6 +3131,7 @@ private: auto divisor = gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs2), 32, true); if(rd!=0){ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, ne, divisor, 0) ,0); @@ -3123,6 +3139,7 @@ private: cc.je(label_else); { auto MMIN = ((uint32_t)1)<<(static_cast(traits::XLEN)-1); + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, land, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), MMIN) , gen_operation(cc, eq, divisor, - 1) @@ -3143,6 +3160,7 @@ private: ), 32, true)); } cc.bind(label_merge); + } } cc.jmp(label_merge); cc.bind(label_else); @@ -3151,6 +3169,7 @@ private: (uint32_t)- 1); } cc.bind(label_merge); + } } } auto returnValue = CONT; @@ -3196,6 +3215,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0) ,0); @@ -3217,6 +3237,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = CONT; @@ -3261,6 +3282,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0) ,0); @@ -3268,6 +3290,7 @@ private: cc.je(label_else); { auto MMIN = (uint32_t)1<<(static_cast(traits::XLEN)-1); + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, land, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), MMIN) , gen_operation(cc, eq, gen_ext(cc, @@ -3296,6 +3319,7 @@ private: } } cc.bind(label_merge); + } } cc.jmp(label_merge); cc.bind(label_else); @@ -3306,6 +3330,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = CONT; @@ -3350,6 +3375,7 @@ private: gen_raise(jh, 0, static_cast(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); } else{ + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0) ,0); @@ -3371,6 +3397,7 @@ private: } } cc.bind(label_merge); + } } auto returnValue = CONT; @@ -4194,6 +4221,7 @@ private: cc.comment("//behavior:"); /*generate behavior*/ mov(jh.cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast(NO_JUMP)); + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1+8), 0) ,0); @@ -4204,6 +4232,7 @@ private: mov(cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast(KNOWN_JUMP)); } cc.bind(label_merge); + } auto returnValue = BRANCH; gen_sync(jh, POST_SYNC, 75); @@ -4243,6 +4272,7 @@ private: cc.comment("//behavior:"); /*generate behavior*/ mov(jh.cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast(NO_JUMP)); + { auto label_merge = cc.newLabel(); cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs1+8), 0) ,0); @@ -4253,6 +4283,7 @@ private: mov(cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast(KNOWN_JUMP)); } cc.bind(label_merge); + } auto returnValue = BRANCH; gen_sync(jh, POST_SYNC, 76);