-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guard against overflow / wrap around of internal part-select bit address
Internally, the maximum address space of a vector is 31 bits + a sign bit to signal invalid addresses (out of bounds or has one or more x or z bits). This commit ensures that unsigned part-select bit addresses which would otherwise overflow and wrap around within this address space are correctly handled as out of bounds.
- Loading branch information
Showing
6 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* partsel_outside | ||
* Check that base_expr ± bit_number in a part-select does not wrap around | ||
* within the internal 32 bit (signed) vector address space. | ||
* This could incorrectly select bits from a vector when unsized numbers are | ||
* used in the part-select index expression. | ||
*/ | ||
|
||
module main; | ||
|
||
reg [1:0] arr = 1; | ||
reg [31:0] uoffset = -32'd1; | ||
wire [1:0] outside_const = arr[-32'd1 +: 2]; | ||
wire [1:0] outside_expr = arr[uoffset +: 2]; | ||
|
||
initial begin | ||
#1 if (outside_const !== 'x) begin | ||
$display("FAILED -- const base_expr out of bounds value %b != xx", outside_const); | ||
$finish; | ||
end | ||
|
||
#2 if (outside_expr !== 'x) begin | ||
$display("FAILED -- non-const base_expr out of bounds value %b != xx", outside_expr); | ||
$finish; | ||
end | ||
|
||
$display("PASSED"); | ||
$finish; | ||
end | ||
|
||
endmodule // main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters