SystemC-Components-Test/tests/sim_performance/top.cpp

97 lines
3.4 KiB
C++
Raw Permalink Normal View History

/*
* top.cpp
*
* Created on: 04.05.2020
* Author: eyck
*/
#include "top.h"
#include <fmt/format.h>
2023-12-22 20:42:21 +01:00
#include <scc/report.h>
#include <scc/utilities.h>
using namespace sc_core;
using namespace fmt;
2023-12-22 20:42:21 +01:00
top::top(sc_core::sc_module_name const& nm, uint8_t dimension, unsigned count)
: sc_module(nm) {
sc_assert(dimension > 0);
SC_HAS_PROCESS(top);
2023-12-22 20:42:21 +01:00
for(auto yidx = 0U; yidx < dimension; ++yidx) {
for(auto xidx = 0U; xidx < dimension; ++xidx) {
auto name = format("sw_{}_{}", xidx, yidx);
2023-12-22 20:42:21 +01:00
SCCDEBUG(SCMOD) << "instantiating switch " << xidx << "/" << yidx;
switches.push_back(scc::make_unique<pkt_switch>(sc_module_name(name.c_str())));
switches.back()->clk_i(clk);
}
}
2023-12-22 20:42:21 +01:00
for(auto yidx = 0U; yidx < dimension; ++yidx) {
for(auto xidx = 0U; xidx < dimension; ++xidx) {
auto& sw = switches[yidx * dimension + xidx];
if(xidx < dimension - 1) {
auto& swr = switches[yidx * dimension + (xidx + 1)];
sw->isck[RIGHT](swr->tsck[LEFT]);
swr->isck[LEFT](sw->tsck[RIGHT]);
}
2023-12-22 20:42:21 +01:00
if(yidx < dimension - 1) {
auto& swb = switches[(yidx + 1) * dimension + xidx];
sw->isck[BOTTOM](swb->tsck[TOP]);
swb->isck[TOP](sw->tsck[BOTTOM]);
}
}
}
auto yidx = 0U;
auto xidx = 0U;
2023-12-22 20:42:21 +01:00
for(xidx = 0U; xidx < dimension; ++xidx) {
auto name = format("snd_{}_{}", xidx + 1, 0);
senders[TOP].push_back(scc::make_unique<pkt_sender>(sc_module_name(name.c_str()), dimension, xidx + 1, 0, count));
auto& snd = senders[TOP].back();
snd->clk_i(clk);
2023-12-22 20:42:21 +01:00
auto& sw = switches[yidx * dimension + xidx];
snd->isck(sw->tsck[TOP]);
sw->isck[TOP](snd->tsck);
}
2023-12-22 20:42:21 +01:00
yidx = dimension - 1;
for(xidx = 0U; xidx < dimension; ++xidx) {
auto name = format("snd_{}_{}", xidx + 1, dimension + 1);
senders[BOTTOM].push_back(scc::make_unique<pkt_sender>(sc_module_name(name.c_str()), dimension, xidx + 1, dimension + 1, count));
auto& snd = senders[BOTTOM].back();
snd->clk_i(clk);
2023-12-22 20:42:21 +01:00
auto& sw = switches[yidx * dimension + xidx];
snd->isck(sw->tsck[BOTTOM]);
sw->isck[BOTTOM](snd->tsck);
}
2023-12-22 20:42:21 +01:00
xidx = 0U;
for(yidx = 0U; yidx < dimension; ++yidx) {
auto name = format("snd_{}_{}", 0, yidx + 1);
senders[LEFT].push_back(scc::make_unique<pkt_sender>(sc_module_name(name.c_str()), dimension, 0, yidx + 1, count));
auto& snd = senders[LEFT].back();
snd->clk_i(clk);
2023-12-22 20:42:21 +01:00
auto& sw = switches[yidx * dimension + xidx];
snd->isck(sw->tsck[LEFT]);
sw->isck[LEFT](snd->tsck);
}
2023-12-22 20:42:21 +01:00
xidx = dimension - 1;
for(yidx = 0U; yidx < dimension; ++yidx) {
auto name = format("snd_{}_{}", dimension + 1, yidx + 1);
senders[RIGHT].push_back(scc::make_unique<pkt_sender>(sc_module_name(name.c_str()), dimension, dimension + 1, yidx + 1, count));
auto& snd = senders[RIGHT].back();
snd->clk_i(clk);
2023-12-22 20:42:21 +01:00
auto& sw = switches[yidx * dimension + xidx];
snd->isck(sw->tsck[RIGHT]);
sw->isck[RIGHT](snd->tsck);
}
SC_THREAD(run);
}
void top::run() {
sc_event_and_list evt_list;
2023-12-22 20:42:21 +01:00
for(auto& sides : senders) {
for(auto& sender : sides) {
evt_list &= sender->get_finish_event();
}
}
wait(evt_list);
sc_stop();
}