37 for (
int i = 0; i <
GetSize(sig_y); i++) {
63 if (cell->
type ==
"$xnor")
67 for (
int i = 0; i <
GetSize(sig_y); i++) {
76 std::string gate_type;
77 if (cell->
type ==
"$and") gate_type =
"$_AND_";
78 if (cell->
type ==
"$or") gate_type =
"$_OR_";
79 if (cell->
type ==
"$xor") gate_type =
"$_XOR_";
80 if (cell->
type ==
"$xnor") gate_type =
"$_XOR_";
83 for (
int i = 0; i <
GetSize(sig_y); i++) {
96 if (sig_y.
size() == 0)
99 if (sig_a.
size() == 0) {
108 if (sig_y.
size() > 1) {
113 std::string gate_type;
114 if (cell->
type ==
"$reduce_and") gate_type =
"$_AND_";
115 if (cell->
type ==
"$reduce_or") gate_type =
"$_OR_";
116 if (cell->
type ==
"$reduce_xor") gate_type =
"$_XOR_";
117 if (cell->
type ==
"$reduce_xnor") gate_type =
"$_XOR_";
118 if (cell->
type ==
"$reduce_bool") gate_type =
"$_OR_";
123 while (sig_a.
size() > 1)
127 for (
int i = 0; i < sig_a.
size(); i += 2)
129 if (i+1 == sig_a.
size()) {
135 gate->
setPort(
"\\A", sig_a[i]);
136 gate->
setPort(
"\\B", sig_a[i+1]);
137 gate->
setPort(
"\\Y", sig_t[i/2]);
138 last_output_cell = gate;
144 if (cell->
type ==
"$reduce_xnor") {
149 last_output_cell = gate;
153 if (last_output_cell ==
NULL) {
156 last_output_cell->setPort(
"\\Y", sig_y);
162 while (sig.
size() > 1)
166 for (
int i = 0; i < sig.
size(); i += 2)
168 if (i+1 == sig.
size()) {
175 gate->
setPort(
"\\B", sig[i+1]);
176 gate->
setPort(
"\\Y", sig_t[i/2]);
193 if (sig_y.
size() == 0)
196 if (sig_y.
size() > 1) {
216 if (sig_y.
size() == 0)
219 if (sig_y.
size() > 1) {
224 std::string gate_type;
225 if (cell->
type ==
"$logic_and") gate_type =
"$_AND_";
226 if (cell->
type ==
"$logic_or") gate_type =
"$_OR_";
231 gate->setPort(
"\\B", sig_b);
232 gate->setPort(
"\\Y", sig_y);
241 for (
int i = 0; i <
GetSize(sig_y); i++) {
243 gate->
setPort(
"\\A", sig_a[i]);
244 gate->
setPort(
"\\B", sig_b[i]);
246 gate->
setPort(
"\\Y", sig_y[i]);
252 int offset = cell->
parameters.at(
"\\OFFSET").as_int();
268 int width = cell->
parameters.at(
"\\WIDTH").as_int();
269 char set_pol = cell->
parameters.at(
"\\SET_POLARITY").as_bool() ?
'P' :
'N';
270 char clr_pol = cell->
parameters.at(
"\\CLR_POLARITY").as_bool() ?
'P' :
'N';
276 std::string gate_type =
stringf(
"$_SR_%c%c_", set_pol, clr_pol);
278 for (
int i = 0; i < width; i++) {
280 gate->
setPort(
"\\S", sig_s[i]);
281 gate->
setPort(
"\\R", sig_r[i]);
282 gate->
setPort(
"\\Q", sig_q[i]);
288 int width = cell->
parameters.at(
"\\WIDTH").as_int();
289 char clk_pol = cell->
parameters.at(
"\\CLK_POLARITY").as_bool() ?
'P' :
'N';
295 std::string gate_type =
stringf(
"$_DFF_%c_", clk_pol);
297 for (
int i = 0; i < width; i++) {
300 gate->
setPort(
"\\D", sig_d[i]);
301 gate->
setPort(
"\\Q", sig_q[i]);
307 int width = cell->
parameters.at(
"\\WIDTH").as_int();
308 char clk_pol = cell->
parameters.at(
"\\CLK_POLARITY").as_bool() ?
'P' :
'N';
309 char en_pol = cell->
parameters.at(
"\\EN_POLARITY").as_bool() ?
'P' :
'N';
316 std::string gate_type =
stringf(
"$_DFFE_%c%c_", clk_pol, en_pol);
318 for (
int i = 0; i < width; i++) {
322 gate->
setPort(
"\\D", sig_d[i]);
323 gate->
setPort(
"\\Q", sig_q[i]);
329 int width = cell->
parameters.at(
"\\WIDTH").as_int();
330 char clk_pol = cell->
parameters.at(
"\\CLK_POLARITY").as_bool() ?
'P' :
'N';
331 char set_pol = cell->
parameters.at(
"\\SET_POLARITY").as_bool() ?
'P' :
'N';
332 char clr_pol = cell->
parameters.at(
"\\CLR_POLARITY").as_bool() ?
'P' :
'N';
340 std::string gate_type =
stringf(
"$_DFFSR_%c%c%c_", clk_pol, set_pol, clr_pol);
342 for (
int i = 0; i < width; i++) {
345 gate->
setPort(
"\\S", sig_s[i]);
346 gate->
setPort(
"\\R", sig_r[i]);
347 gate->
setPort(
"\\D", sig_d[i]);
348 gate->
setPort(
"\\Q", sig_q[i]);
354 int width = cell->
parameters.at(
"\\WIDTH").as_int();
355 char clk_pol = cell->
parameters.at(
"\\CLK_POLARITY").as_bool() ?
'P' :
'N';
356 char rst_pol = cell->
parameters.at(
"\\ARST_POLARITY").as_bool() ?
'P' :
'N';
358 std::vector<RTLIL::State> rst_val = cell->
parameters.at(
"\\ARST_VALUE").bits;
359 while (
int(rst_val.size()) < width)
367 std::string gate_type_0 =
stringf(
"$_DFF_%c%c0_", clk_pol, rst_pol);
368 std::string gate_type_1 =
stringf(
"$_DFF_%c%c1_", clk_pol, rst_pol);
370 for (
int i = 0; i < width; i++) {
374 gate->
setPort(
"\\D", sig_d[i]);
375 gate->
setPort(
"\\Q", sig_q[i]);
381 int width = cell->
parameters.at(
"\\WIDTH").as_int();
382 char en_pol = cell->
parameters.at(
"\\EN_POLARITY").as_bool() ?
'P' :
'N';
388 std::string gate_type =
stringf(
"$_DLATCH_%c_", en_pol);
390 for (
int i = 0; i < width; i++) {
393 gate->
setPort(
"\\D", sig_d[i]);
394 gate->
setPort(
"\\Q", sig_q[i]);
439 log(
" simplemap [selection]\n");
441 log(
"This pass maps a small selection of simple coarse-grain cells to yosys gate\n");
442 log(
"primitives. The following internal cell types are mapped by this pass:\n");
444 log(
" $not, $pos, $and, $or, $xor, $xnor\n");
445 log(
" $reduce_and, $reduce_or, $reduce_xor, $reduce_xnor, $reduce_bool\n");
446 log(
" $logic_not, $logic_and, $logic_or, $mux\n");
447 log(
" $sr, $dff, $dffsr, $adff, $dlatch\n");
452 log_header(
"Executing SIMPLEMAP pass (map simple cells to gate primitives).\n");
455 std::map<RTLIL::IdString, void(*)(RTLIL::Module*, RTLIL::Cell*)> mappers;
458 for (
auto mod : design->
modules()) {
461 std::vector<RTLIL::Cell*> cells = mod->cells();
462 for (
auto cell : cells) {
463 if (mappers.count(cell->type) == 0)
468 mappers.at(cell->type)(mod, cell);
bool selected(T1 *module) const
static void simplemap_bitop(RTLIL::Module *module, RTLIL::Cell *cell)
static void simplemap_lognot(RTLIL::Module *module, RTLIL::Cell *cell)
std::string stringf(const char *fmt,...)
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
void log_header(const char *format,...)
#define YOSYS_NAMESPACE_END
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
std::map< RTLIL::IdString, RTLIL::Const > parameters
void extend_u0(int width, bool is_signed=false)
static void simplemap_pos(RTLIL::Module *module, RTLIL::Cell *cell)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
static void simplemap_dffsr(RTLIL::Module *module, RTLIL::Cell *cell)
static void simplemap_dff(RTLIL::Module *module, RTLIL::Cell *cell)
static void simplemap_mux(RTLIL::Module *module, RTLIL::Cell *cell)
static void simplemap_dffe(RTLIL::Module *module, RTLIL::Cell *cell)
void connect(const RTLIL::SigSig &conn)
static void simplemap_concat(RTLIL::Module *module, RTLIL::Cell *cell)
#define PRIVATE_NAMESPACE_BEGIN
SimplemapPass SimplemapPass
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
PRIVATE_NAMESPACE_END YOSYS_NAMESPACE_BEGIN void simplemap_get_mappers(std::map< RTLIL::IdString, void(*)(RTLIL::Module *, RTLIL::Cell *)> &mappers)
int GetSize(RTLIL::Wire *wire)
static void simplemap_sr(RTLIL::Module *module, RTLIL::Cell *cell)
#define log_assert(_assert_expr_)
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
#define PRIVATE_NAMESPACE_END
static void logic_reduce(RTLIL::Module *module, RTLIL::SigSpec &sig)
static void simplemap_slice(RTLIL::Module *module, RTLIL::Cell *cell)
#define USING_YOSYS_NAMESPACE
RTLIL::ObjRange< RTLIL::Module * > modules()
#define YOSYS_NAMESPACE_BEGIN
static void simplemap_adff(RTLIL::Module *module, RTLIL::Cell *cell)
static void simplemap_reduce(RTLIL::Module *module, RTLIL::Cell *cell)
void log(const char *format,...)
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
void append(const RTLIL::SigSpec &signal)
void extend(int width, bool is_signed=false)
static void simplemap_dlatch(RTLIL::Module *module, RTLIL::Cell *cell)
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN void simplemap_not(RTLIL::Module *module, RTLIL::Cell *cell)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
std::pair< SigSpec, SigSpec > SigSig
static void simplemap_logbin(RTLIL::Module *module, RTLIL::Cell *cell)
const char * log_id(RTLIL::IdString str)