aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/calc.cc
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2014-07-29 14:42:33 +0200
committerClifford Wolf <clifford@clifford.at>2014-07-29 16:35:13 +0200
commit397b00252dc0c4af725614bd12fc299147ba8efa (patch)
treee7a1dfdd61f165a517036c4efdde2c53ef9076e7 /kernel/calc.cc
parent48822e79a34880c5f0b07e9889e463e7b6d7111b (diff)
downloadyosys-397b00252dc0c4af725614bd12fc299147ba8efa.tar.gz
yosys-397b00252dc0c4af725614bd12fc299147ba8efa.tar.bz2
yosys-397b00252dc0c4af725614bd12fc299147ba8efa.zip
Added $shift and $shiftx cell types (needed for correct part select behavior)
Diffstat (limited to 'kernel/calc.cc')
-rw-r--r--kernel/calc.cc43
1 files changed, 38 insertions, 5 deletions
diff --git a/kernel/calc.cc b/kernel/calc.cc
index b413760d1..b3ff3cf2a 100644
--- a/kernel/calc.cc
+++ b/kernel/calc.cc
@@ -276,7 +276,7 @@ RTLIL::Const RTLIL::const_logic_or(const RTLIL::Const &arg1, const RTLIL::Const
return result;
}
-static RTLIL::Const const_shift(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool sign_ext, int direction, int result_len)
+static RTLIL::Const const_shift_worker(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool sign_ext, int direction, int result_len)
{
int undef_bit_pos = -1;
BigInteger offset = const2big(arg2, false, undef_bit_pos) * direction;
@@ -305,28 +305,61 @@ RTLIL::Const RTLIL::const_shl(const RTLIL::Const &arg1, const RTLIL::Const &arg2
{
RTLIL::Const arg1_ext = arg1;
extend_u0(arg1_ext, result_len, signed1);
- return const_shift(arg1_ext, arg2, false, -1, result_len);
+ return const_shift_worker(arg1_ext, arg2, false, -1, result_len);
}
RTLIL::Const RTLIL::const_shr(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool, int result_len)
{
RTLIL::Const arg1_ext = arg1;
extend_u0(arg1_ext, result_len, signed1);
- return const_shift(arg1_ext, arg2, false, +1, result_len);
+ return const_shift_worker(arg1_ext, arg2, false, +1, result_len);
}
RTLIL::Const RTLIL::const_sshl(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
{
if (!signed1)
return const_shl(arg1, arg2, signed1, signed2, result_len);
- return const_shift(arg1, arg2, true, -1, result_len);
+ return const_shift_worker(arg1, arg2, true, -1, result_len);
}
RTLIL::Const RTLIL::const_sshr(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
{
if (!signed1)
return const_shr(arg1, arg2, signed1, signed2, result_len);
- return const_shift(arg1, arg2, true, +1, result_len);
+ return const_shift_worker(arg1, arg2, true, +1, result_len);
+}
+
+static RTLIL::Const const_shift_shiftx(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool, bool signed2, int result_len, RTLIL::State other_bits)
+{
+ int undef_bit_pos = -1;
+ BigInteger offset = const2big(arg2, signed2, undef_bit_pos);
+
+ if (result_len < 0)
+ result_len = arg1.bits.size();
+
+ RTLIL::Const result(RTLIL::State::Sx, result_len);
+ if (undef_bit_pos >= 0)
+ return result;
+
+ for (int i = 0; i < result_len; i++) {
+ BigInteger pos = BigInteger(i) + offset;
+ if (pos < 0 || pos >= arg1.bits.size())
+ result.bits[i] = other_bits;
+ else
+ result.bits[i] = arg1.bits[pos.toInt()];
+ }
+
+ return result;
+}
+
+RTLIL::Const RTLIL::const_shift(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
+{
+ return const_shift_shiftx(arg1, arg2, signed1, signed2, result_len, RTLIL::State::S0);
+}
+
+RTLIL::Const RTLIL::const_shiftx(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)
+{
+ return const_shift_shiftx(arg1, arg2, signed1, signed2, result_len, RTLIL::State::Sx);
}
RTLIL::Const RTLIL::const_lt(const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len)