2013-11-24 15:52:30 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-11-24 15:52:30 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-11-24 15:52:30 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
#include "simplemap.h"
|
2013-11-24 15:52:30 -06:00
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
2014-12-24 03:49:24 -06:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
2013-11-24 16:31:14 -06:00
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_not(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
sig_a.extend_u0(GetSize(sig_y), cell->parameters.at(ID::A_SIGNED).as_bool());
|
2014-07-23 09:09:27 -05:00
|
|
|
|
2014-10-10 09:59:44 -05:00
|
|
|
for (int i = 0; i < GetSize(sig_y); i++) {
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_NOT_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a[i]);
|
|
|
|
gate->setPort(ID::Y, sig_y[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_pos(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
sig_a.extend_u0(GetSize(sig_y), cell->parameters.at(ID::A_SIGNED).as_bool());
|
2014-07-23 09:09:27 -05:00
|
|
|
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(RTLIL::SigSig(sig_y, sig_a));
|
2013-12-28 04:54:40 -06:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_bitop(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
|
|
|
RTLIL::SigSpec sig_b = cell->getPort(ID::B);
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2014-07-23 09:09:27 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
sig_a.extend_u0(GetSize(sig_y), cell->parameters.at(ID::A_SIGNED).as_bool());
|
|
|
|
sig_b.extend_u0(GetSize(sig_y), cell->parameters.at(ID::B_SIGNED).as_bool());
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
if (cell->type == ID($xnor))
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2014-10-10 09:59:44 -05:00
|
|
|
RTLIL::SigSpec sig_t = module->addWire(NEW_ID, GetSize(sig_y));
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-10-10 09:59:44 -05:00
|
|
|
for (int i = 0; i < GetSize(sig_y); i++) {
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_NOT_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_t[i]);
|
|
|
|
gate->setPort(ID::Y, sig_y[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
sig_y = sig_t;
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type;
|
|
|
|
if (cell->type == ID($and)) gate_type = ID($_AND_);
|
|
|
|
if (cell->type == ID($or)) gate_type = ID($_OR_);
|
|
|
|
if (cell->type == ID($xor)) gate_type = ID($_XOR_);
|
|
|
|
if (cell->type == ID($xnor)) gate_type = ID($_XOR_);
|
2013-11-24 15:52:30 -06:00
|
|
|
log_assert(!gate_type.empty());
|
|
|
|
|
2014-10-10 09:59:44 -05:00
|
|
|
for (int i = 0; i < GetSize(sig_y); i++) {
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a[i]);
|
|
|
|
gate->setPort(ID::B, sig_b[i]);
|
|
|
|
gate->setPort(ID::Y, sig_y[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_reduce(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_y.size() == 0)
|
2013-11-24 15:52:30 -06:00
|
|
|
return;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_a.size() == 0) {
|
2019-08-15 12:05:08 -05:00
|
|
|
if (cell->type == ID($reduce_and)) module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(1, sig_y.size())));
|
|
|
|
if (cell->type == ID($reduce_or)) module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(0, sig_y.size())));
|
|
|
|
if (cell->type == ID($reduce_xor)) module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(0, sig_y.size())));
|
|
|
|
if (cell->type == ID($reduce_xnor)) module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(1, sig_y.size())));
|
|
|
|
if (cell->type == ID($reduce_bool)) module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(0, sig_y.size())));
|
2013-11-24 15:52:30 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_y.size() > 1) {
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(RTLIL::SigSig(sig_y.extract(1, sig_y.size()-1), RTLIL::SigSpec(0, sig_y.size()-1)));
|
2013-11-24 15:52:30 -06:00
|
|
|
sig_y = sig_y.extract(0, 1);
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type;
|
|
|
|
if (cell->type == ID($reduce_and)) gate_type = ID($_AND_);
|
|
|
|
if (cell->type == ID($reduce_or)) gate_type = ID($_OR_);
|
|
|
|
if (cell->type == ID($reduce_xor)) gate_type = ID($_XOR_);
|
|
|
|
if (cell->type == ID($reduce_xnor)) gate_type = ID($_XOR_);
|
|
|
|
if (cell->type == ID($reduce_bool)) gate_type = ID($_OR_);
|
2013-11-24 15:52:30 -06:00
|
|
|
log_assert(!gate_type.empty());
|
|
|
|
|
2014-07-26 08:57:57 -05:00
|
|
|
RTLIL::Cell *last_output_cell = NULL;
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
while (sig_a.size() > 1)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
RTLIL::SigSpec sig_t = module->addWire(NEW_ID, sig_a.size() / 2);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
for (int i = 0; i < sig_a.size(); i += 2)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
if (i+1 == sig_a.size()) {
|
2014-07-23 09:09:27 -05:00
|
|
|
sig_t.append(sig_a[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a[i]);
|
|
|
|
gate->setPort(ID::B, sig_a[i+1]);
|
|
|
|
gate->setPort(ID::Y, sig_t[i/2]);
|
2014-07-26 08:57:57 -05:00
|
|
|
last_output_cell = gate;
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
sig_a = sig_t;
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
if (cell->type == ID($reduce_xnor)) {
|
2014-07-21 05:35:06 -05:00
|
|
|
RTLIL::SigSpec sig_t = module->addWire(NEW_ID);
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_NOT_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a);
|
|
|
|
gate->setPort(ID::Y, sig_t);
|
2014-07-26 08:57:57 -05:00
|
|
|
last_output_cell = gate;
|
2013-11-24 15:52:30 -06:00
|
|
|
sig_a = sig_t;
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:57 -05:00
|
|
|
if (last_output_cell == NULL) {
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(RTLIL::SigSig(sig_y, sig_a));
|
2013-11-24 15:52:30 -06:00
|
|
|
} else {
|
2019-08-15 16:50:10 -05:00
|
|
|
last_output_cell->setPort(ID::Y, sig_y);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 15:04:05 -05:00
|
|
|
static void logic_reduce(RTLIL::Module *module, RTLIL::SigSpec &sig, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
while (sig.size() > 1)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
RTLIL::SigSpec sig_t = module->addWire(NEW_ID, sig.size() / 2);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
for (int i = 0; i < sig.size(); i += 2)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2014-07-22 13:15:14 -05:00
|
|
|
if (i+1 == sig.size()) {
|
2014-07-23 09:09:27 -05:00
|
|
|
sig_t.append(sig[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_OR_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig[i]);
|
|
|
|
gate->setPort(ID::B, sig[i+1]);
|
|
|
|
gate->setPort(ID::Y, sig_t[i/2]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
sig = sig_t;
|
|
|
|
}
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig.size() == 0)
|
2019-08-06 18:22:47 -05:00
|
|
|
sig = State::S0;
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_lognot(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
2015-04-24 15:04:05 -05:00
|
|
|
logic_reduce(module, sig_a, cell);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_y.size() == 0)
|
2013-11-24 15:52:30 -06:00
|
|
|
return;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_y.size() > 1) {
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(RTLIL::SigSig(sig_y.extract(1, sig_y.size()-1), RTLIL::SigSpec(0, sig_y.size()-1)));
|
2013-11-24 15:52:30 -06:00
|
|
|
sig_y = sig_y.extract(0, 1);
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_NOT_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a);
|
|
|
|
gate->setPort(ID::Y, sig_y);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_logbin(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
2015-04-24 15:04:05 -05:00
|
|
|
logic_reduce(module, sig_a, cell);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_b = cell->getPort(ID::B);
|
2015-04-24 15:04:05 -05:00
|
|
|
logic_reduce(module, sig_b, cell);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_y.size() == 0)
|
2013-11-24 15:52:30 -06:00
|
|
|
return;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig_y.size() > 1) {
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(RTLIL::SigSig(sig_y.extract(1, sig_y.size()-1), RTLIL::SigSpec(0, sig_y.size()-1)));
|
2013-11-24 15:52:30 -06:00
|
|
|
sig_y = sig_y.extract(0, 1);
|
|
|
|
}
|
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type;
|
|
|
|
if (cell->type == ID($logic_and)) gate_type = ID($_AND_);
|
|
|
|
if (cell->type == ID($logic_or)) gate_type = ID($_OR_);
|
2013-11-24 15:52:30 -06:00
|
|
|
log_assert(!gate_type.empty());
|
|
|
|
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a);
|
|
|
|
gate->setPort(ID::B, sig_b);
|
|
|
|
gate->setPort(ID::Y, sig_y);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_eqne(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
|
|
|
RTLIL::SigSpec sig_b = cell->getPort(ID::B);
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2020-04-02 11:51:32 -05:00
|
|
|
bool is_signed = cell->parameters.at(ID::A_SIGNED).as_bool();
|
2019-08-15 12:05:08 -05:00
|
|
|
bool is_ne = cell->type.in(ID($ne), ID($nex));
|
2014-12-24 03:49:24 -06:00
|
|
|
|
2015-10-25 13:30:49 -05:00
|
|
|
RTLIL::SigSpec xor_out = module->addWire(NEW_ID, max(GetSize(sig_a), GetSize(sig_b)));
|
2014-12-24 03:49:24 -06:00
|
|
|
RTLIL::Cell *xor_cell = module->addXor(NEW_ID, sig_a, sig_b, xor_out, is_signed);
|
2020-04-02 11:51:32 -05:00
|
|
|
xor_cell->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2014-12-24 03:49:24 -06:00
|
|
|
simplemap_bitop(module, xor_cell);
|
|
|
|
module->remove(xor_cell);
|
|
|
|
|
2014-12-25 09:41:20 -06:00
|
|
|
RTLIL::SigSpec reduce_out = is_ne ? sig_y : module->addWire(NEW_ID);
|
|
|
|
RTLIL::Cell *reduce_cell = module->addReduceOr(NEW_ID, xor_out, reduce_out);
|
2020-04-02 11:51:32 -05:00
|
|
|
reduce_cell->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2014-12-24 03:49:24 -06:00
|
|
|
simplemap_reduce(module, reduce_cell);
|
|
|
|
module->remove(reduce_cell);
|
2014-12-25 09:41:20 -06:00
|
|
|
|
|
|
|
if (!is_ne) {
|
|
|
|
RTLIL::Cell *not_cell = module->addLogicNot(NEW_ID, reduce_out, sig_y);
|
2020-04-02 11:51:32 -05:00
|
|
|
not_cell->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2014-12-25 09:41:20 -06:00
|
|
|
simplemap_lognot(module, not_cell);
|
|
|
|
module->remove(not_cell);
|
|
|
|
}
|
2014-12-24 03:49:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void simplemap_mux(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
|
|
|
RTLIL::SigSpec sig_b = cell->getPort(ID::B);
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-10-10 09:59:44 -05:00
|
|
|
for (int i = 0; i < GetSize(sig_y); i++) {
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_MUX_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a[i]);
|
|
|
|
gate->setPort(ID::B, sig_b[i]);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->setPort(ID::S, cell->getPort(ID::S));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::Y, sig_y[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 05:54:52 -05:00
|
|
|
void simplemap_tribuf(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_e = cell->getPort(ID::EN);
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2015-08-16 05:54:52 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < GetSize(sig_y); i++) {
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_TBUF_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, sig_a[i]);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->setPort(ID::E, sig_e);
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::Y, sig_y[i]);
|
2015-08-16 05:54:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 03:16:07 -05:00
|
|
|
void simplemap_lut(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
SigSpec lut_ctrl = cell->getPort(ID::A);
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec lut_data = cell->getParam(ID::LUT);
|
|
|
|
lut_data.extend_u0(1 << cell->getParam(ID::WIDTH).as_int());
|
2015-04-27 03:16:07 -05:00
|
|
|
|
|
|
|
for (int idx = 0; GetSize(lut_data) > 1; idx++) {
|
|
|
|
SigSpec sig_s = lut_ctrl[idx];
|
|
|
|
SigSpec new_lut_data = module->addWire(NEW_ID, GetSize(lut_data)/2);
|
|
|
|
for (int i = 0; i < GetSize(lut_data); i += 2) {
|
2019-08-15 12:05:08 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, ID($_MUX_));
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::A, lut_data[i]);
|
|
|
|
gate->setPort(ID::B, lut_data[i+1]);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->setPort(ID::S, lut_ctrl[idx]);
|
2019-08-15 16:50:10 -05:00
|
|
|
gate->setPort(ID::Y, new_lut_data[i/2]);
|
2015-04-27 03:16:07 -05:00
|
|
|
}
|
|
|
|
lut_data = new_lut_data;
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
module->connect(cell->getPort(ID::Y), lut_data);
|
2015-04-27 03:16:07 -05:00
|
|
|
}
|
|
|
|
|
2016-06-17 09:31:16 -05:00
|
|
|
void simplemap_sop(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
SigSpec ctrl = cell->getPort(ID::A);
|
2020-04-02 11:51:32 -05:00
|
|
|
SigSpec table = cell->getParam(ID::TABLE);
|
2016-06-17 09:31:16 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->getParam(ID::WIDTH).as_int();
|
|
|
|
int depth = cell->getParam(ID::DEPTH).as_int();
|
2016-06-17 09:31:16 -05:00
|
|
|
table.extend_u0(2 * width * depth);
|
|
|
|
|
|
|
|
SigSpec products;
|
|
|
|
|
|
|
|
for (int i = 0; i < depth; i++) {
|
|
|
|
SigSpec in, pat;
|
|
|
|
for (int j = 0; j < width; j++) {
|
|
|
|
if (table[2*i*width + 2*j + 0] == State::S1) {
|
|
|
|
in.append(ctrl[j]);
|
|
|
|
pat.append(State::S0);
|
|
|
|
}
|
|
|
|
if (table[2*i*width + 2*j + 1] == State::S1) {
|
|
|
|
in.append(ctrl[j]);
|
|
|
|
pat.append(State::S1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
products.append(GetSize(in) > 0 ? module->Eq(NEW_ID, in, pat) : State::S1);
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:50:10 -05:00
|
|
|
module->connect(cell->getPort(ID::Y), module->ReduceOr(NEW_ID, products));
|
2016-06-17 09:31:16 -05:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_slice(RTLIL::Module *module, RTLIL::Cell *cell)
|
2014-02-07 10:44:57 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int offset = cell->parameters.at(ID::OFFSET).as_int();
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_a = cell->getPort(ID::A);
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(RTLIL::SigSig(sig_y, sig_a.extract(offset, sig_y.size())));
|
2014-02-07 10:44:57 -06:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_concat(RTLIL::Module *module, RTLIL::Cell *cell)
|
2014-02-07 10:44:57 -06:00
|
|
|
{
|
2019-08-15 16:50:10 -05:00
|
|
|
RTLIL::SigSpec sig_ab = cell->getPort(ID::A);
|
|
|
|
sig_ab.append(cell->getPort(ID::B));
|
|
|
|
RTLIL::SigSpec sig_y = cell->getPort(ID::Y);
|
2014-07-26 07:32:50 -05:00
|
|
|
module->connect(RTLIL::SigSig(sig_y, sig_ab));
|
2014-02-07 10:44:57 -06:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_sr(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char set_pol = cell->parameters.at(ID::SET_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char clr_pol = cell->parameters.at(ID::CLR_POLARITY).as_bool() ? 'P' : 'N';
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_s = cell->getPort(ID::SET);
|
|
|
|
RTLIL::SigSpec sig_r = cell->getPort(ID::CLR);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
|
|
|
std::string gate_type = stringf("$_SR_%c%c_", set_pol, clr_pol);
|
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::S, sig_s[i]);
|
|
|
|
gate->setPort(ID::R, sig_r[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 18:18:39 -05:00
|
|
|
void simplemap_ff(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
2016-10-11 18:18:39 -05:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
2016-10-11 18:18:39 -05:00
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type = ID($_FF_);
|
2016-10-11 18:18:39 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
2016-10-11 18:18:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_dff(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char clk_pol = cell->parameters.at(ID::CLK_POLARITY).as_bool() ? 'P' : 'N';
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_clk = cell->getPort(ID::CLK);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type = stringf("$_DFF_%c_", clk_pol);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::C, sig_clk);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_dffe(RTLIL::Module *module, RTLIL::Cell *cell)
|
2014-12-08 03:50:19 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char clk_pol = cell->parameters.at(ID::CLK_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char en_pol = cell->parameters.at(ID::EN_POLARITY).as_bool() ? 'P' : 'N';
|
2014-12-08 03:50:19 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_clk = cell->getPort(ID::CLK);
|
|
|
|
RTLIL::SigSpec sig_en = cell->getPort(ID::EN);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
2014-12-08 03:50:19 -06:00
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type = stringf("$_DFFE_%c%c_", clk_pol, en_pol);
|
2014-12-08 03:50:19 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::C, sig_clk);
|
|
|
|
gate->setPort(ID::E, sig_en);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
2014-12-08 03:50:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_dffsr(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char clk_pol = cell->parameters.at(ID::CLK_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char set_pol = cell->parameters.at(ID::SET_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char clr_pol = cell->parameters.at(ID::CLR_POLARITY).as_bool() ? 'P' : 'N';
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_clk = cell->getPort(ID::CLK);
|
|
|
|
RTLIL::SigSpec sig_s = cell->getPort(ID::SET);
|
|
|
|
RTLIL::SigSpec sig_r = cell->getPort(ID::CLR);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type = stringf("$_DFFSR_%c%c%c_", clk_pol, set_pol, clr_pol);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::C, sig_clk);
|
|
|
|
gate->setPort(ID::S, sig_s[i]);
|
|
|
|
gate->setPort(ID::R, sig_r[i]);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:55:56 -05:00
|
|
|
void simplemap_dffsre(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char clk_pol = cell->parameters.at(ID::CLK_POLARITY).as_bool() ? 'P' : 'N';
|
2020-04-08 20:55:56 -05:00
|
|
|
char set_pol = cell->parameters.at(ID::SET_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char clr_pol = cell->parameters.at(ID::CLR_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char en_pol = cell->parameters.at(ID::EN_POLARITY).as_bool() ? 'P' : 'N';
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-08 20:55:56 -05:00
|
|
|
RTLIL::SigSpec sig_clk = cell->getPort(ID::CLK);
|
|
|
|
RTLIL::SigSpec sig_s = cell->getPort(ID::SET);
|
|
|
|
RTLIL::SigSpec sig_r = cell->getPort(ID::CLR);
|
|
|
|
RTLIL::SigSpec sig_e = cell->getPort(ID::EN);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
|
|
|
|
|
|
|
IdString gate_type = stringf("$_DFFSR_%c%c%c%c_", clk_pol, set_pol, clr_pol, en_pol);
|
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::C, sig_clk);
|
|
|
|
gate->setPort(ID::S, sig_s[i]);
|
|
|
|
gate->setPort(ID::R, sig_r[i]);
|
|
|
|
gate->setPort(ID::E, sig_e);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void simplemap_adff_sdff(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
bool is_async = cell->type == ID($adff);
|
|
|
|
char clk_pol = cell->parameters.at(ID::CLK_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char rst_pol = cell->parameters.at(is_async ? ID::ARST_POLARITY : ID::SRST_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
const char *type = is_async ? "DFF" : "SDFF";
|
|
|
|
|
|
|
|
std::vector<RTLIL::State> rst_val = cell->parameters.at(is_async ? ID::ARST_VALUE : ID::SRST_VALUE).bits;
|
2013-11-24 15:52:30 -06:00
|
|
|
while (int(rst_val.size()) < width)
|
|
|
|
rst_val.push_back(RTLIL::State::S0);
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_clk = cell->getPort(ID::CLK);
|
2020-04-08 20:55:56 -05:00
|
|
|
RTLIL::SigSpec sig_rst = cell->getPort(is_async ? ID::ARST : ID::SRST);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
|
|
|
|
|
|
|
IdString gate_type_0 = stringf("$_%s_%c%c0_", type, clk_pol, rst_pol);
|
|
|
|
IdString gate_type_1 = stringf("$_%s_%c%c1_", type, clk_pol, rst_pol);
|
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, rst_val.at(i) == RTLIL::State::S1 ? gate_type_1 : gate_type_0);
|
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::C, sig_clk);
|
|
|
|
gate->setPort(ID::R, sig_rst);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void simplemap_adffe_sdffe_sdffce(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
bool is_async = cell->type == ID($adffe);
|
|
|
|
char clk_pol = cell->parameters.at(ID::CLK_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char rst_pol = cell->parameters.at(is_async ? ID::ARST_POLARITY : ID::SRST_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char en_pol = cell->parameters.at(ID::EN_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
const char *type = is_async ? "DFFE" : cell->type == ID($sdffe) ? "SDFFE" : "SDFFCE";
|
|
|
|
|
|
|
|
std::vector<RTLIL::State> rst_val = cell->parameters.at(is_async ? ID::ARST_VALUE : ID::SRST_VALUE).bits;
|
|
|
|
while (int(rst_val.size()) < width)
|
|
|
|
rst_val.push_back(RTLIL::State::S0);
|
|
|
|
|
|
|
|
RTLIL::SigSpec sig_clk = cell->getPort(ID::CLK);
|
|
|
|
RTLIL::SigSpec sig_rst = cell->getPort(is_async ? ID::ARST : ID::SRST);
|
|
|
|
RTLIL::SigSpec sig_e = cell->getPort(ID::EN);
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-08 20:55:56 -05:00
|
|
|
IdString gate_type_0 = stringf("$_%s_%c%c0%c_", type, clk_pol, rst_pol, en_pol);
|
|
|
|
IdString gate_type_1 = stringf("$_%s_%c%c1%c_", type, clk_pol, rst_pol, en_pol);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, rst_val.at(i) == RTLIL::State::S1 ? gate_type_1 : gate_type_0);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::C, sig_clk);
|
|
|
|
gate->setPort(ID::R, sig_rst);
|
2020-04-08 20:55:56 -05:00
|
|
|
gate->setPort(ID::E, sig_e);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap_dlatch(RTLIL::Module *module, RTLIL::Cell *cell)
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2020-04-02 11:51:32 -05:00
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char en_pol = cell->parameters.at(ID::EN_POLARITY).as_bool() ? 'P' : 'N';
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec sig_en = cell->getPort(ID::EN);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2019-08-15 12:05:08 -05:00
|
|
|
IdString gate_type = stringf("$_DLATCH_%c_", en_pol);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
2014-07-25 08:05:18 -05:00
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
2020-04-02 11:51:32 -05:00
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::E, sig_en);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:55:56 -05:00
|
|
|
void simplemap_adlatch(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char en_pol = cell->parameters.at(ID::EN_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char rst_pol = cell->parameters.at(ID::ARST_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
|
|
|
|
std::vector<RTLIL::State> rst_val = cell->parameters.at(ID::ARST_VALUE).bits;
|
|
|
|
while (int(rst_val.size()) < width)
|
|
|
|
rst_val.push_back(RTLIL::State::S0);
|
|
|
|
|
|
|
|
RTLIL::SigSpec sig_en = cell->getPort(ID::EN);
|
|
|
|
RTLIL::SigSpec sig_rst = cell->getPort(ID::ARST);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
|
|
|
|
|
|
|
IdString gate_type_0 = stringf("$_DLATCH_%c%c0_", en_pol, rst_pol);
|
|
|
|
IdString gate_type_1 = stringf("$_DLATCH_%c%c1_", en_pol, rst_pol);
|
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, rst_val.at(i) == RTLIL::State::S1 ? gate_type_1 : gate_type_0);
|
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::E, sig_en);
|
|
|
|
gate->setPort(ID::R, sig_rst);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void simplemap_dlatchsr(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
|
|
|
int width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
char en_pol = cell->parameters.at(ID::EN_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char set_pol = cell->parameters.at(ID::SET_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
char clr_pol = cell->parameters.at(ID::CLR_POLARITY).as_bool() ? 'P' : 'N';
|
|
|
|
|
|
|
|
RTLIL::SigSpec sig_en = cell->getPort(ID::EN);
|
|
|
|
RTLIL::SigSpec sig_s = cell->getPort(ID::SET);
|
|
|
|
RTLIL::SigSpec sig_r = cell->getPort(ID::CLR);
|
|
|
|
RTLIL::SigSpec sig_d = cell->getPort(ID::D);
|
|
|
|
RTLIL::SigSpec sig_q = cell->getPort(ID::Q);
|
|
|
|
|
|
|
|
IdString gate_type = stringf("$_DLATCHSR_%c%c%c_", en_pol, set_pol, clr_pol);
|
|
|
|
|
|
|
|
for (int i = 0; i < width; i++) {
|
|
|
|
RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
|
|
|
|
gate->add_strpool_attribute(ID::src, cell->get_strpool_attribute(ID::src));
|
|
|
|
gate->setPort(ID::E, sig_en);
|
|
|
|
gate->setPort(ID::S, sig_s[i]);
|
|
|
|
gate->setPort(ID::R, sig_r[i]);
|
|
|
|
gate->setPort(ID::D, sig_d[i]);
|
|
|
|
gate->setPort(ID::Q, sig_q[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:50:23 -05:00
|
|
|
void simplemap_get_mappers(dict<IdString, void(*)(RTLIL::Module*, RTLIL::Cell*)> &mappers)
|
2013-11-24 16:31:14 -06:00
|
|
|
{
|
2019-08-15 12:05:08 -05:00
|
|
|
mappers[ID($not)] = simplemap_not;
|
|
|
|
mappers[ID($pos)] = simplemap_pos;
|
|
|
|
mappers[ID($and)] = simplemap_bitop;
|
|
|
|
mappers[ID($or)] = simplemap_bitop;
|
|
|
|
mappers[ID($xor)] = simplemap_bitop;
|
|
|
|
mappers[ID($xnor)] = simplemap_bitop;
|
|
|
|
mappers[ID($reduce_and)] = simplemap_reduce;
|
|
|
|
mappers[ID($reduce_or)] = simplemap_reduce;
|
|
|
|
mappers[ID($reduce_xor)] = simplemap_reduce;
|
|
|
|
mappers[ID($reduce_xnor)] = simplemap_reduce;
|
|
|
|
mappers[ID($reduce_bool)] = simplemap_reduce;
|
|
|
|
mappers[ID($logic_not)] = simplemap_lognot;
|
|
|
|
mappers[ID($logic_and)] = simplemap_logbin;
|
|
|
|
mappers[ID($logic_or)] = simplemap_logbin;
|
|
|
|
mappers[ID($eq)] = simplemap_eqne;
|
|
|
|
mappers[ID($eqx)] = simplemap_eqne;
|
|
|
|
mappers[ID($ne)] = simplemap_eqne;
|
|
|
|
mappers[ID($nex)] = simplemap_eqne;
|
|
|
|
mappers[ID($mux)] = simplemap_mux;
|
|
|
|
mappers[ID($tribuf)] = simplemap_tribuf;
|
|
|
|
mappers[ID($lut)] = simplemap_lut;
|
|
|
|
mappers[ID($sop)] = simplemap_sop;
|
|
|
|
mappers[ID($slice)] = simplemap_slice;
|
|
|
|
mappers[ID($concat)] = simplemap_concat;
|
|
|
|
mappers[ID($sr)] = simplemap_sr;
|
|
|
|
mappers[ID($ff)] = simplemap_ff;
|
|
|
|
mappers[ID($dff)] = simplemap_dff;
|
|
|
|
mappers[ID($dffe)] = simplemap_dffe;
|
|
|
|
mappers[ID($dffsr)] = simplemap_dffsr;
|
2020-04-08 20:55:56 -05:00
|
|
|
mappers[ID($dffsre)] = simplemap_dffsre;
|
|
|
|
mappers[ID($adff)] = simplemap_adff_sdff;
|
|
|
|
mappers[ID($sdff)] = simplemap_adff_sdff;
|
|
|
|
mappers[ID($adffe)] = simplemap_adffe_sdffe_sdffce;
|
|
|
|
mappers[ID($sdffe)] = simplemap_adffe_sdffe_sdffce;
|
|
|
|
mappers[ID($sdffce)] = simplemap_adffe_sdffe_sdffce;
|
2019-08-15 12:05:08 -05:00
|
|
|
mappers[ID($dlatch)] = simplemap_dlatch;
|
2020-04-08 20:55:56 -05:00
|
|
|
mappers[ID($adlatch)] = simplemap_adlatch;
|
|
|
|
mappers[ID($dlatchsr)] = simplemap_dlatchsr;
|
2013-11-24 16:31:14 -06:00
|
|
|
}
|
|
|
|
|
2014-12-24 03:49:24 -06:00
|
|
|
void simplemap(RTLIL::Module *module, RTLIL::Cell *cell)
|
|
|
|
{
|
2020-04-14 12:50:23 -05:00
|
|
|
static dict<IdString, void(*)(RTLIL::Module*, RTLIL::Cell*)> mappers;
|
2014-12-24 03:49:24 -06:00
|
|
|
static bool initialized_mappers = false;
|
|
|
|
|
|
|
|
if (!initialized_mappers) {
|
|
|
|
simplemap_get_mappers(mappers);
|
|
|
|
initialized_mappers = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mappers.at(cell->type)(module, cell);
|
|
|
|
}
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
YOSYS_NAMESPACE_END
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2013-11-24 15:52:30 -06:00
|
|
|
struct SimplemapPass : public Pass {
|
|
|
|
SimplemapPass() : Pass("simplemap", "mapping simple coarse-grain cells") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" simplemap [selection]\n");
|
|
|
|
log("\n");
|
|
|
|
log("This pass maps a small selection of simple coarse-grain cells to yosys gate\n");
|
|
|
|
log("primitives. The following internal cell types are mapped by this pass:\n");
|
|
|
|
log("\n");
|
2014-09-03 19:07:52 -05:00
|
|
|
log(" $not, $pos, $and, $or, $xor, $xnor\n");
|
2013-11-24 15:52:30 -06:00
|
|
|
log(" $reduce_and, $reduce_or, $reduce_xor, $reduce_xnor, $reduce_bool\n");
|
2015-08-16 05:54:52 -05:00
|
|
|
log(" $logic_not, $logic_and, $logic_or, $mux, $tribuf\n");
|
2020-04-08 20:55:56 -05:00
|
|
|
log(" $sr, $ff, $dff, $dffe, $dffsr, $dffsre, $adff, $adffe, $sdff, $sdffe, $sdffce, $dlatch, $adlatch, $dlatchsr\n");
|
2013-11-24 15:52:30 -06:00
|
|
|
log("\n");
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2013-11-24 15:52:30 -06:00
|
|
|
{
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing SIMPLEMAP pass (map simple cells to gate primitives).\n");
|
2013-11-24 15:52:30 -06:00
|
|
|
extra_args(args, 1, design);
|
|
|
|
|
2020-04-14 12:50:23 -05:00
|
|
|
dict<IdString, void(*)(RTLIL::Module*, RTLIL::Cell*)> mappers;
|
2013-11-24 16:31:14 -06:00
|
|
|
simplemap_get_mappers(mappers);
|
2013-11-24 15:52:30 -06:00
|
|
|
|
2014-07-27 03:41:42 -05:00
|
|
|
for (auto mod : design->modules()) {
|
2019-04-20 04:10:05 -05:00
|
|
|
if (!design->selected(mod) || mod->get_blackbox_attribute())
|
2013-11-24 15:52:30 -06:00
|
|
|
continue;
|
2014-07-27 03:41:42 -05:00
|
|
|
std::vector<RTLIL::Cell*> cells = mod->cells();
|
|
|
|
for (auto cell : cells) {
|
|
|
|
if (mappers.count(cell->type) == 0)
|
2013-11-24 15:52:30 -06:00
|
|
|
continue;
|
2014-07-27 03:41:42 -05:00
|
|
|
if (!design->selected(mod, cell))
|
2013-11-24 15:52:30 -06:00
|
|
|
continue;
|
2014-07-27 03:41:42 -05:00
|
|
|
log("Mapping %s.%s (%s).\n", log_id(mod), log_id(cell), log_id(cell->type));
|
|
|
|
mappers.at(cell->type)(mod, cell);
|
|
|
|
mod->remove(cell);
|
2013-11-24 15:52:30 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} SimplemapPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|