diff --git a/core/inst_handlers/inst_helpers.hpp b/core/inst_handlers/inst_helpers.hpp index 734bda6..de89af0 100644 --- a/core/inst_handlers/inst_helpers.hpp +++ b/core/inst_handlers/inst_helpers.hpp @@ -6,35 +6,23 @@ typedef int64_t sreg_t; typedef uint64_t reg_t; #define xlen 64 -template -inline sreg_t sext32(T x) { - return (sreg_t)(int32_t)(x); -} +template inline sreg_t sext32(T x) { return (sreg_t)(int32_t)(x); } -template -inline reg_t zext32(T x) { - return (reg_t)(uint32_t)(x); -} +template inline reg_t zext32(T x) { return (reg_t)(uint32_t)(x); } -template -inline sreg_t sext(T x, uint32_t pos) { +template inline sreg_t sext(T x, uint32_t pos) +{ return (((sreg_t)(x) << (64 - (pos))) >> (64 - (pos))); } -template -inline reg_t zext(T x, uint32_t pos) { +template inline reg_t zext(T x, uint32_t pos) +{ return (((reg_t)(x) << (64 - (pos))) >> (64 - (pos))); } -template -inline sreg_t sext_xlen(T x) { - return sext(x, xlen); -} +template inline sreg_t sext_xlen(T x) { return sext(x, xlen); } -template -inline reg_t zext_xlen(T x) { - return zext(x, xlen); -} +template inline reg_t zext_xlen(T x) { return zext(x, xlen); } inline uint64_t mulhu(uint64_t a, uint64_t b) { @@ -43,13 +31,13 @@ inline uint64_t mulhu(uint64_t a, uint64_t b) uint64_t a0 = (uint32_t)a, a1 = a >> 32; uint64_t b0 = (uint32_t)b, b1 = b >> 32; - t = a1*b0 + ((a0*b0) >> 32); + t = a1 * b0 + ((a0 * b0) >> 32); y1 = t; y2 = t >> 32; - t = a0*b1 + y1; + t = a0 * b1 + y1; - t = a1*b1 + y2 + (t >> 32); + t = a1 * b1 + y2 + (t >> 32); y2 = t; y3 = t >> 32; diff --git a/core/inst_handlers/rv64/a/RvaInsts.cpp b/core/inst_handlers/rv64/a/RvaInsts.cpp index 70f6076..a04fb9d 100644 --- a/core/inst_handlers/rv64/a/RvaInsts.cpp +++ b/core/inst_handlers/rv64/a/RvaInsts.cpp @@ -1,6 +1,7 @@ #include "core/inst_handlers/rv64/a/RvaInsts.hpp" #include "include/ActionTags.hpp" #include "core/ActionGroup.hpp" + namespace atlas { void RvaInsts::getInstComputeAddressHandlers(std::map & inst_handlers) @@ -165,8 +166,6 @@ namespace atlas nullptr, "sc_w", ActionTags::EXECUTE_TAG)); } - - ActionGroup* RvaInsts::amoadd_w_64_compute_address_handler(atlas::AtlasState* state) { (void)state; diff --git a/core/inst_handlers/rv64/d/RvdInsts.cpp b/core/inst_handlers/rv64/d/RvdInsts.cpp index 71220df..d9a784f 100644 --- a/core/inst_handlers/rv64/d/RvdInsts.cpp +++ b/core/inst_handlers/rv64/d/RvdInsts.cpp @@ -1,6 +1,7 @@ #include "core/inst_handlers/rv64/d/RvdInsts.hpp" #include "include/ActionTags.hpp" #include "core/ActionGroup.hpp" + namespace atlas { void RvdInsts::getInstComputeAddressHandlers(std::map & inst_handlers) @@ -131,8 +132,6 @@ namespace atlas nullptr, "fsw", ActionTags::EXECUTE_TAG)); } - - ActionGroup* RvdInsts::fcvt_d_w_64_handler(atlas::AtlasState* state) { (void)state; diff --git a/core/inst_handlers/rv64/f/RvfInsts.cpp b/core/inst_handlers/rv64/f/RvfInsts.cpp index 55de365..b58794e 100644 --- a/core/inst_handlers/rv64/f/RvfInsts.cpp +++ b/core/inst_handlers/rv64/f/RvfInsts.cpp @@ -1,6 +1,7 @@ #include "core/inst_handlers/rv64/f/RvfInsts.hpp" #include "include/ActionTags.hpp" #include "core/ActionGroup.hpp" + namespace atlas { void RvfInsts::getInstComputeAddressHandlers(std::map & inst_handlers) @@ -107,8 +108,6 @@ namespace atlas nullptr, "fsw", ActionTags::EXECUTE_TAG)); } - - ActionGroup* RvfInsts::fsqrt_s_64_handler(atlas::AtlasState* state) { (void)state; diff --git a/core/inst_handlers/rv64/i/RviInsts.cpp b/core/inst_handlers/rv64/i/RviInsts.cpp index 40481c1..0253519 100644 --- a/core/inst_handlers/rv64/i/RviInsts.cpp +++ b/core/inst_handlers/rv64/i/RviInsts.cpp @@ -4,6 +4,7 @@ #include "core/ActionGroup.hpp" #include "core/AtlasState.hpp" #include "core/AtlasInst.hpp" + namespace atlas { void RviInsts::getInstComputeAddressHandlers(std::map & inst_handlers) @@ -229,8 +230,6 @@ namespace atlas nullptr, "xori", ActionTags::EXECUTE_TAG)); } - - ActionGroup* RviInsts::cflush_i_l1_64_handler(atlas::AtlasState* state) { (void)state; diff --git a/core/inst_handlers/rv64/m/RvmInsts.cpp b/core/inst_handlers/rv64/m/RvmInsts.cpp index 677db9c..eea6cad 100644 --- a/core/inst_handlers/rv64/m/RvmInsts.cpp +++ b/core/inst_handlers/rv64/m/RvmInsts.cpp @@ -59,11 +59,16 @@ namespace atlas sreg_t lhs = sext_xlen(rs1_val); sreg_t rhs = sext_xlen(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(UINT64_MAX); - } else if (lhs == INT64_MIN && rhs == -1) { + } + else if (lhs == INT64_MIN && rhs == -1) + { insn->getRd()->write(lhs); - } else { + } + else + { insn->getRd()->write(sext_xlen(lhs / rhs)); } @@ -78,13 +83,16 @@ namespace atlas reg_t lhs = zext_xlen(rs1_val); reg_t rhs = zext_xlen(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(UINT64_MAX); - } else { + } + else + { insn->getRd()->write(sext_xlen(lhs / rhs)); } - return nullptr; + return nullptr; } ActionGroup* RvmInsts::divuw_64_handler(atlas::AtlasState* state) @@ -95,9 +103,12 @@ namespace atlas reg_t lhs = zext32(rs1_val); reg_t rhs = zext32(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(UINT64_MAX); - } else { + } + else + { insn->getRd()->write(sext32(lhs / rhs)); } @@ -112,9 +123,12 @@ namespace atlas sreg_t lhs = sext32(rs1_val); sreg_t rhs = sext32(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(UINT64_MAX); - } else { + } + else + { insn->getRd()->write(sext32(lhs / rhs)); } @@ -139,9 +153,12 @@ namespace atlas const uint64_t rs1_val = insn->getRs1()->read(); const uint64_t rs2_val = insn->getRs2()->read(); - if (xlen == 64) { + if (xlen == 64) + { insn->getRd()->write(mulh(rs1_val, rs2_val)); - } else { + } + else + { insn->getRd()->write(sext32((sext32(rs1_val) * sext32(rs2_val)) >> 32)); } @@ -154,9 +171,12 @@ namespace atlas const uint64_t rs1_val = insn->getRs1()->read(); const uint64_t rs2_val = insn->getRs2()->read(); - if (xlen == 64) { + if (xlen == 64) + { insn->getRd()->write(mulhsu(rs1_val, rs2_val)); - } else { + } + else + { insn->getRd()->write(sext32((sext32(rs1_val) * reg_t((uint32_t)rs2_val)) >> 32)); } @@ -165,17 +185,21 @@ namespace atlas ActionGroup* RvmInsts::mulhu_64_handler(atlas::AtlasState* state) { - const AtlasInstPtr & insn = state->getCurrentInst(); + const AtlasInstPtr & insn = state->getCurrentInst(); const uint64_t rs1_val = insn->getRs1()->read(); const uint64_t rs2_val = insn->getRs2()->read(); - if (xlen == 64) { + if (xlen == 64) + { insn->getRd()->write(mulhu(rs1_val, rs2_val)); - } else { - insn->getRd()->write(sext32(((uint64_t)(uint32_t)rs1_val * (uint64_t)(uint32_t)rs2_val) >> 32)); + } + else + { + insn->getRd()->write( + sext32(((uint64_t)(uint32_t)rs1_val * (uint64_t)(uint32_t)rs2_val) >> 32)); } - return nullptr; + return nullptr; } ActionGroup* RvmInsts::mulw_64_handler(atlas::AtlasState* state) @@ -198,11 +222,16 @@ namespace atlas sreg_t lhs = sext_xlen(rs1_val); sreg_t rhs = sext_xlen(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(lhs); - } else if (lhs == INT64_MIN && rhs == -1) { + } + else if (lhs == INT64_MIN && rhs == -1) + { insn->getRd()->write(0); - } else { + } + else + { insn->getRd()->write(sext_xlen(lhs % rhs)); } @@ -217,9 +246,12 @@ namespace atlas reg_t lhs = zext_xlen(rs1_val); reg_t rhs = zext_xlen(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(sext_xlen(lhs)); - } else { + } + else + { insn->getRd()->write(sext_xlen(lhs % rhs)); } @@ -234,9 +266,12 @@ namespace atlas reg_t lhs = zext32(rs1_val); reg_t rhs = zext32(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(sext32(lhs)); - } else { + } + else + { insn->getRd()->write(sext32(lhs % rhs)); } @@ -251,12 +286,15 @@ namespace atlas sreg_t lhs = sext32(rs1_val); sreg_t rhs = sext32(rs2_val); - if (rhs == 0) { + if (rhs == 0) + { insn->getRd()->write(lhs); - } else { + } + else + { insn->getRd()->write(sext32(lhs % rhs)); } - return nullptr; + return nullptr; } } // namespace atlas diff --git a/core/inst_handlers/rv64/zicsr/RvzicsrInsts.cpp b/core/inst_handlers/rv64/zicsr/RvzicsrInsts.cpp index 78bc638..4837825 100644 --- a/core/inst_handlers/rv64/zicsr/RvzicsrInsts.cpp +++ b/core/inst_handlers/rv64/zicsr/RvzicsrInsts.cpp @@ -1,6 +1,7 @@ #include "core/inst_handlers/rv64/zicsr/RvzicsrInsts.hpp" #include "include/ActionTags.hpp" #include "core/ActionGroup.hpp" + namespace atlas { void RvzicsrInsts::getInstHandlers(std::map & inst_handlers) @@ -25,8 +26,6 @@ namespace atlas nullptr, "csrrwi", ActionTags::EXECUTE_TAG)); } - - ActionGroup* RvzicsrInsts::csrrs_64_handler(atlas::AtlasState* state) { (void)state; diff --git a/core/inst_handlers/rv64/zifencei/RvzifenceiInsts.cpp b/core/inst_handlers/rv64/zifencei/RvzifenceiInsts.cpp index c7b1c96..f172d38 100644 --- a/core/inst_handlers/rv64/zifencei/RvzifenceiInsts.cpp +++ b/core/inst_handlers/rv64/zifencei/RvzifenceiInsts.cpp @@ -1,6 +1,7 @@ #include "core/inst_handlers/rv64/zifencei/RvzifenceiInsts.hpp" #include "include/ActionTags.hpp" #include "core/ActionGroup.hpp" + namespace atlas { void RvzifenceiInsts::getInstHandlers(std::map & inst_handlers) @@ -11,8 +12,6 @@ namespace atlas nullptr, "fence_i", ActionTags::EXECUTE_TAG)); } - - ActionGroup* RvzifenceiInsts::fence_i_64_handler(atlas::AtlasState* state) { (void)state;