63 lines
1.0 KiB
C++
63 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <vector>
|
|
#include <cstdint>
|
|
|
|
#include "config.h"
|
|
|
|
namespace DynamicPipeline {
|
|
|
|
enum CommandType : uint16_t
|
|
{
|
|
ADD,
|
|
SUB,
|
|
MUL,
|
|
DIV,
|
|
POW,
|
|
CMD_COUNT
|
|
};
|
|
|
|
struct Command
|
|
{
|
|
enum CommandType t;
|
|
uint16_t op1;
|
|
uint16_t op2;
|
|
uint16_t res;
|
|
|
|
Command(enum CommandType t, uint16_t op1, uint16_t op2, uint16_t res)
|
|
: t(t), op1(op1), op2(op2), res(res)
|
|
{
|
|
|
|
}
|
|
};
|
|
|
|
struct MemCell
|
|
{
|
|
double v;
|
|
int ready;
|
|
};
|
|
|
|
class System
|
|
{
|
|
private:
|
|
std::vector<Command> *program_memory;
|
|
std::array<MemCell, DYN_PIPELINE_MEM_SIZE> data_memory;
|
|
std::array<int, DYN_PIPELINE_LAYERS> layer_cmd {-1};
|
|
unsigned int pc {0};
|
|
unsigned int system_time;
|
|
|
|
void print_program_memory(void) const;
|
|
void print_pipeline(void) const;
|
|
bool pipeline_empty(void) const;
|
|
bool next_instruction(void) const;
|
|
bool instruction_ready(void) const;
|
|
void step(void);
|
|
|
|
public:
|
|
void init(const std::vector<Command> * const prg, const std::array<double, DYN_PIPELINE_MEM_SIZE>& mem, const int init_mem_size);
|
|
void run(void);
|
|
};
|
|
|
|
}
|