aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rtlil.cc
diff options
context:
space:
mode:
authorXiretza <xiretza@xiretza.xyz>2020-04-08 19:30:47 +0200
committerXiretza <xiretza@xiretza.xyz>2020-05-28 22:59:03 +0200
commit17163cf43a6b6eec9aac44f6a4463dda54b8ed68 (patch)
tree02dd1e144c36eb40565cbb792726c7d8d4573eb4 /kernel/rtlil.cc
parent0d99522b3c2ca2502129110e09f9988874e37abc (diff)
downloadyosys-17163cf43a6b6eec9aac44f6a4463dda54b8ed68.tar.gz
yosys-17163cf43a6b6eec9aac44f6a4463dda54b8ed68.tar.bz2
yosys-17163cf43a6b6eec9aac44f6a4463dda54b8ed68.zip
Add flooring modulo operator
The $div and $mod cells use truncating division semantics (rounding towards 0), as defined by e.g. Verilog. Another rounding mode, flooring (rounding towards negative infinity), can be used in e.g. VHDL. The new $modfloor cell provides this flooring modulo (also known as "remainder" in several languages, but this name is ambiguous). This commit also fixes the handling of $mod in opt_expr, which was previously optimized as if it was $modfloor.
Diffstat (limited to 'kernel/rtlil.cc')
-rw-r--r--kernel/rtlil.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 196e301b6..f2480ba5a 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -948,7 +948,7 @@ namespace {
return;
}
- if (cell->type.in(ID($add), ID($sub), ID($mul), ID($div), ID($mod), ID($pow))) {
+ if (cell->type.in(ID($add), ID($sub), ID($mul), ID($div), ID($mod), ID($modfloor), ID($pow))) {
param_bool(ID::A_SIGNED);
param_bool(ID::B_SIGNED);
port(ID::A, param(ID::A_WIDTH));
@@ -1949,6 +1949,7 @@ DEF_METHOD(Sub, max(sig_a.size(), sig_b.size()), ID($sub))
DEF_METHOD(Mul, max(sig_a.size(), sig_b.size()), ID($mul))
DEF_METHOD(Div, max(sig_a.size(), sig_b.size()), ID($div))
DEF_METHOD(Mod, max(sig_a.size(), sig_b.size()), ID($mod))
+DEF_METHOD(ModFloor, max(sig_a.size(), sig_b.size()), ID($modfloor))
DEF_METHOD(LogicAnd, 1, ID($logic_and))
DEF_METHOD(LogicOr, 1, ID($logic_or))
#undef DEF_METHOD