Merge pull request #2158 from miek/sshr-sign-extension

cxxrtl: fix sshr sign-extension.
This commit is contained in:
whitequark 2020-06-15 01:37:05 +00:00 committed by GitHub
commit 9d0f1aa222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -376,10 +376,12 @@ struct value : public expr_base<value<Bits>> {
: data[chunks - 1 - n] << (chunk::bits - shift_bits); : data[chunks - 1 - n] << (chunk::bits - shift_bits);
} }
if (Signed && is_neg()) { 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; result.data[n] = chunk::mask;
if (shift_bits != 0) 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; return result;
} }