cxxrtl: fix sshr sign-extension.
authorMike Walters <mike@flomp.net>
Sun, 14 Jun 2020 13:42:20 +0000 (14:42 +0100)
committerMike Walters <mike@flomp.net>
Mon, 15 Jun 2020 00:01:49 +0000 (01:01 +0100)
backends/cxxrtl/cxxrtl.h

index 2458487e143cd1c3da7a4be6e577b8494c16fbea..0e2e27ed46f9faf7604c1b5e27326200bbf5535d 100644 (file)
@@ -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;
        }