From fbca690b3b48e9fdaf4cce8e0793b65529ca69de Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Thu, 8 Aug 2024 12:57:08 +0200 Subject: [PATCH] replaces gen_wait, updates template to include fp_functions when necessary --- gen_input/templates/tcc/CORENAME.cpp.gtl | 41 ++++++++++++++++++++---- src/vm/tcc/vm_tgc5c.cpp | 8 ++--- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/gen_input/templates/tcc/CORENAME.cpp.gtl b/gen_input/templates/tcc/CORENAME.cpp.gtl index e01d400..c215a03 100644 --- a/gen_input/templates/tcc/CORENAME.cpp.gtl +++ b/gen_input/templates/tcc/CORENAME.cpp.gtl @@ -88,7 +88,9 @@ protected: <% def fcsr = registers.find {it.name=='FCSR'} if(fcsr != null) {%> - inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";} + inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";} + + void add_prologue(tu_builder& tu) override; <%}%> void setup_module(std::string m) override { super::setup_module(m); @@ -102,8 +104,6 @@ if(fcsr != null) {%> void gen_leave_trap(tu_builder& tu, unsigned lvl); - void gen_wait(tu_builder& tu, unsigned type); - inline void gen_set_tval(tu_builder& tu, uint64_t new_tval); inline void gen_set_tval(tu_builder& tu, value new_tval); @@ -266,9 +266,6 @@ template void vm_impl::gen_leave_trap(tu_builder& tu, unsi tu.store(traits::LAST_BRANCH, tu.constant(static_cast(UNKNOWN_JUMP), 32)); } -template void vm_impl::gen_wait(tu_builder& tu, unsigned type) { -} - template void vm_impl::gen_set_tval(tu_builder& tu, uint64_t new_tval) { tu(fmt::format("tval = {};", new_tval)); } @@ -283,6 +280,38 @@ template void vm_impl::gen_trap_behavior(tu_builder& tu) { tu.store(traits::LAST_BRANCH, tu.constant(static_cast(UNKNOWN_JUMP),32)); tu("return *next_pc;"); } +<% +if(fcsr != null) {%> +template void vm_impl::add_prologue(tu_builder& tu){ + std::ostringstream os; + os << "uint32_t (*fadd_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fadd_s << ";\\n"; + os << "uint32_t (*fsub_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fsub_s << ";\\n"; + os << "uint32_t (*fmul_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fmul_s << ";\\n"; + os << "uint32_t (*fdiv_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fdiv_s << ";\\n"; + os << "uint32_t (*fsqrt_s)(uint32_t v1, uint8_t mode)=" << (uintptr_t)&fsqrt_s << ";\\n"; + os << "uint32_t (*fcmp_s)(uint32_t v1, uint32_t v2, uint32_t op)=" << (uintptr_t)&fcmp_s << ";\\n"; + os << "uint32_t (*fcvt_s)(uint32_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_s << ";\\n"; + os << "uint32_t (*fmadd_s)(uint32_t v1, uint32_t v2, uint32_t v3, uint32_t op, uint8_t mode)=" << (uintptr_t)&fmadd_s << ";\\n"; + os << "uint32_t (*fsel_s)(uint32_t v1, uint32_t v2, uint32_t op)=" << (uintptr_t)&fsel_s << ";\\n"; + os << "uint32_t (*fclass_s)( uint32_t v1 )=" << (uintptr_t)&fclass_s << ";\\n"; + os << "uint32_t (*fconv_d2f)(uint64_t v1, uint8_t mode)=" << (uintptr_t)&fconv_d2f << ";\\n"; + os << "uint64_t (*fconv_f2d)(uint32_t v1, uint8_t mode)=" << (uintptr_t)&fconv_f2d << ";\\n"; + os << "uint64_t (*fadd_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fadd_d << ";\\n"; + os << "uint64_t (*fsub_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fsub_d << ";\\n"; + os << "uint64_t (*fmul_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fmul_d << ";\\n"; + os << "uint64_t (*fdiv_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fdiv_d << ";\\n"; + os << "uint64_t (*fsqrt_d)(uint64_t v1, uint8_t mode)=" << (uintptr_t)&fsqrt_d << ";\\n"; + os << "uint64_t (*fcmp_d)(uint64_t v1, uint64_t v2, uint32_t op)=" << (uintptr_t)&fcmp_d << ";\\n"; + os << "uint64_t (*fcvt_d)(uint64_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_d << ";\\n"; + os << "uint64_t (*fmadd_d)(uint64_t v1, uint64_t v2, uint64_t v3, uint32_t op, uint8_t mode)=" << (uintptr_t)&fmadd_d << ";\\n"; + os << "uint64_t (*fsel_d)(uint64_t v1, uint64_t v2, uint32_t op)=" << (uintptr_t)&fsel_d << ";\\n"; + os << "uint64_t (*fclass_d)(uint64_t v1 )=" << (uintptr_t)&fclass_d << ";\\n"; + os << "uint64_t (*fcvt_32_64)(uint32_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_32_64 << ";\\n"; + os << "uint32_t (*fcvt_64_32)(uint64_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_64_32 << ";\\n"; + os << "uint32_t (*unbox_s)(uint64_t v)=" << (uintptr_t)&unbox_s << ";\\n"; + tu.add_prologue(os.str()); +} +<%}%> } // namespace ${coreDef.name.toLowerCase()} diff --git a/src/vm/tcc/vm_tgc5c.cpp b/src/vm/tcc/vm_tgc5c.cpp index 79b937e..23daf58 100644 --- a/src/vm/tcc/vm_tgc5c.cpp +++ b/src/vm/tcc/vm_tgc5c.cpp @@ -98,8 +98,6 @@ protected: void gen_leave_trap(tu_builder& tu, unsigned lvl); - void gen_wait(tu_builder& tu, unsigned type); - inline void gen_set_tval(tu_builder& tu, uint64_t new_tval); inline void gen_set_tval(tu_builder& tu, value new_tval); @@ -1941,7 +1939,7 @@ private: gen_set_pc(tu, pc, traits::NEXT_PC); tu.open_scope(); this->gen_set_tval(tu, instr); - this->gen_wait(tu, 1); + tu.callf("wait", tu.constant(1,8)); auto returnValue = std::make_tuple(CONT); tu.close_scope(); @@ -3648,9 +3646,6 @@ template void vm_impl::gen_leave_trap(tu_builder& tu, unsi tu.store(traits::LAST_BRANCH, tu.constant(static_cast(UNKNOWN_JUMP), 32)); } -template void vm_impl::gen_wait(tu_builder& tu, unsigned type) { -} - template void vm_impl::gen_set_tval(tu_builder& tu, uint64_t new_tval) { tu(fmt::format("tval = {};", new_tval)); } @@ -3666,6 +3661,7 @@ template void vm_impl::gen_trap_behavior(tu_builder& tu) { tu("return *next_pc;"); } + } // namespace tgc5c template <>