Files
pzks-labs/inc/dyn-pipeline.hpp
T

98 lines
1.8 KiB
C++
Raw Normal View History

#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)
{
}
};
2026-11-08 18:25:35 +02:00
struct CommandOOE
{
enum CommandType t;
uint16_t op1;
uint16_t op2;
uint16_t res;
uint16_t exe;
CommandOOE(enum CommandType t, uint16_t op1, uint16_t op2, uint16_t res)
: t(t), op1(op1), op2(op2), res(res), exe(0)
{
}
};
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);
};
2026-11-08 18:25:35 +02:00
class SystemOOE
{
private:
std::vector<CommandOOE> *program_memory;
std::array<MemCell, DYN_PIPELINE_MEM_SIZE> data_memory;
std::array<int, DYN_PIPELINE_LAYERS> layer_cmd {-1};
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;
int get_instruction(void) const;
void step(void);
public:
void init(const std::vector<CommandOOE> * const prg, const std::array<double, DYN_PIPELINE_MEM_SIZE>& mem, const int init_mem_size);
void run(void);
};
}