OpenASIP 2.2
Loading...
Searching...
No Matches
Functions | Variables
RISCVInstructionExecutor Namespace Reference

Functions

std::vector< SimValueexecuteInstructionHelper (const char *opName, uint8_t width, const uint64_t *inputs, int inputsCount)
 

Variables

constexpr unsigned OPC_CUSTOM_0 = 0b0001011
 
constexpr unsigned OPC_CUSTOM_1 = 0b0101011
 
std::map< std::string, int > customOps = {}
 
std::unique_ptr< OperationPoolpool = nullptr
 

Function Documentation

◆ executeInstructionHelper()

std::vector< SimValue > RISCVInstructionExecutor::executeInstructionHelper ( const char *  opName,
uint8_t  width,
const uint64_t *  inputs,
int  inputsCount 
)

Helper function that executes an OSAL instruction.

Takes in the opName, instruction width, and the inputs, and returns the output vector.

Parameters
opNameoperation to be executed
widthinstruction width (typically 32 or 64)
inputsarray of input values
inputsCountnumber of values in the inputs array
Returns
vector of SimValue objects.

Definition at line 61 of file RISCVInstructionExecutor.cc.

63 {
64 if (RISCVInstructionExecutor::pool == nullptr) {
65 RISCVInstructionExecutor::pool = std::make_unique<OperationPool>();
66 }
67
68 Operation& op = RISCVInstructionExecutor::pool->operation(opName);
69 if (&op == &NullOperation::instance()) {
72 std::string("ExecuteInstruction error: No behavior "
73 "implementation found for operation '") +
74 opName + "'");
75 }
76 OperationBehavior& behavior = op.behavior();
77
78 if (&behavior == &NullOperationBehavior::instance()) {
79 throw std::logic_error(
80 std::string("ExecuteInstruction error: No behavior "
81 "implementation found for operation '") +
82 opName + "'");
83 }
84
85 OperationContext opContext(opName);
86 behavior.createState(opContext);
87
88 if (inputsCount < op.numberOfInputs()) {
89 behavior.deleteState(opContext);
92 std::string("ExecuteInstruction error: Not enough input values"));
93 }
94
95 const int opInputs = op.numberOfInputs();
96 const int opOutputs = op.numberOfOutputs();
97 const int opValues = opInputs + opOutputs;
98
99 std::vector<std::unique_ptr<SimValue>> simValues(opValues);
100
101 for (int i = 0; i < opInputs; ++i) {
102 simValues[i] = std::make_unique<SimValue>(inputs[i], width);
103 }
104 for (int i = 0; i < opOutputs; ++i) {
105 simValues[opInputs + i] = std::make_unique<SimValue>(0, width);
106 }
107
108 std::vector<SimValue*> simValPtrs(opValues);
109 for (int i = 0; i < opValues; ++i) {
110 simValPtrs[i] = simValues[i].get();
111 }
112
113 if (!behavior.simulateTrigger(simValPtrs.data(), opContext)) {
114 behavior.deleteState(opContext);
117 std::string(
118 "ExecuteInstruction error: operation execution failed"));
119 }
120
121 std::vector<SimValue> results(opOutputs);
122 for (int i = 0; i < opOutputs; i++) {
123 results[i] = *simValues[opInputs + i];
124 }
125
126 behavior.deleteState(opContext);
127 return results;
128}
#define THROW_EXCEPTION(exceptionType, message)
Exception wrapper macro that automatically includes file name, line number and function name where th...
Definition Exception.hh:39
static NullOperationBehavior & instance()
static NullOperation & instance()
virtual void createState(OperationContext &context) const
virtual bool simulateTrigger(SimValue **io, OperationContext &context) const =0
virtual void deleteState(OperationContext &context) const
virtual OperationBehavior & behavior() const
Definition Operation.cc:388
virtual int numberOfInputs() const
Definition Operation.cc:192
virtual int numberOfOutputs() const
Definition Operation.cc:202
std::unique_ptr< OperationPool > pool

References Operation::behavior(), OperationBehavior::createState(), OperationBehavior::deleteState(), NullOperation::instance(), NullOperationBehavior::instance(), Operation::numberOfInputs(), Operation::numberOfOutputs(), pool, OperationBehavior::simulateTrigger(), and THROW_EXCEPTION.

Referenced by executeInstruction32(), and executeInstruction64().

Here is the call graph for this function:

Variable Documentation

◆ customOps

std::map<std::string, int> RISCVInstructionExecutor::customOps = {}

Definition at line 45 of file RISCVInstructionExecutor.cc.

45{};

Referenced by initializeMachine(), resetMachine(), and unpackInstruction().

◆ OPC_CUSTOM_0

constexpr unsigned RISCVInstructionExecutor::OPC_CUSTOM_0 = 0b0001011
constexpr

Definition at line 42 of file RISCVInstructionExecutor.cc.

Referenced by unpackInstruction().

◆ OPC_CUSTOM_1

constexpr unsigned RISCVInstructionExecutor::OPC_CUSTOM_1 = 0b0101011
constexpr

Definition at line 43 of file RISCVInstructionExecutor.cc.

Referenced by unpackInstruction().

◆ pool

std::unique_ptr<OperationPool> RISCVInstructionExecutor::pool = nullptr