diff options
author | Mike Walters <mike@flomp.net> | 2020-06-14 14:42:20 +0100 |
---|---|---|
committer | Mike Walters <mike@flomp.net> | 2020-06-15 01:01:49 +0100 |
commit | 66a2de2912604864e5d7a7717397caf814646621 (patch) | |
tree | 1b8a1e27fdda5e1d180163ec3ea905de91334eed | |
parent | dc6961f3d46657e501ed7115f819d7dd6372b1ce (diff) | |
download | yosys-66a2de2912604864e5d7a7717397caf814646621.tar.gz yosys-66a2de2912604864e5d7a7717397caf814646621.tar.bz2 yosys-66a2de2912604864e5d7a7717397caf814646621.zip |
cxxrtl: fix sshr sign-extension.
-rw-r--r-- | backends/cxxrtl/cxxrtl.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h index 2458487e1..0e2e27ed4 100644 --- a/backends/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/cxxrtl.h @@ -376,10 +376,12 @@ struct value : public expr_base<value<Bits>> { : data[chunks - 1 - n] << (chunk::bits - shift_bits); } if (Signed && is_neg()) { - for (size_t n = chunks - shift_chunks; n < chunks; n++) + size_t top_chunk_idx = (Bits - shift_bits) / chunk::bits; + size_t top_chunk_bits = (Bits - shift_bits) % chunk::bits; + for (size_t n = top_chunk_idx + 1; n < chunks; n++) result.data[n] = chunk::mask; if (shift_bits != 0) - result.data[chunks - shift_chunks] |= chunk::mask << (chunk::bits - shift_bits); + result.data[top_chunk_idx] |= chunk::mask << top_chunk_bits; } return result; } |