summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rtlil.cc176
-rw-r--r--kernel/rtlil.h55
2 files changed, 158 insertions, 73 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index c232dadd..dea0e105 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -869,8 +869,8 @@ void RTLIL::Module::fixup_ports()
}
-#define DEF_METHOD(_func, _type) \
- RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed) { \
+#define DEF_METHOD(_func, _y_size, _type) \
+ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed) { \
RTLIL::Cell *cell = new RTLIL::Cell; \
cell->name = name; \
cell->type = _type; \
@@ -881,21 +881,26 @@ void RTLIL::Module::fixup_ports()
cell->connections["\\Y"] = sig_y; \
add(cell); \
return cell; \
+ } \
+ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed) { \
+ RTLIL::SigSpec sig_y = new_wire(_y_size, NEW_ID); \
+ add ## _func(name, sig_a, sig_y, is_signed); \
+ return sig_y; \
}
-DEF_METHOD(addNot, "$not")
-DEF_METHOD(addPos, "$pos")
-DEF_METHOD(addBu0, "$bu0")
-DEF_METHOD(addNeg, "$neg")
-DEF_METHOD(addReduceAnd, "$reduce_and")
-DEF_METHOD(addReduceOr, "$reduce_or")
-DEF_METHOD(addReduceXor, "$reduce_xor")
-DEF_METHOD(addReduceXnor, "$reduce_xnor")
-DEF_METHOD(addReduceBool, "$reduce_bool")
-DEF_METHOD(addLogicNot, "$logic_not")
+DEF_METHOD(Not, sig_a.width, "$not")
+DEF_METHOD(Pos, sig_a.width, "$pos")
+DEF_METHOD(Bu0, sig_a.width, "$bu0")
+DEF_METHOD(Neg, sig_a.width, "$neg")
+DEF_METHOD(ReduceAnd, 1, "$reduce_and")
+DEF_METHOD(ReduceOr, 1, "$reduce_or")
+DEF_METHOD(ReduceXor, 1, "$reduce_xor")
+DEF_METHOD(ReduceXnor, 1, "$reduce_xnor")
+DEF_METHOD(ReduceBool, 1, "$reduce_bool")
+DEF_METHOD(LogicNot, 1, "$logic_not")
#undef DEF_METHOD
-#define DEF_METHOD(_func, _type) \
- RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed) { \
+#define DEF_METHOD(_func, _y_size, _type) \
+ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_y, bool is_signed) { \
RTLIL::Cell *cell = new RTLIL::Cell; \
cell->name = name; \
cell->type = _type; \
@@ -909,34 +914,39 @@ DEF_METHOD(addLogicNot, "$logic_not")
cell->connections["\\Y"] = sig_y; \
add(cell); \
return cell; \
+ } \
+ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed) { \
+ RTLIL::SigSpec sig_y = new_wire(_y_size, NEW_ID); \
+ add ## _func(name, sig_a, sig_b, sig_y, is_signed); \
+ return sig_y; \
}
-DEF_METHOD(addAnd, "$and")
-DEF_METHOD(addOr, "$or")
-DEF_METHOD(addXor, "$xor")
-DEF_METHOD(addXnor, "$xnor")
-DEF_METHOD(addShl, "$shl")
-DEF_METHOD(addShr, "$shr")
-DEF_METHOD(addSshl, "$sshl")
-DEF_METHOD(addSshr, "$sshr")
-DEF_METHOD(addLt, "$lt")
-DEF_METHOD(addLe, "$le")
-DEF_METHOD(addEq, "$eq")
-DEF_METHOD(addNe, "$ne")
-DEF_METHOD(addEqx, "$eqx")
-DEF_METHOD(addNex, "$nex")
-DEF_METHOD(addGe, "$ge")
-DEF_METHOD(addGt, "$gt")
-DEF_METHOD(addAdd, "$add")
-DEF_METHOD(addSub, "$sub")
-DEF_METHOD(addMul, "$mul")
-DEF_METHOD(addDiv, "$div")
-DEF_METHOD(addMod, "$mod")
-DEF_METHOD(addLogicAnd, "$logic_and")
-DEF_METHOD(addLogicOr, "$logic_or")
+DEF_METHOD(And, std::max(sig_a.width, sig_b.width), "$and")
+DEF_METHOD(Or, std::max(sig_a.width, sig_b.width), "$or")
+DEF_METHOD(Xor, std::max(sig_a.width, sig_b.width), "$xor")
+DEF_METHOD(Xnor, std::max(sig_a.width, sig_b.width), "$xnor")
+DEF_METHOD(Shl, sig_a.width, "$shl")
+DEF_METHOD(Shr, sig_a.width, "$shr")
+DEF_METHOD(Sshl, sig_a.width, "$sshl")
+DEF_METHOD(Sshr, sig_a.width, "$sshr")
+DEF_METHOD(Lt, 1, "$lt")
+DEF_METHOD(Le, 1, "$le")
+DEF_METHOD(Eq, 1, "$eq")
+DEF_METHOD(Ne, 1, "$ne")
+DEF_METHOD(Eqx, 1, "$eqx")
+DEF_METHOD(Nex, 1, "$nex")
+DEF_METHOD(Ge, 1, "$ge")
+DEF_METHOD(Gt, 1, "$gt")
+DEF_METHOD(Add, std::max(sig_a.width, sig_b.width), "$add")
+DEF_METHOD(Sub, std::max(sig_a.width, sig_b.width), "$sub")
+DEF_METHOD(Mul, std::max(sig_a.width, sig_b.width), "$mul")
+DEF_METHOD(Div, std::max(sig_a.width, sig_b.width), "$div")
+DEF_METHOD(Mod, std::max(sig_a.width, sig_b.width), "$mod")
+DEF_METHOD(LogicAnd, 1, "$logic_and")
+DEF_METHOD(LogicOr, 1, "$logic_or")
#undef DEF_METHOD
#define DEF_METHOD(_func, _type, _pmux) \
- RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y) { \
+ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s, RTLIL::SigSpec sig_y) { \
RTLIL::Cell *cell = new RTLIL::Cell; \
cell->name = name; \
cell->type = _type; \
@@ -949,50 +959,70 @@ DEF_METHOD(addLogicOr, "$logic_or")
cell->connections["\\Y"] = sig_y; \
add(cell); \
return cell; \
+ } \
+ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s) { \
+ RTLIL::SigSpec sig_y = new_wire(sig_a.width, NEW_ID); \
+ add ## _func(name, sig_a, sig_b, sig_s, sig_y); \
+ return sig_y; \
}
-DEF_METHOD(addMux, "$mux", 0)
-DEF_METHOD(addPmux, "$pmux", 1)
-DEF_METHOD(addSafePmux, "$safe_pmux", 1)
+DEF_METHOD(Mux, "$mux", 0)
+DEF_METHOD(Pmux, "$pmux", 1)
+DEF_METHOD(SafePmux, "$safe_pmux", 1)
#undef DEF_METHOD
#define DEF_METHOD_2(_func, _type, _P1, _P2) \
- RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2) { \
- RTLIL::Cell *cell = new RTLIL::Cell; \
- cell->name = name; \
- cell->type = _type; \
- cell->connections["\\" #_P1] = sig1; \
- cell->connections["\\" #_P2] = sig2; \
- add(cell); \
- return cell; \
+ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2) { \
+ RTLIL::Cell *cell = new RTLIL::Cell; \
+ cell->name = name; \
+ cell->type = _type; \
+ cell->connections["\\" #_P1] = sig1; \
+ cell->connections["\\" #_P2] = sig2; \
+ add(cell); \
+ return cell; \
+ } \
+ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1) { \
+ RTLIL::SigSpec sig2 = new_wire(1, NEW_ID); \
+ add ## _func(name, sig1, sig2); \
+ return sig2; \
}
#define DEF_METHOD_3(_func, _type, _P1, _P2, _P3) \
- RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3) { \
- RTLIL::Cell *cell = new RTLIL::Cell; \
- cell->name = name; \
- cell->type = _type; \
- cell->connections["\\" #_P1] = sig1; \
- cell->connections["\\" #_P2] = sig2; \
- cell->connections["\\" #_P3] = sig3; \
- add(cell); \
- return cell; \
+ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3) { \
+ RTLIL::Cell *cell = new RTLIL::Cell; \
+ cell->name = name; \
+ cell->type = _type; \
+ cell->connections["\\" #_P1] = sig1; \
+ cell->connections["\\" #_P2] = sig2; \
+ cell->connections["\\" #_P3] = sig3; \
+ add(cell); \
+ return cell; \
+ } \
+ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2) { \
+ RTLIL::SigSpec sig3 = new_wire(1, NEW_ID); \
+ add ## _func(name, sig1, sig2, sig3); \
+ return sig3; \
}
#define DEF_METHOD_4(_func, _type, _P1, _P2, _P3, _P4) \
- RTLIL::Cell* RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3, RTLIL::SigSpec sig4) { \
- RTLIL::Cell *cell = new RTLIL::Cell; \
- cell->name = name; \
- cell->type = _type; \
- cell->connections["\\" #_P1] = sig1; \
- cell->connections["\\" #_P2] = sig2; \
- cell->connections["\\" #_P3] = sig3; \
- cell->connections["\\" #_P4] = sig4; \
- add(cell); \
- return cell; \
+ RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3, RTLIL::SigSpec sig4) { \
+ RTLIL::Cell *cell = new RTLIL::Cell; \
+ cell->name = name; \
+ cell->type = _type; \
+ cell->connections["\\" #_P1] = sig1; \
+ cell->connections["\\" #_P2] = sig2; \
+ cell->connections["\\" #_P3] = sig3; \
+ cell->connections["\\" #_P4] = sig4; \
+ add(cell); \
+ return cell; \
+ } \
+ RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, RTLIL::SigSpec sig1, RTLIL::SigSpec sig2, RTLIL::SigSpec sig3) { \
+ RTLIL::SigSpec sig4 = new_wire(1, NEW_ID); \
+ add ## _func(name, sig1, sig2, sig3, sig4); \
+ return sig4; \
}
-DEF_METHOD_2(addInvGate, "$_INV_", A, Y)
-DEF_METHOD_3(addAndGate, "$_AND_", A, B, Y)
-DEF_METHOD_3(addOrGate, "$_OR_", A, B, Y)
-DEF_METHOD_3(addXorGate, "$_XOR_", A, B, Y)
-DEF_METHOD_4(addMuxGate, "$_MUX_", A, B, S, Y)
+DEF_METHOD_2(InvGate, "$_INV_", A, Y)
+DEF_METHOD_3(AndGate, "$_AND_", A, B, Y)
+DEF_METHOD_3(OrGate, "$_OR_", A, B, Y)
+DEF_METHOD_3(XorGate, "$_XOR_", A, B, Y)
+DEF_METHOD_4(MuxGate, "$_MUX_", A, B, S, Y)
#undef DEF_METHOD_2
#undef DEF_METHOD_3
#undef DEF_METHOD_4
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index b95a0442..17406d5d 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -294,6 +294,8 @@ struct RTLIL::Module {
void cloneInto(RTLIL::Module *new_mod) const;
virtual RTLIL::Module *clone() const;
+ // The add* methods create a cell and return the created cell. All signals must exist in advance.
+
RTLIL::Cell* addNot (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
RTLIL::Cell* addPos (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
RTLIL::Cell* addBu0 (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_y, bool is_signed = false);
@@ -368,6 +370,59 @@ struct RTLIL::Module {
RTLIL::Cell* addDlatchGate (RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity = true);
RTLIL::Cell* addDlatchsrGate (RTLIL::IdString name, RTLIL::SigSpec sig_en, RTLIL::SigSpec sig_set, RTLIL::SigSpec sig_clr,
RTLIL::SigSpec sig_d, RTLIL::SigSpec sig_q, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true);
+
+ // The methods without the add* prefix create a cell and an output signal. They return the newly created output signal.
+
+ RTLIL::SigSpec Not (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec Pos (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec Bu0 (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec Neg (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+
+ RTLIL::SigSpec And (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Or (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Xor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Xnor (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+
+ RTLIL::SigSpec ReduceAnd (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec ReduceOr (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec ReduceXor (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec ReduceXnor (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec ReduceBool (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+
+ RTLIL::SigSpec Shl (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Shr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Sshl (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Sshr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+
+ RTLIL::SigSpec Lt (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Le (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Eq (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Ne (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Eqx (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Nex (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Ge (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Gt (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+
+ RTLIL::SigSpec Add (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Sub (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Mul (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Div (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Mod (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec Pow (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool a_signed = false, bool b_signed = false);
+
+ RTLIL::SigSpec LogicNot (RTLIL::IdString name, RTLIL::SigSpec sig_a, bool is_signed = false);
+ RTLIL::SigSpec LogicAnd (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+ RTLIL::SigSpec LogicOr (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, bool is_signed = false);
+
+ RTLIL::SigSpec Mux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
+ RTLIL::SigSpec Pmux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
+ RTLIL::SigSpec SafePmux (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
+
+ RTLIL::SigSpec InvGate (RTLIL::IdString name, RTLIL::SigSpec sig_a);
+ RTLIL::SigSpec AndGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b);
+ RTLIL::SigSpec OrGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b);
+ RTLIL::SigSpec XorGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b);
+ RTLIL::SigSpec MuxGate (RTLIL::IdString name, RTLIL::SigSpec sig_a, RTLIL::SigSpec sig_b, RTLIL::SigSpec sig_s);
};
struct RTLIL::Wire {