Skip to content

Commit

Permalink
macro usage fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyasa committed Nov 25, 2024
1 parent b5f8f5f commit b983193
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions icicle/backend/cpu/include/cpu_program_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace icicle {
class CpuProgramExecutor
{
public:
CpuProgramExecutor(Program<S>& program)
CpuProgramExecutor(const Program<S>& program)
: m_program(program), m_variable_ptrs(program.get_nof_vars()), m_intermediates(program.m_nof_intermidiates)
{
// initialize m_variable_ptrs vector
int variable_ptrs_idx = program.m_nof_inputs + program.m_nof_outputs;
for (int idx = 0; idx < program.m_nof_constants; ++idx) {
m_variable_ptrs[variable_ptrs_idx++] = &(program.m_constants[idx]);
m_variable_ptrs[variable_ptrs_idx++] = (S*)(&(program.m_constants[idx]));
}
for (int idx = 0; idx < program.m_nof_intermidiates; ++idx) {
m_variable_ptrs[variable_ptrs_idx++] = &(m_intermediates[idx]);
Expand All @@ -37,7 +37,7 @@ namespace icicle {
std::vector<S*> m_variable_ptrs;

private:
Program<S>& m_program;
const Program<S>& m_program;
std::vector<S> m_intermediates;

// exe functions
Expand Down
26 changes: 19 additions & 7 deletions icicle/include/icicle/program/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,26 @@ namespace icicle {
generate_program(operation->m_operand2);

// Build an instruction
std::byte int_arr[4] = {};
int_arr[0] = std::byte(operation->m_opcode);
int_arr[1] = std::byte(operation->m_operand1->m_variable_idx);
if (operation->m_operand2) { int_arr[2] = std::byte(operation->m_operand2->m_variable_idx); }
if (operation->m_variable_idx < 0) { operation->m_variable_idx = allocate_intermidiate(); }
int_arr[3] = std::byte(operation->m_variable_idx);
std::byte int_arr[sizeof(InstructionType)] = {};
// Set instruction::opcode
int_arr[INST_OPCODE] = std::byte(operation->m_opcode);
// Set instruction::operand1
int_arr[INST_OPERAND1] = std::byte(operation->m_operand1->m_variable_idx);

if (operation->m_operand2) {
// Set instruction::operand2
int_arr[INST_OPERAND2] = std::byte(operation->m_operand2->m_variable_idx);
}

if (operation->m_variable_idx < 0) {
// allocate a register for the result
operation->m_variable_idx = allocate_intermidiate();
}

// Set instruction::operand2
int_arr[INST_RESULT] = std::byte(operation->m_variable_idx);
InstructionType instruction;
std::memcpy(&instruction, int_arr, 4);
std::memcpy(&instruction, int_arr, sizeof(InstructionType));
m_instructions.push_back(instruction);
}

Expand Down

0 comments on commit b983193

Please sign in to comment.