mirror of
https://github.com/YosysHQ/yosys
synced 2025-08-17 16:52:16 +00:00
external init implementation and testing
This commit is contained in:
parent
e57a2b9442
commit
d786262ad6
3 changed files with 85 additions and 19 deletions
|
@ -17,16 +17,16 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "kernel/yosys.h"
|
||||
#include "kernel/sigtools.h"
|
||||
#include "kernel/mem.h"
|
||||
#include "kernel/ff.h"
|
||||
#include "kernel/mem.h"
|
||||
#include "kernel/sigtools.h"
|
||||
#include "kernel/yosys.h"
|
||||
|
||||
USING_YOSYS_NAMESPACE
|
||||
PRIVATE_NAMESPACE_BEGIN
|
||||
|
||||
struct OptMemPass : public Pass {
|
||||
OptMemPass() : Pass("opt_mem", "optimize memories") { }
|
||||
OptMemPass() : Pass("opt_mem", "optimize memories") {}
|
||||
void help() override
|
||||
{
|
||||
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||
|
@ -35,17 +35,23 @@ struct OptMemPass : public Pass {
|
|||
log("\n");
|
||||
log("This pass performs various optimizations on memories in the design.\n");
|
||||
log("\n");
|
||||
log(" -external-init\n");
|
||||
log(" Assume memories are initialised externally, i.e. the memory\n");
|
||||
log(" is pre-populated so content is available even when there is no\n");
|
||||
log(" write within the circuit.\n");
|
||||
log("\n");
|
||||
}
|
||||
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
||||
{
|
||||
log_header(design, "Executing OPT_MEM pass (optimize memories).\n");
|
||||
bool external_init = false;
|
||||
|
||||
size_t argidx;
|
||||
for (argidx = 1; argidx < args.size(); argidx++) {
|
||||
// if (args[argidx] == "-nomux") {
|
||||
// mode_nomux = true;
|
||||
// continue;
|
||||
// }
|
||||
if (args[argidx] == "-external-init") {
|
||||
external_init = true;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
extra_args(args, argidx, design);
|
||||
|
@ -102,7 +108,7 @@ struct OptMemPass : public Pass {
|
|||
}
|
||||
std::vector<int> swizzle;
|
||||
for (int i = 0; i < mem.width; i++) {
|
||||
if (!always_0[i] && !always_1[i]) {
|
||||
if ((!always_0[i] && !always_1[i]) || external_init) {
|
||||
swizzle.push_back(i);
|
||||
continue;
|
||||
}
|
||||
|
@ -118,7 +124,7 @@ struct OptMemPass : public Pass {
|
|||
bit = State::Sx;
|
||||
}
|
||||
// Reconnect read port data.
|
||||
for (auto &port: mem.rd_ports) {
|
||||
for (auto &port : mem.rd_ports) {
|
||||
for (int sub = 0; sub < (1 << port.wide_log2); sub++) {
|
||||
int bidx = sub * mem.width + i;
|
||||
if (!port.clk_enable) {
|
||||
|
@ -161,11 +167,11 @@ struct OptMemPass : public Pass {
|
|||
continue;
|
||||
}
|
||||
if (GetSize(swizzle) != mem.width) {
|
||||
for (auto &port: mem.wr_ports) {
|
||||
for (auto &port : mem.wr_ports) {
|
||||
SigSpec new_data;
|
||||
SigSpec new_en;
|
||||
for (int sub = 0; sub < (1 << port.wide_log2); sub++) {
|
||||
for (auto i: swizzle) {
|
||||
for (auto i : swizzle) {
|
||||
new_data.append(port.data[sub * mem.width + i]);
|
||||
new_en.append(port.en[sub * mem.width + i]);
|
||||
}
|
||||
|
@ -173,13 +179,13 @@ struct OptMemPass : public Pass {
|
|||
port.data = new_data;
|
||||
port.en = new_en;
|
||||
}
|
||||
for (auto &port: mem.rd_ports) {
|
||||
for (auto &port : mem.rd_ports) {
|
||||
SigSpec new_data;
|
||||
Const new_init;
|
||||
Const new_arst;
|
||||
Const new_srst;
|
||||
for (int sub = 0; sub < (1 << port.wide_log2); sub++) {
|
||||
for (auto i: swizzle) {
|
||||
for (auto i : swizzle) {
|
||||
int bidx = sub * mem.width + i;
|
||||
new_data.append(port.data[bidx]);
|
||||
new_init.bits().push_back(port.init_value[bidx]);
|
||||
|
@ -192,15 +198,15 @@ struct OptMemPass : public Pass {
|
|||
port.arst_value = new_arst;
|
||||
port.srst_value = new_srst;
|
||||
}
|
||||
for (auto &init: mem.inits) {
|
||||
for (auto &init : mem.inits) {
|
||||
Const new_data;
|
||||
Const new_en;
|
||||
for (int s = 0; s < GetSize(init.data); s += mem.width) {
|
||||
for (auto i: swizzle) {
|
||||
for (auto i : swizzle) {
|
||||
new_data.bits().push_back(init.data[s + i]);
|
||||
}
|
||||
}
|
||||
for (auto i: swizzle) {
|
||||
for (auto i : swizzle) {
|
||||
new_en.bits().push_back(init.en[i]);
|
||||
}
|
||||
init.data = new_data;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue