8000 Fix arithmetic left-shift by constants over 32 bits (#6007) (#6015) · verilator/verilator@fc70053 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc70053

Browse files
authored
Fix arithmetic left-shift by constants over 32 bits (#6007) (#6015)
1 parent 8d3b47a commit fc70053

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/V3Number.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,8 +1877,8 @@ V3Number& V3Number::opShiftL(const V3Number& lhs, const V3Number& rhs) {
18771877
if (rhs.bitIs1(bit)) return *this; // shift of over 2^32 must be zero
18781878
}
18791879
const uint32_t rhsval = rhs.toUInt();
1880-
for (int bit = 0; bit < width(); ++bit) {
1881-
if (bit >= static_cast<int>(rhsval)) setBit(bit, lhs.bitIs(bit - rhsval));
1880+
for (uint32_t bit = 0; bit < static_cast<uint32_t>(width()); ++bit) {
1881+
if (bit >= rhsval) setBit(bit, lhs.bitIs(bit - rhsval));
18821882
}
18831883
return *this;
18841884
}

test_regress/t/t_math_shiftls.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
3+
#
4+
# Copyright 2025 by Wilson Snyder. This program is free software; you
5+
# can redistribute it and/or modify it under the terms of either the GNU
6+
# Lesser General Public License Version 3 or the Perl Artistic License
7+
# Version 2.0.
8+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9+
10+
import vltest_bootstrap
11+
12+
test.scenarios('simulator')
13+
14+
test.compile(verilator_flags2=['--binary'])
15+
16+
test.execute()
17+
18+
test.passes()

test_regress/t/t_math_shiftls.v

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// DESCRIPTION: Verilator: Verilog Test module
2+
//
3+
// This file ONLY is placed under the Creative Commons Public Domain, for
4+
// any use, without warranty, 2025 by Zhen Yan.
5+
// SPDX-License-Identifier: CC0-1.0
6+
7+
`define stop $stop
8+
`define checkd(gotv, expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__, `__LINE__, (gotv), (expv)); `stop; end while(0);
9+
10+
module top (out33);
11+
12+
output wire [6:0] out33;
13+
14+
assign out33 = (7'o66 <<< 32'hFFFF_FFFF);
15+
16+
initial begin
17+
#10;
18+
`checkd(out33, '0);
19+
$write("*-* All Finished *-*\n");
20+
$finish;
21+
end
22+
23+
endmodule

0 commit comments

Comments
 (0)
0