-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make codegen implement shra as a function.
This allows us to bind the intermediate result `$signed(to_shift) >>> amount` to a reg with a defined width, which avoids the `$signed()` having a self-determined width, which is a lint finding. Fixes #1642. PiperOrigin-RevId: 682526771
- Loading branch information
1 parent
773e02a
commit d0c9bbd
Showing
9 changed files
with
184 additions
and
21 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
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
16 changes: 16 additions & 0 deletions
16
xls/codegen/testdata/module_builder_test_ShraAsFunction.svtxt
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,16 @@ | ||
module ShraAsFunction( | ||
input wire [31:0] x, | ||
input wire [31:0] y | ||
); | ||
// lint_off SIGNED_TYPE | ||
function automatic [31:0] shra_32b_by_32b (input reg [31:0] to_shift, input reg [31:0] shift_amount); | ||
reg signed [31:0] signed_result; | ||
begin | ||
signed_result = $signed(to_shift) >>> shift_amount; | ||
shra_32b_by_32b = $unsigned(signed_result); | ||
end | ||
endfunction | ||
// lint_on SIGNED_TYPE | ||
wire [31:0] x_smul_y; | ||
assign x_smul_y = shra_32b_by_32b(x, y); | ||
endmodule |
16 changes: 16 additions & 0 deletions
16
xls/codegen/testdata/module_builder_test_ShraAsFunction.vtxt
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,16 @@ | ||
module ShraAsFunction( | ||
input wire [31:0] x, | ||
input wire [31:0] y | ||
); | ||
// lint_off SIGNED_TYPE | ||
function automatic [31:0] shra_32b_by_32b (input reg [31:0] to_shift, input reg [31:0] shift_amount); | ||
reg signed [31:0] signed_result; | ||
begin | ||
signed_result = $signed(to_shift) >>> shift_amount; | ||
shra_32b_by_32b = $unsigned(signed_result); | ||
end | ||
endfunction | ||
// lint_on SIGNED_TYPE | ||
wire [31:0] x_smul_y; | ||
assign x_smul_y = shra_32b_by_32b(x, y); | ||
endmodule |
16 changes: 16 additions & 0 deletions
16
xls/codegen/testdata/module_builder_test_ShraAsFunctionSingleBit.svtxt
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,16 @@ | ||
module ShraAsFunctionSingleBit( | ||
input wire x, | ||
input wire y | ||
); | ||
// lint_off SIGNED_TYPE | ||
function automatic logic shra_1b_by_1b (input reg to_shift, input reg shift_amount); | ||
reg signed signed_result; | ||
begin | ||
signed_result = $signed(to_shift) >>> shift_amount; | ||
shra_1b_by_1b = $unsigned(signed_result); | ||
end | ||
endfunction | ||
// lint_on SIGNED_TYPE | ||
wire x_smul_y; | ||
assign x_smul_y = shra_1b_by_1b(x, y); | ||
endmodule |
16 changes: 16 additions & 0 deletions
16
xls/codegen/testdata/module_builder_test_ShraAsFunctionSingleBit.vtxt
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,16 @@ | ||
module ShraAsFunctionSingleBit( | ||
input wire x, | ||
input wire y | ||
); | ||
// lint_off SIGNED_TYPE | ||
function automatic shra_1b_by_1b (input reg to_shift, input reg shift_amount); | ||
reg signed signed_result; | ||
begin | ||
signed_result = $signed(to_shift) >>> shift_amount; | ||
shra_1b_by_1b = $unsigned(signed_result); | ||
end | ||
endfunction | ||
// lint_on SIGNED_TYPE | ||
wire x_smul_y; | ||
assign x_smul_y = shra_1b_by_1b(x, y); | ||
endmodule |