yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
simplemap.cc File Reference
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/log.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+ Include dependency graph for simplemap.cc:

Go to the source code of this file.

Data Structures

struct  SimplemapPass
 

Functions

USING_YOSYS_NAMESPACE static
PRIVATE_NAMESPACE_BEGIN void 
simplemap_not (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_pos (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_bitop (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_reduce (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void logic_reduce (RTLIL::Module *module, RTLIL::SigSpec &sig)
 
static void simplemap_lognot (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_logbin (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_mux (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_slice (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_concat (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_sr (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_dff (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_dffe (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_dffsr (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_adff (RTLIL::Module *module, RTLIL::Cell *cell)
 
static void simplemap_dlatch (RTLIL::Module *module, RTLIL::Cell *cell)
 
PRIVATE_NAMESPACE_END
YOSYS_NAMESPACE_BEGIN void 
simplemap_get_mappers (std::map< RTLIL::IdString, void(*)(RTLIL::Module *, RTLIL::Cell *)> &mappers)
 

Variables

SimplemapPass SimplemapPass
 

Function Documentation

static void logic_reduce ( RTLIL::Module module,
RTLIL::SigSpec sig 
)
static

Definition at line 160 of file simplemap.cc.

161 {
162  while (sig.size() > 1)
163  {
164  RTLIL::SigSpec sig_t = module->addWire(NEW_ID, sig.size() / 2);
165 
166  for (int i = 0; i < sig.size(); i += 2)
167  {
168  if (i+1 == sig.size()) {
169  sig_t.append(sig[i]);
170  continue;
171  }
172 
173  RTLIL::Cell *gate = module->addCell(NEW_ID, "$_OR_");
174  gate->setPort("\\A", sig[i]);
175  gate->setPort("\\B", sig[i+1]);
176  gate->setPort("\\Y", sig_t[i/2]);
177  }
178 
179  sig = sig_t;
180  }
181 
182  if (sig.size() == 0)
183  sig = RTLIL::SigSpec(0, 1);
184 }
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
int size() const
Definition: rtlil.h:1019
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
#define NEW_ID
Definition: yosys.h:166
void append(const RTLIL::SigSpec &signal)
Definition: rtlil.cc:2523

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_adff ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 352 of file simplemap.cc.

353 {
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';
357 
358  std::vector<RTLIL::State> rst_val = cell->parameters.at("\\ARST_VALUE").bits;
359  while (int(rst_val.size()) < width)
360  rst_val.push_back(RTLIL::State::S0);
361 
362  RTLIL::SigSpec sig_clk = cell->getPort("\\CLK");
363  RTLIL::SigSpec sig_rst = cell->getPort("\\ARST");
364  RTLIL::SigSpec sig_d = cell->getPort("\\D");
365  RTLIL::SigSpec sig_q = cell->getPort("\\Q");
366 
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);
369 
370  for (int i = 0; i < width; i++) {
371  RTLIL::Cell *gate = module->addCell(NEW_ID, rst_val.at(i) == RTLIL::State::S1 ? gate_type_1 : gate_type_0);
372  gate->setPort("\\C", sig_clk);
373  gate->setPort("\\R", sig_rst);
374  gate->setPort("\\D", sig_d[i]);
375  gate->setPort("\\Q", sig_q[i]);
376  }
377 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_bitop ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 54 of file simplemap.cc.

55 {
56  RTLIL::SigSpec sig_a = cell->getPort("\\A");
57  RTLIL::SigSpec sig_b = cell->getPort("\\B");
58  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
59 
60  sig_a.extend_u0(GetSize(sig_y), cell->parameters.at("\\A_SIGNED").as_bool());
61  sig_b.extend_u0(GetSize(sig_y), cell->parameters.at("\\B_SIGNED").as_bool());
62 
63  if (cell->type == "$xnor")
64  {
65  RTLIL::SigSpec sig_t = module->addWire(NEW_ID, GetSize(sig_y));
66 
67  for (int i = 0; i < GetSize(sig_y); i++) {
68  RTLIL::Cell *gate = module->addCell(NEW_ID, "$_NOT_");
69  gate->setPort("\\A", sig_t[i]);
70  gate->setPort("\\Y", sig_y[i]);
71  }
72 
73  sig_y = sig_t;
74  }
75 
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_";
81  log_assert(!gate_type.empty());
82 
83  for (int i = 0; i < GetSize(sig_y); i++) {
84  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
85  gate->setPort("\\A", sig_a[i]);
86  gate->setPort("\\B", sig_b[i]);
87  gate->setPort("\\Y", sig_y[i]);
88  }
89 }
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
RTLIL::IdString type
Definition: rtlil.h:854
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
void extend_u0(int width, bool is_signed=false)
Definition: rtlil.cc:2612
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
#define log_assert(_assert_expr_)
Definition: log.h:85
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_concat ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 258 of file simplemap.cc.

259 {
260  RTLIL::SigSpec sig_ab = cell->getPort("\\A");
261  sig_ab.append(cell->getPort("\\B"));
262  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
263  module->connect(RTLIL::SigSig(sig_y, sig_ab));
264 }
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
void append(const RTLIL::SigSpec &signal)
Definition: rtlil.cc:2523
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_dff ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 286 of file simplemap.cc.

287 {
288  int width = cell->parameters.at("\\WIDTH").as_int();
289  char clk_pol = cell->parameters.at("\\CLK_POLARITY").as_bool() ? 'P' : 'N';
290 
291  RTLIL::SigSpec sig_clk = cell->getPort("\\CLK");
292  RTLIL::SigSpec sig_d = cell->getPort("\\D");
293  RTLIL::SigSpec sig_q = cell->getPort("\\Q");
294 
295  std::string gate_type = stringf("$_DFF_%c_", clk_pol);
296 
297  for (int i = 0; i < width; i++) {
298  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
299  gate->setPort("\\C", sig_clk);
300  gate->setPort("\\D", sig_d[i]);
301  gate->setPort("\\Q", sig_q[i]);
302  }
303 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_dffe ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 305 of file simplemap.cc.

306 {
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';
310 
311  RTLIL::SigSpec sig_clk = cell->getPort("\\CLK");
312  RTLIL::SigSpec sig_en = cell->getPort("\\EN");
313  RTLIL::SigSpec sig_d = cell->getPort("\\D");
314  RTLIL::SigSpec sig_q = cell->getPort("\\Q");
315 
316  std::string gate_type = stringf("$_DFFE_%c%c_", clk_pol, en_pol);
317 
318  for (int i = 0; i < width; i++) {
319  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
320  gate->setPort("\\C", sig_clk);
321  gate->setPort("\\E", sig_en);
322  gate->setPort("\\D", sig_d[i]);
323  gate->setPort("\\Q", sig_q[i]);
324  }
325 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_dffsr ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 327 of file simplemap.cc.

328 {
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';
333 
334  RTLIL::SigSpec sig_clk = cell->getPort("\\CLK");
335  RTLIL::SigSpec sig_s = cell->getPort("\\SET");
336  RTLIL::SigSpec sig_r = cell->getPort("\\CLR");
337  RTLIL::SigSpec sig_d = cell->getPort("\\D");
338  RTLIL::SigSpec sig_q = cell->getPort("\\Q");
339 
340  std::string gate_type = stringf("$_DFFSR_%c%c%c_", clk_pol, set_pol, clr_pol);
341 
342  for (int i = 0; i < width; i++) {
343  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
344  gate->setPort("\\C", sig_clk);
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]);
349  }
350 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_dlatch ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 379 of file simplemap.cc.

380 {
381  int width = cell->parameters.at("\\WIDTH").as_int();
382  char en_pol = cell->parameters.at("\\EN_POLARITY").as_bool() ? 'P' : 'N';
383 
384  RTLIL::SigSpec sig_en = cell->getPort("\\EN");
385  RTLIL::SigSpec sig_d = cell->getPort("\\D");
386  RTLIL::SigSpec sig_q = cell->getPort("\\Q");
387 
388  std::string gate_type = stringf("$_DLATCH_%c_", en_pol);
389 
390  for (int i = 0; i < width; i++) {
391  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
392  gate->setPort("\\E", sig_en);
393  gate->setPort("\\D", sig_d[i]);
394  gate->setPort("\\Q", sig_q[i]);
395  }
396 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void simplemap_get_mappers ( std::map< RTLIL::IdString, void(*)(RTLIL::Module *, RTLIL::Cell *)> &  mappers)

Definition at line 403 of file simplemap.cc.

404 {
405  mappers["$not"] = simplemap_not;
406  mappers["$pos"] = simplemap_pos;
407  mappers["$and"] = simplemap_bitop;
408  mappers["$or"] = simplemap_bitop;
409  mappers["$xor"] = simplemap_bitop;
410  mappers["$xnor"] = simplemap_bitop;
411  mappers["$reduce_and"] = simplemap_reduce;
412  mappers["$reduce_or"] = simplemap_reduce;
413  mappers["$reduce_xor"] = simplemap_reduce;
414  mappers["$reduce_xnor"] = simplemap_reduce;
415  mappers["$reduce_bool"] = simplemap_reduce;
416  mappers["$logic_not"] = simplemap_lognot;
417  mappers["$logic_and"] = simplemap_logbin;
418  mappers["$logic_or"] = simplemap_logbin;
419  mappers["$mux"] = simplemap_mux;
420  mappers["$slice"] = simplemap_slice;
421  mappers["$concat"] = simplemap_concat;
422  mappers["$sr"] = simplemap_sr;
423  mappers["$dff"] = simplemap_dff;
424  mappers["$dffe"] = simplemap_dffe;
425  mappers["$dffsr"] = simplemap_dffsr;
426  mappers["$adff"] = simplemap_adff;
427  mappers["$dlatch"] = simplemap_dlatch;
428 }
static void simplemap_bitop(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:54
static void simplemap_lognot(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:186
static void simplemap_pos(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:44
static void simplemap_dffsr(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:327
static void simplemap_dff(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:286
static void simplemap_mux(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:235
static void simplemap_dffe(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:305
static void simplemap_concat(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:258
static void simplemap_sr(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:266
static void simplemap_slice(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:250
static void simplemap_adff(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:352
static void simplemap_reduce(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:91
static void simplemap_dlatch(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:379
USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN void simplemap_not(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:30
static void simplemap_logbin(RTLIL::Module *module, RTLIL::Cell *cell)
Definition: simplemap.cc:206

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_logbin ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 206 of file simplemap.cc.

207 {
208  RTLIL::SigSpec sig_a = cell->getPort("\\A");
209  logic_reduce(module, sig_a);
210 
211  RTLIL::SigSpec sig_b = cell->getPort("\\B");
212  logic_reduce(module, sig_b);
213 
214  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
215 
216  if (sig_y.size() == 0)
217  return;
218 
219  if (sig_y.size() > 1) {
220  module->connect(RTLIL::SigSig(sig_y.extract(1, sig_y.size()-1), RTLIL::SigSpec(0, sig_y.size()-1)));
221  sig_y = sig_y.extract(0, 1);
222  }
223 
224  std::string gate_type;
225  if (cell->type == "$logic_and") gate_type = "$_AND_";
226  if (cell->type == "$logic_or") gate_type = "$_OR_";
227  log_assert(!gate_type.empty());
228 
229  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
230  gate->setPort("\\A", sig_a);
231  gate->setPort("\\B", sig_b);
232  gate->setPort("\\Y", sig_y);
233 }
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
RTLIL::IdString type
Definition: rtlil.h:854
int size() const
Definition: rtlil.h:1019
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define log_assert(_assert_expr_)
Definition: log.h:85
#define NEW_ID
Definition: yosys.h:166
static void logic_reduce(RTLIL::Module *module, RTLIL::SigSpec &sig)
Definition: simplemap.cc:160
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
Definition: rtlil.cc:2414
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_lognot ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 186 of file simplemap.cc.

187 {
188  RTLIL::SigSpec sig_a = cell->getPort("\\A");
189  logic_reduce(module, sig_a);
190 
191  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
192 
193  if (sig_y.size() == 0)
194  return;
195 
196  if (sig_y.size() > 1) {
197  module->connect(RTLIL::SigSig(sig_y.extract(1, sig_y.size()-1), RTLIL::SigSpec(0, sig_y.size()-1)));
198  sig_y = sig_y.extract(0, 1);
199  }
200 
201  RTLIL::Cell *gate = module->addCell(NEW_ID, "$_NOT_");
202  gate->setPort("\\A", sig_a);
203  gate->setPort("\\Y", sig_y);
204 }
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
int size() const
Definition: rtlil.h:1019
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define NEW_ID
Definition: yosys.h:166
static void logic_reduce(RTLIL::Module *module, RTLIL::SigSpec &sig)
Definition: simplemap.cc:160
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
Definition: rtlil.cc:2414
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_mux ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 235 of file simplemap.cc.

236 {
237  RTLIL::SigSpec sig_a = cell->getPort("\\A");
238  RTLIL::SigSpec sig_b = cell->getPort("\\B");
239  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
240 
241  for (int i = 0; i < GetSize(sig_y); i++) {
242  RTLIL::Cell *gate = module->addCell(NEW_ID, "$_MUX_");
243  gate->setPort("\\A", sig_a[i]);
244  gate->setPort("\\B", sig_b[i]);
245  gate->setPort("\\S", cell->getPort("\\S"));
246  gate->setPort("\\Y", sig_y[i]);
247  }
248 }
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

USING_YOSYS_NAMESPACE static PRIVATE_NAMESPACE_BEGIN void simplemap_not ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 30 of file simplemap.cc.

31 {
32  RTLIL::SigSpec sig_a = cell->getPort("\\A");
33  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
34 
35  sig_a.extend(GetSize(sig_y), cell->parameters.at("\\A_SIGNED").as_bool());
36 
37  for (int i = 0; i < GetSize(sig_y); i++) {
38  RTLIL::Cell *gate = module->addCell(NEW_ID, "$_NOT_");
39  gate->setPort("\\A", sig_a[i]);
40  gate->setPort("\\Y", sig_y[i]);
41  }
42 }
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
#define NEW_ID
Definition: yosys.h:166
void extend(int width, bool is_signed=false)
Definition: rtlil.cc:2593

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_pos ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 44 of file simplemap.cc.

45 {
46  RTLIL::SigSpec sig_a = cell->getPort("\\A");
47  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
48 
49  sig_a.extend_u0(GetSize(sig_y), cell->parameters.at("\\A_SIGNED").as_bool());
50 
51  module->connect(RTLIL::SigSig(sig_y, sig_a));
52 }
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
void extend_u0(int width, bool is_signed=false)
Definition: rtlil.cc:2612
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
int GetSize(RTLIL::Wire *wire)
Definition: yosys.cc:334
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_reduce ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 91 of file simplemap.cc.

92 {
93  RTLIL::SigSpec sig_a = cell->getPort("\\A");
94  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
95 
96  if (sig_y.size() == 0)
97  return;
98 
99  if (sig_a.size() == 0) {
100  if (cell->type == "$reduce_and") module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(1, sig_y.size())));
101  if (cell->type == "$reduce_or") module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(0, sig_y.size())));
102  if (cell->type == "$reduce_xor") module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(0, sig_y.size())));
103  if (cell->type == "$reduce_xnor") module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(1, sig_y.size())));
104  if (cell->type == "$reduce_bool") module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(0, sig_y.size())));
105  return;
106  }
107 
108  if (sig_y.size() > 1) {
109  module->connect(RTLIL::SigSig(sig_y.extract(1, sig_y.size()-1), RTLIL::SigSpec(0, sig_y.size()-1)));
110  sig_y = sig_y.extract(0, 1);
111  }
112 
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_";
119  log_assert(!gate_type.empty());
120 
121  RTLIL::Cell *last_output_cell = NULL;
122 
123  while (sig_a.size() > 1)
124  {
125  RTLIL::SigSpec sig_t = module->addWire(NEW_ID, sig_a.size() / 2);
126 
127  for (int i = 0; i < sig_a.size(); i += 2)
128  {
129  if (i+1 == sig_a.size()) {
130  sig_t.append(sig_a[i]);
131  continue;
132  }
133 
134  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
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;
139  }
140 
141  sig_a = sig_t;
142  }
143 
144  if (cell->type == "$reduce_xnor") {
145  RTLIL::SigSpec sig_t = module->addWire(NEW_ID);
146  RTLIL::Cell *gate = module->addCell(NEW_ID, "$_NOT_");
147  gate->setPort("\\A", sig_a);
148  gate->setPort("\\Y", sig_t);
149  last_output_cell = gate;
150  sig_a = sig_t;
151  }
152 
153  if (last_output_cell == NULL) {
154  module->connect(RTLIL::SigSig(sig_y, sig_a));
155  } else {
156  last_output_cell->setPort("\\Y", sig_y);
157  }
158 }
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
RTLIL::IdString type
Definition: rtlil.h:854
int size() const
Definition: rtlil.h:1019
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define log_assert(_assert_expr_)
Definition: log.h:85
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
#define NEW_ID
Definition: yosys.h:166
#define NULL
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
Definition: rtlil.cc:2414
void append(const RTLIL::SigSpec &signal)
Definition: rtlil.cc:2523
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_slice ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 250 of file simplemap.cc.

251 {
252  int offset = cell->parameters.at("\\OFFSET").as_int();
253  RTLIL::SigSpec sig_a = cell->getPort("\\A");
254  RTLIL::SigSpec sig_y = cell->getPort("\\Y");
255  module->connect(RTLIL::SigSig(sig_y, sig_a.extract(offset, sig_y.size())));
256 }
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
int size() const
Definition: rtlil.h:1019
void connect(const RTLIL::SigSig &conn)
Definition: rtlil.cc:1278
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
Definition: rtlil.cc:2414
std::pair< SigSpec, SigSpec > SigSig
Definition: rtlil.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void simplemap_sr ( RTLIL::Module module,
RTLIL::Cell cell 
)
static

Definition at line 266 of file simplemap.cc.

267 {
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';
271 
272  RTLIL::SigSpec sig_s = cell->getPort("\\SET");
273  RTLIL::SigSpec sig_r = cell->getPort("\\CLR");
274  RTLIL::SigSpec sig_q = cell->getPort("\\Q");
275 
276  std::string gate_type = stringf("$_SR_%c%c_", set_pol, clr_pol);
277 
278  for (int i = 0; i < width; i++) {
279  RTLIL::Cell *gate = module->addCell(NEW_ID, gate_type);
280  gate->setPort("\\S", sig_s[i]);
281  gate->setPort("\\R", sig_r[i]);
282  gate->setPort("\\Q", sig_q[i]);
283  }
284 }
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
std::map< RTLIL::IdString, RTLIL::Const > parameters
Definition: rtlil.h:856
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
Definition: rtlil.cc:1809
#define NEW_ID
Definition: yosys.h:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation