diff --git a/CMakeLists.txt b/CMakeLists.txt index b8dd450..2a46f47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,6 @@ set(LIB_SOURCES src/iss/arch/tgc5c.cpp src/vm/interp/vm_tgc5c.cpp src/vm/fp_functions.cpp - src/vm/instruction_decoder.cpp src/iss/semihosting/semihosting.cpp ) diff --git a/gen_input/templates/asmjit/CORENAME.cpp.gtl b/gen_input/templates/asmjit/CORENAME.cpp.gtl index 97ed953..245727b 100644 --- a/gen_input/templates/asmjit/CORENAME.cpp.gtl +++ b/gen_input/templates/asmjit/CORENAME.cpp.gtl @@ -37,7 +37,7 @@ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY diff --git a/gen_input/templates/interp/CORENAME.cpp.gtl b/gen_input/templates/interp/CORENAME.cpp.gtl index 43968bf..6804f57 100644 --- a/gen_input/templates/interp/CORENAME.cpp.gtl +++ b/gen_input/templates/interp/CORENAME.cpp.gtl @@ -48,7 +48,7 @@ def nativeTypeSize(int size){ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY diff --git a/gen_input/templates/llvm/CORENAME.cpp.gtl b/gen_input/templates/llvm/CORENAME.cpp.gtl index 517253a..a98b832 100644 --- a/gen_input/templates/llvm/CORENAME.cpp.gtl +++ b/gen_input/templates/llvm/CORENAME.cpp.gtl @@ -36,7 +36,7 @@ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY diff --git a/gen_input/templates/tcc/CORENAME.cpp.gtl b/gen_input/templates/tcc/CORENAME.cpp.gtl index 6f688df..e6250e4 100644 --- a/gen_input/templates/tcc/CORENAME.cpp.gtl +++ b/gen_input/templates/tcc/CORENAME.cpp.gtl @@ -37,7 +37,7 @@ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY diff --git a/src/vm/asmjit/vm_tgc5c.cpp b/src/vm/asmjit/vm_tgc5c.cpp index fe0215c..7f0729a 100644 --- a/src/vm/asmjit/vm_tgc5c.cpp +++ b/src/vm/asmjit/vm_tgc5c.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY diff --git a/src/vm/instruction_decoder.cpp b/src/vm/instruction_decoder.cpp deleted file mode 100644 index 34fbe8a..0000000 --- a/src/vm/instruction_decoder.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 MINRES Technologies GmbH - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * alex@minres.com - initial implementation - ******************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -decoder::decoder(std::vector instr_list) { - for(auto instr : instr_list) { - root.instrs.push_back(instr); - } - populate_decoding_tree(root); -} - -void decoder::populate_decoding_tree(decoding_tree_node& parent) { - // create submask - parent.submask = - std::accumulate(parent.instrs.begin(), parent.instrs.end(), std::numeric_limits::max(), - [](int current_submask, const generic_instruction_descriptor& instr) { return current_submask & instr.mask; }); - // put each instr according to submask&encoding into children - for(auto instr : parent.instrs) { - bool foundMatch = false; - for(auto& child : parent.children) { - // use value as identifying trait - if(child.value == (instr.value & parent.submask)) { - child.instrs.push_back(instr); - foundMatch = true; - } - } - if(!foundMatch) { - decoding_tree_node child = decoding_tree_node(instr.value & parent.submask); - child.instrs.push_back(instr); - parent.children.push_back(child); - } - } - parent.instrs.clear(); - // call populate_decoding_tree for all children - if(parent.children.size() > 1) - for(auto& child : parent.children) { - populate_decoding_tree(child); - } - else { - // sort instrs by value of the mask, so we have the least restrictive mask last - std::sort(parent.children[0].instrs.begin(), parent.children[0].instrs.end(), - [](const generic_instruction_descriptor& instr1, const generic_instruction_descriptor& instr2) { - return instr1.mask > instr2.mask; - }); - } -} -uint32_t decoder::decode_instr(uint32_t word) { return _decode_instr(this->root, word); } -uint32_t decoder::_decode_instr(decoding_tree_node const& node, uint32_t word) { - if(!node.instrs.empty()) { - for(auto& instr : node.instrs) { - if((instr.mask & word) == instr.value) - return instr.index; - } - } else if(!node.children.empty()) { - for(auto& child : node.children) { - if(child.value == (node.submask & word)) { - return _decode_instr(child, word); - } - } - } - return std::numeric_limits::max(); -} diff --git a/src/vm/instruction_decoder.h b/src/vm/instruction_decoder.h deleted file mode 100644 index c1e8aac..0000000 --- a/src/vm/instruction_decoder.h +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2024 MINRES Technologies GmbH - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * Contributors: - * alex@minres.com - initial implementation - ******************************************************************************/ - -#include -#include -#include -#include - -struct generic_instruction_descriptor { - uint32_t value; - uint32_t mask; - uint32_t index; -}; - -struct decoding_tree_node { - std::vector instrs; - std::vector children; - uint32_t submask = std::numeric_limits::max(); - uint32_t value; - decoding_tree_node(uint32_t value) - : value(value) {} -}; -class decoder { -public: - decoder(std::vector instr_list); - uint32_t decode_instr(uint32_t word); - -private: - decoding_tree_node root{decoding_tree_node(std::numeric_limits::max())}; - void populate_decoding_tree(decoding_tree_node& root); - uint32_t _decode_instr(decoding_tree_node const& node, uint32_t word); -}; \ No newline at end of file diff --git a/src/vm/interp/vm_tgc5c.cpp b/src/vm/interp/vm_tgc5c.cpp index aa930ff..1c1d410 100644 --- a/src/vm/interp/vm_tgc5c.cpp +++ b/src/vm/interp/vm_tgc5c.cpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY diff --git a/src/vm/llvm/vm_tgc5c.cpp b/src/vm/llvm/vm_tgc5c.cpp index c5cd06f..6f098c0 100644 --- a/src/vm/llvm/vm_tgc5c.cpp +++ b/src/vm/llvm/vm_tgc5c.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY diff --git a/src/vm/tcc/vm_tgc5c.cpp b/src/vm/tcc/vm_tgc5c.cpp index 1969679..2aa5ab6 100644 --- a/src/vm/tcc/vm_tgc5c.cpp +++ b/src/vm/tcc/vm_tgc5c.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #ifndef FMT_HEADER_ONLY #define FMT_HEADER_ONLY