verilator cleanups

This commit is contained in:
Eric Matthews 2021-06-04 16:50:23 -07:00
parent 5ba13cf90a
commit d87f03bf29
6 changed files with 104 additions and 102 deletions

View file

@ -1,17 +1,20 @@
#include "axi_ddr_sim.h"
#include "ddr_page.h"
#include <stdint.h>
#include <iostream>
#include <cstdlib>
#include <assert.h>
#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vtaiga_sim.h"
#include "axi_ddr_sim.h"
#include "ddr_page.h"
using namespace std;
template <class TB>
axi_ddr_sim<TB>::axi_ddr_sim(TB * tb){
axi_ddr_sim::axi_ddr_sim(Vtaiga_sim * tb){
this->tb = tb;
}
template <class TB>
void axi_ddr_sim<TB>::init_signals(){
void axi_ddr_sim::init_signals(){
tb->ddr_axi_bresp = 0;
tb->ddr_axi_bvalid = 0;
tb->ddr_axi_rvalid = 0;
@ -22,8 +25,8 @@ void axi_ddr_sim<TB>::init_signals(){
tb->ddr_axi_rvalid = 0;
}
template <class TB>
axi_ddr_sim<TB>::axi_ddr_sim(string filepath, uint32_t starting_memory_location, int number_of_bytes, TB * tb){
axi_ddr_sim::axi_ddr_sim(string filepath, uint32_t starting_memory_location, int number_of_bytes, Vtaiga_sim * tb){
ifstream input_memory_file;
input_memory_file.open(filepath);
string line;
@ -51,8 +54,8 @@ axi_ddr_sim<TB>::axi_ddr_sim(string filepath, uint32_t starting_memory_location,
}
template <class TB>
axi_ddr_sim<TB>::axi_ddr_sim(ifstream & input_memory_file, TB * tb){
axi_ddr_sim::axi_ddr_sim(ifstream & input_memory_file, Vtaiga_sim * tb){
string line;
uint32_t max_pages = DDR_SIZE/PAGE_SIZE;
@ -84,8 +87,8 @@ axi_ddr_sim<TB>::axi_ddr_sim(ifstream & input_memory_file, TB * tb){
fflush(stdout);
}
template <class TB>
int axi_ddr_sim<TB>::get_data(uint32_t data_address){
int axi_ddr_sim::get_data(uint32_t data_address){
uint32_t starting_address = (data_address / PAGE_SIZE) * PAGE_SIZE;
if(ddr_pages.count(starting_address)){ //If page exists
return ddr_pages[starting_address].return_data(data_address%PAGE_SIZE/4);
@ -97,8 +100,8 @@ int axi_ddr_sim<TB>::get_data(uint32_t data_address){
return ddr_pages[starting_address].return_data(data_address%PAGE_SIZE/4);
}
}
template <class TB>
void axi_ddr_sim<TB>::set_data(uint32_t data_address, uint32_t set_data, uint32_t byte_enable){
void axi_ddr_sim::set_data(uint32_t data_address, uint32_t set_data, uint32_t byte_enable){
uint32_t data = get_data(data_address);
uint32_t starting_address = (data_address / PAGE_SIZE) * PAGE_SIZE;
data = (data & ~byte_enable) | (set_data & byte_enable);
@ -106,16 +109,16 @@ void axi_ddr_sim<TB>::set_data(uint32_t data_address, uint32_t set_data, uint32
};
template <class TB>
ddr_page axi_ddr_sim<TB>::get_page(uint32_t page_address){
ddr_page axi_ddr_sim::get_page(uint32_t page_address){
return ddr_pages[page_address];
}
template <class TB>
void axi_ddr_sim<TB>::parse_input_signals(){
void axi_ddr_sim::parse_input_signals(){
//If the master has a write requests
if(tb->ddr_axi_awvalid && wd_ad_channel_queue.size() < MAX_INFLIGHT_WD_REQ){
if(tb->ddr_axi_awvalid && wr_ad_channel_queue.size() < MAX_INFLIGHT_WR_REQ){
AXI_write_address_channel_signals elem{tb->ddr_axi_awaddr, tb->ddr_axi_awlen, tb->ddr_axi_awsize, tb->ddr_axi_awburst,tb->ddr_axi_awcache,tb->ddr_axi_awid};
wd_ad_channel_queue.push(elem);
wr_ad_channel_queue.push(elem);
}
//If the master has write data
if(tb->ddr_axi_wvalid){
@ -128,8 +131,8 @@ void axi_ddr_sim<TB>::parse_input_signals(){
rd_ad_channel_queue.push(elem);
}
}
template <class TB>
void axi_ddr_sim<TB>::parse_output_signals(){
void axi_ddr_sim::parse_output_signals(){
if(tb->rst ==1){
tb->ddr_axi_wready = 0;
tb->ddr_axi_arready = 0;
@ -149,7 +152,7 @@ void axi_ddr_sim<TB>::parse_output_signals(){
tb->ddr_axi_wready = 1;
//Write Req
if(wd_ad_channel_queue.size() < MAX_INFLIGHT_WD_REQ)
if(wr_ad_channel_queue.size() < MAX_INFLIGHT_WR_REQ)
tb->ddr_axi_awready = 1;
else
tb->ddr_axi_awready = 0;
@ -202,8 +205,8 @@ void axi_ddr_sim<TB>::parse_output_signals(){
}
}
}
template <class TB>
void axi_ddr_sim<TB>::handle_read_req(){
void axi_ddr_sim::handle_read_req(){
if(rd_ad_channel_queue.size() > 0 ){
if(current_read_parameters.delay_cycles_left == 0){
AXI_read_data_channel_signals elem;
@ -241,8 +244,8 @@ void axi_ddr_sim<TB>::handle_read_req(){
}
}
template <class TB>
void axi_ddr_sim<TB>::handle_write_req(){
void axi_ddr_sim::handle_write_req(){
//cout << "w_data_channel_queue size: " << w_data_channel_queue.size() << endl;
//cout << "current_write_parameters.number_of_bursts_left: " << current_write_parameters.number_of_bursts_left << endl;
if(w_data_channel_queue.size() > 0 && current_write_parameters.number_of_bursts_left > 0){
@ -270,15 +273,15 @@ void axi_ddr_sim<TB>::handle_write_req(){
set_data(current_write_parameters.address, elem.wdata, byte_enable);
current_write_parameters.number_of_bursts_left--;
if(wd_ad_channel_queue.front().awburst == 0 ){//FIXED
if(wr_ad_channel_queue.front().awburst == 0 ){//FIXED
//do nothing
}
else if(wd_ad_channel_queue.front().awburst == 1){ //INCR
else if(wr_ad_channel_queue.front().awburst == 1){ //INCR
//Increment Address by number of bytes in a burst(arsize)
current_write_parameters.address += current_write_parameters.increment;
}
else if(wd_ad_channel_queue.front().awburst == 2){ //WRAP
else if(wr_ad_channel_queue.front().awburst == 2){ //WRAP
current_write_parameters.address += current_write_parameters.increment;
if(current_write_parameters.address == current_write_parameters.wrap_boundary + current_write_parameters.number_bytes * current_write_parameters.burst_length){
current_write_parameters.address = current_write_parameters.wrap_boundary;
@ -289,7 +292,7 @@ void axi_ddr_sim<TB>::handle_write_req(){
AXI_write_response_channel_signals resp_elem;
resp_elem.bid = elem.wid;
resp_elem.bresp = 0;
wd_ad_channel_queue.pop();
wr_ad_channel_queue.pop();
w_res_channel_queue.push(resp_elem);
}
}
@ -299,8 +302,8 @@ void axi_ddr_sim<TB>::handle_write_req(){
}
}
template <class TB>
void axi_ddr_sim<TB>::update_current_read_parameters(){
void axi_ddr_sim::update_current_read_parameters(){
//If I can serve a new read request
if(rd_ad_channel_queue.size() > 0 && current_read_parameters.number_of_bursts_left == 0){
current_read_parameters.address = rd_ad_channel_queue.front().araddr;
@ -322,32 +325,32 @@ void axi_ddr_sim<TB>::update_current_read_parameters(){
}
}
}
template <class TB>
void axi_ddr_sim<TB>::update_current_write_parameters(){
void axi_ddr_sim::update_current_write_parameters(){
//If I can serve a new read request
if(wd_ad_channel_queue.size() > 0 && current_write_parameters.number_of_bursts_left == 0){
current_write_parameters.address = wd_ad_channel_queue.front().awaddr;
current_write_parameters.number_of_bursts_left = wd_ad_channel_queue.front().awlen +1;
if(wr_ad_channel_queue.size() > 0 && current_write_parameters.number_of_bursts_left == 0){
current_write_parameters.address = wr_ad_channel_queue.front().awaddr;
current_write_parameters.number_of_bursts_left = wr_ad_channel_queue.front().awlen +1;
current_write_parameters.delay_cycles_left = write_distribution(generator);
if(wd_ad_channel_queue.front().awburst == 0 ){//FIXED
if(wr_ad_channel_queue.front().awburst == 0 ){//FIXED
current_write_parameters.increment = 0;
}
else if(wd_ad_channel_queue.front().awburst == 1){ //INCR
else if(wr_ad_channel_queue.front().awburst == 1){ //INCR
//Increment Address by number of bytes in a burst(arsize)
current_write_parameters.increment = pow(2,wd_ad_channel_queue.front().awsize);
current_write_parameters.increment = pow(2,wr_ad_channel_queue.front().awsize);
}
else if(wd_ad_channel_queue.front().awburst == 2){ //WRAP
current_write_parameters.increment = pow(2,wd_ad_channel_queue.front().awsize);
current_write_parameters.number_bytes = pow(2,wd_ad_channel_queue.front().awsize);
current_write_parameters.burst_length = wd_ad_channel_queue.front().awlen +1;
else if(wr_ad_channel_queue.front().awburst == 2){ //WRAP
current_write_parameters.increment = pow(2,wr_ad_channel_queue.front().awsize);
current_write_parameters.number_bytes = pow(2,wr_ad_channel_queue.front().awsize);
current_write_parameters.burst_length = wr_ad_channel_queue.front().awlen +1;
current_write_parameters.wrap_boundary = (int)(current_write_parameters.address/(current_write_parameters.number_bytes * current_write_parameters.burst_length)) * (current_write_parameters.number_bytes * current_write_parameters.burst_length);
}
}
}
template <class TB>
void axi_ddr_sim<TB>::step(){
void axi_ddr_sim::step(){
parse_input_signals();
update_current_read_parameters();

View file

@ -30,8 +30,12 @@
#include <cmath>
#include <map>
#include <random>
#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vtaiga_sim.h"
#include "axi_interface.h"
#include "ddr_page.h"
using namespace std;
@ -44,18 +48,18 @@ struct addr_calculation_parameters{
int number_of_bursts_left;
int delay_cycles_left;
};
template <class TB>
class axi_ddr_sim{
public:
//Functions--------------------------------------------------------------
//Init instructions-----------------
axi_ddr_sim();
//Initialize DDR
axi_ddr_sim(TB * tb);
axi_ddr_sim(Vtaiga_sim * tb);
//Initialize DDR from file
axi_ddr_sim(string filepath, uint32_t starting_memory_location, int number_of_bytes, TB * tb);
axi_ddr_sim(ifstream & input_memory_file, TB * tb);
axi_ddr_sim(string filepath, uint32_t starting_memory_location, int number_of_bytes, Vtaiga_sim * tb);
axi_ddr_sim(ifstream & input_memory_file, Vtaiga_sim * tb);
void step();
int get_data(uint32_t data_address);
@ -79,7 +83,7 @@ template <class TB>
uniform_int_distribution<int> write_distribution;
//Pointers to Data
map<uint32_t,ddr_page> ddr_pages;
TB *tb;
Vtaiga_sim *tb;
void parse_output_signals();
void parse_input_signals();
@ -94,7 +98,7 @@ template <class TB>
//Read Request Queue
queue<AXI_read_address_channel_signals> rd_ad_channel_queue;
//Write Request Queue
queue<AXI_write_address_channel_signals> wd_ad_channel_queue;
queue<AXI_write_address_channel_signals> wr_ad_channel_queue;
//Read Data Queue
queue<AXI_read_data_channel_signals> r_data_channel_queue;
//Write Data Queue
@ -105,5 +109,4 @@ template <class TB>
unsigned starting_location = 0x80000000;
};
#include "axi_ddr_sim.cc"
#endif

View file

@ -23,16 +23,14 @@
#include <iostream>
#include "TaigaTracer.h"
//#define TRACE_ON
template <class TB>
bool TaigaTracer<TB>::check_instruction_issued(uint32_t inst) {
bool TaigaTracer::check_instruction_issued(uint32_t inst) {
return (tb->instruction_data_dec == inst && tb->instruction_issued);
}
template <class TB>
bool TaigaTracer<TB>::has_terminated() {
bool TaigaTracer::has_terminated() {
if (check_instruction_issued(ERROR_TERMINATION_NOP)) {
std::cout << "\n\nError!!!!\n\n";
@ -45,8 +43,8 @@ bool TaigaTracer<TB>::has_terminated() {
return false;
}
template <class TB>
bool TaigaTracer<TB>::has_stalled() {
bool TaigaTracer::has_stalled() {
if (!tb->instruction_issued) {
if (stall_count > stall_limit) {
stall_count = 0;
@ -62,22 +60,22 @@ bool TaigaTracer<TB>::has_stalled() {
return false;
}
template <class TB>
void TaigaTracer<TB>::reset_stats() {
void TaigaTracer::reset_stats() {
for (int i=0; i < numEvents; i++)
event_counters[i] = 0;
}
template <class TB>
void TaigaTracer<TB>::update_stats() {
void TaigaTracer::update_stats() {
if (collect_stats) {
for (int i=0; i < numEvents; i++)
event_counters[i] += tb->taiga_events[i];
}
}
template <class TB>
void TaigaTracer<TB>::print_stats() {
void TaigaTracer::print_stats() {
std::cout << " Taiga trace stats\n";
std::cout << "--------------------------------------------------------------\n";
for (int i=0; i < numEvents; i++)
@ -87,8 +85,8 @@ void TaigaTracer<TB>::print_stats() {
}
template <class TB>
void TaigaTracer<TB>::reset() {
void TaigaTracer::reset() {
tb->clk = 0;
tb->rst = 1;
for (int i=0; i <reset_length; i++){
@ -101,21 +99,21 @@ void TaigaTracer<TB>::reset() {
}
template <class TB>
void TaigaTracer<TB>::set_log_file(std::ofstream* logFile) {
void TaigaTracer::set_log_file(std::ofstream* logFile) {
this->logFile = logFile;
}
template <class TB>
void TaigaTracer<TB>::update_UART() {
void TaigaTracer::update_UART() {
if (tb->write_uart) {
std::cout << tb->uart_byte << std::flush;
*logFile << tb->uart_byte;
}
}
template <class TB>
void TaigaTracer<TB>::update_memory() {
void TaigaTracer::update_memory() {
tb->instruction_bram_data_out = instruction_r;
if (tb->instruction_bram_en)
instruction_r = mem->read(tb->instruction_bram_addr);
@ -127,8 +125,8 @@ void TaigaTracer<TB>::update_memory() {
}
}
template <class TB>
void TaigaTracer<TB>::tick() {
void TaigaTracer::tick() {
cycle_count++;
tb->clk = 1;
@ -165,8 +163,8 @@ void TaigaTracer<TB>::tick() {
update_memory();
}
template <class TB>
void TaigaTracer<TB>::start_tracer(const char *trace_file) {
void TaigaTracer::start_tracer(const char *trace_file) {
#ifdef TRACE_ON
verilatorWaveformTracer = new VerilatedVcdC;
tb->trace(verilatorWaveformTracer, 99);
@ -175,24 +173,24 @@ void TaigaTracer<TB>::start_tracer(const char *trace_file) {
}
template <class TB>
uint64_t TaigaTracer<TB>::get_cycle_count() {
uint64_t TaigaTracer::get_cycle_count() {
return cycle_count;
}
template <class TB>
TaigaTracer<TB>::TaigaTracer(std::ifstream& programFile) {
TaigaTracer::TaigaTracer(std::ifstream& programFile) {
#ifdef TRACE_ON
Verilated::traceEverOn(true);
#endif
tb = new TB;
tb = new Vtaiga_sim;
#ifdef DDR_LOAD_FILE
axi_ddr = new axi_ddr_sim<Vtaiga_sim>(DDR_INIT_FILE,DDR_FILE_STARTING_LOCATION,DDR_FILE_NUM_BYTES);
axi_ddr = new axi_ddr_sim(DDR_INIT_FILE,DDR_FILE_STARTING_LOCATION,DDR_FILE_NUM_BYTES);
#else
axi_ddr = new axi_ddr_sim<Vtaiga_sim>(programFile, tb);
axi_ddr = new axi_ddr_sim(programFile, tb);
#endif
programFile.clear();
@ -203,8 +201,8 @@ TaigaTracer<TB>::TaigaTracer(std::ifstream& programFile) {
data_out_r = 0;
}
template <class TB>
TaigaTracer<TB>::~TaigaTracer() {
TaigaTracer::~TaigaTracer() {
#ifdef TRACE_ON
verilatorWaveformTracer->flush();
verilatorWaveformTracer->close();

View file

@ -25,6 +25,9 @@
#include <stdlib.h>
#include <iostream>
#include <iterator>
#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vtaiga_sim.h"
#include "SimMem.h"
#include "AXI_DDR_simulation/axi_ddr_sim.h"
//#define TRACE_ON
@ -73,7 +76,6 @@ static const char * const eventNames[] = {
static const int numEvents = arraySize(eventNames);
//Testbench with Taiga trace outputs on toplevel
template <class TB>
class TaigaTracer {
public:
TaigaTracer(std::ifstream& programFile);
@ -91,9 +93,9 @@ public:
uint64_t get_cycle_count();
//DDR Simulation
TB *tb;
Vtaiga_sim *tb;
private:
axi_ddr_sim<TB> * axi_ddr;
axi_ddr_sim * axi_ddr;
SimMem *mem;
#ifdef TRACE_ON
VerilatedVcdC *verilatorWaveformTracer;
@ -114,7 +116,4 @@ private:
uint32_t data_out_r;
};
#include "TaigaTracer.cc"
#endif

View file

@ -1,13 +1,12 @@
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include "Vtaiga_sim.h"
#include "verilated.h"
#include "verilated_vcd_c.h"
#include "Vtaiga_sim.h"
#include "TaigaTracer.h"
TaigaTracer<Vtaiga_sim> *taigaTracer;
TaigaTracer *taigaTracer;
//For time index on assertions
double sc_time_stamp () {
@ -62,7 +61,7 @@ int main(int argc, char **argv) {
}
// Create an instance of our module under test
taigaTracer = new TaigaTracer<Vtaiga_sim>(programFile);
taigaTracer = new TaigaTracer(programFile);
taigaTracer->set_log_file(&logFile);
#ifdef TRACE_ON
taigaTracer->start_tracer(argv[4]);

View file

@ -35,7 +35,7 @@ DELAY_SEED = 867583
ddr_size_def = DDR_SIZE=\(long\)$(DDR_SIZE_GB)*\(long\)1073741824
page_size_def = PAGE_SIZE=\($(PAGE_SIZE_KB)*1024\)
max_inflight_read_requests = MAX_INFLIGHT_RD_REQ=$(MAX_READ_REQ)
max_inflight_write_requests = MAX_INFLIGHT_WD_REQ=$(MAX_WRITE_REQ)
max_inflight_write_requests = MAX_INFLIGHT_WR_REQ=$(MAX_WRITE_REQ)
mix_delay_read = MIN_DELAY_RD=$(MIN_RD_DELAY)
max_delay_read = MAX_DELAY_RD=$(MAX_RD_DELAY)
min_delay_write = MIN_DELAY_WR=$(MIN_WR_DELAY)
@ -46,7 +46,7 @@ delay_seed = DELAY_SEED=$(DELAY_SEED)
#ddr_start_loc = DDR_FILE_STARTING_LOCATION=$(DDR_FILE_STARTING_LOCATION)
#ddr_num_bytes = DDR_FILE_NUM_BYTES=$(DDR_FILE_NUM_BYTES)
CFLAGS = -g0 -O3 -std=c++11 -march=native -D$(ddr_size_def) -D$(page_size_def) -D$(max_inflight_read_requests) -D$(max_inflight_write_requests)\
CFLAGS = -g0 -O3 -std=c++14 -march=native -D$(ddr_size_def) -D$(page_size_def) -D$(max_inflight_read_requests) -D$(max_inflight_write_requests)\
-D$(mix_delay_read) -D$(max_delay_read) -D$(min_delay_write) -D$(max_delay_write) -D$(delay_seed)
#(to-do)-D$(ddr_init_file) -D$(ddr_start_loc) -D$(ddr_num_bytes)
@ -90,7 +90,7 @@ $(TAIGA_SIM): $(TAIGA_HW_SRCS) $(TAIGA_SIM_SRCS)
verilator --cc --exe --Mdir $(TAIGA_SIM_DIR) -DENABLE_SIMULATION_ASSERTIONS --assert \
-o taiga-sim \
$(VERILATOR_LINT_IGNORE) $(VERILATOR_CFLAGS) \
$(TAIGA_INCLUDED_SIM_SRCS) \
$(TAIGA_SIM_SRCS) \
$(TAIGA_HW_SRCS) $(VERILATOR_DIR)/taiga_sim.sv --top-module taiga_sim
$(MAKE) -C $(TAIGA_SIM_DIR) -f Vtaiga_sim.mk