Skip to content

Commit

Permalink
Refactor Instruction Handler Classes to Support RV32 and RV64 (#23)
Browse files Browse the repository at this point in the history
To reuse as much code as possible, I've removed the `rv64` subdirectory
and refactored the instruction handler classes to provide a placeholder
for future RV32 instruction handler functions.
  • Loading branch information
kathlenemagnus authored Dec 13, 2024
1 parent 78ead2f commit 72b5f08
Show file tree
Hide file tree
Showing 27 changed files with 1,164 additions and 971 deletions.
37 changes: 19 additions & 18 deletions core/Execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

#include "sparta/utils/LogUtils.hpp"

#include "core/inst_handlers/rv64/a/RvaInsts.hpp"
#include "core/inst_handlers/rv64/d/RvdInsts.hpp"
#include "core/inst_handlers/rv64/f/RvfInsts.hpp"
#include "core/inst_handlers/rv64/i/RviInsts.hpp"
#include "core/inst_handlers/rv64/m/RvmInsts.hpp"
#include "core/inst_handlers/rv64/zicsr/RvzicsrInsts.hpp"
#include "core/inst_handlers/rv64/zifencei/RvzifenceiInsts.hpp"
#include "core/inst_handlers/a/RvaInsts.hpp"
#include "core/inst_handlers/d/RvdInsts.hpp"
#include "core/inst_handlers/f/RvfInsts.hpp"
#include "core/inst_handlers/i/RviInsts.hpp"
#include "core/inst_handlers/m/RvmInsts.hpp"
#include "core/inst_handlers/zicsr/RvzicsrInsts.hpp"
#include "core/inst_handlers/zifencei/RvzifenceiInsts.hpp"

namespace atlas
{
Expand All @@ -25,20 +25,21 @@ namespace atlas
execute_action.addTag(ActionTags::EXECUTE_TAG);
execute_action_group_.addAction(execute_action);

// TODO: Get RV32 inst handlers
// Get instruction handlers
RviInsts::getInstHandlers(inst_handlers_);
RvmInsts::getInstHandlers(inst_handlers_);
RvaInsts::getInstHandlers(inst_handlers_);
RvfInsts::getInstHandlers(inst_handlers_);
RvdInsts::getInstHandlers(inst_handlers_);
RvzicsrInsts::getInstHandlers(inst_handlers_);
RvzifenceiInsts::getInstHandlers(inst_handlers_);
RviInsts::getInstHandlers<RV64>(inst_handlers_);
RvmInsts::getInstHandlers<RV64>(inst_handlers_);
RvaInsts::getInstHandlers<RV64>(inst_handlers_);
RvfInsts::getInstHandlers<RV64>(inst_handlers_);
RvdInsts::getInstHandlers<RV64>(inst_handlers_);
RvzicsrInsts::getInstHandlers<RV64>(inst_handlers_);
RvzifenceiInsts::getInstHandlers<RV64>(inst_handlers_);

// Get instruction compute address handlers
RviInsts::getInstComputeAddressHandlers(inst_compute_address_handlers_);
RvaInsts::getInstComputeAddressHandlers(inst_compute_address_handlers_);
RvfInsts::getInstComputeAddressHandlers(inst_compute_address_handlers_);
RvdInsts::getInstComputeAddressHandlers(inst_compute_address_handlers_);
RviInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
RvaInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
RvfInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
RvdInsts::getInstComputeAddressHandlers<RV64>(inst_compute_address_handlers_);
}

ActionGroup* Execute::execute_(AtlasState* state)
Expand Down
8 changes: 7 additions & 1 deletion core/inst_handlers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
project(Atlas)

add_subdirectory(rv64)
add_subdirectory(i)
add_subdirectory(m)
add_subdirectory(a)
add_subdirectory(f)
add_subdirectory(d)
add_subdirectory(zicsr)
add_subdirectory(zifencei)

add_library(atlasinsts)
target_link_libraries(atlasinsts
Expand Down
File renamed without changes.
447 changes: 447 additions & 0 deletions core/inst_handlers/a/RvaInsts.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace atlas
public:
using base_type = RvaInsts;

template <typename XLEN>
static void getInstComputeAddressHandlers(std::map<std::string, Action> & inst_handlers);
template <typename XLEN>
static void getInstHandlers(std::map<std::string, Action> & inst_handlers);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace atlas

template <typename T> ActionGroup* compute_address_handler(AtlasState* state)
{
static_assert(std::is_same<T, RV64>::value || std::is_same<T, RV32>::value);
static_assert(std::is_same_v<T, RV64> || std::is_same_v<T, RV32>);

const AtlasInstPtr & inst = state->getCurrentInst();
const T rs1_val = inst->getRs1()->dmiRead<uint64_t>();
Expand All @@ -26,12 +26,12 @@ namespace atlas
template <typename RV, typename SIZE, template <typename> class BinaryOp, bool U = true>
ActionGroup* amo_handler(atlas::AtlasState* state)
{
static_assert(std::is_same<RV, RV64>::value || std::is_same<RV, RV32>::value);
static_assert(std::is_same<SIZE, W>::value || std::is_same<SIZE, D>::value);
static_assert(std::is_same_v<RV, RV64> || std::is_same_v<RV, RV32>);
static_assert(std::is_same_v<SIZE, W> || std::is_same_v<SIZE, D>);
static_assert(sizeof(RV) >= sizeof(SIZE));

using Op =
typename std::conditional<std::is_same<RV, RV64>::value,
typename std::conditional<std::is_same_v<RV, RV64>,
typename std::conditional<U, uint64_t, int64_t>::type,
typename std::conditional<U, uint32_t, int32_t>::type>::type;

Expand Down Expand Up @@ -71,4 +71,4 @@ namespace atlas
return rhs;
}
};
} // namespace atlas
} // namespace atlas
File renamed without changes.
Loading

0 comments on commit 72b5f08

Please sign in to comment.