-
Notifications
You must be signed in to change notification settings - Fork 112
merge mxint_linear #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
firemountain154B
wants to merge
6
commits into
main
Choose a base branch
from
cx/merge_new_mxint_linear
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
merge mxint_linear #229
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
128a573
merge mxint_linear
firemountain154B 867730f
finish mxint_linear
firemountain154B e94263a
format again
firemountain154B 97e2b81
mxint linear
firemountain154B d351017
bug on mxint_cast
firemountain154B 1018b3f
gogogo
firemountain154B File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -5,13 +5,13 @@ Description : The accumulator for mxint. | |
| When inputing different exponent, the mantissa will cast to the same bitwidth then accumulate. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a lossy behaviour? If it is, it might worth to add a few more lines to explain its behaviour? I assume this is the module that aligns the exponent first? |
||
| */ | ||
| module mxint_accumulator #( | ||
| parameter DATA_IN_0_PRECISION_0 = 8, | ||
| parameter DATA_IN_0_PRECISION_1 = 4, | ||
| // precision_0 = mantissa_width | ||
| // precision_1 = exponent_width | ||
| parameter DATA_IN_0_PRECISION_0 = 4, | ||
| parameter DATA_IN_0_PRECISION_1 = 8, | ||
| parameter BLOCK_SIZE = 4, | ||
| parameter IN_DEPTH = 2, | ||
| parameter DATA_OUT_0_PRECISION_0 = DATA_IN_0_PRECISION_0 + 2 ** DATA_IN_0_PRECISION_1 + $clog2( | ||
| IN_DEPTH | ||
| ), | ||
| parameter DATA_OUT_0_PRECISION_0 = DATA_IN_0_PRECISION_0 + $clog2(IN_DEPTH), | ||
| parameter DATA_OUT_0_PRECISION_1 = DATA_IN_0_PRECISION_1 | ||
| ) ( | ||
| input logic clk, | ||
|
|
@@ -37,15 +37,23 @@ module mxint_accumulator #( | |
| assign data_out_0_valid = (counter == IN_DEPTH); | ||
| /* verilator lint_on WIDTH */ | ||
|
|
||
| // mantissa shift | ||
| logic [DATA_OUT_0_PRECISION_0 - 1:0] shifted_mdata_in_0[BLOCK_SIZE - 1:0]; | ||
| // lossless shift | ||
| logic [DATA_IN_0_PRECISION_0 - 1:0] shifted_mdata_in_0[BLOCK_SIZE - 1:0]; | ||
| logic [DATA_OUT_0_PRECISION_0 - 1:0] shifted_mdata_out_0[BLOCK_SIZE - 1:0]; | ||
|
|
||
| logic no_value_in_register; | ||
| logic [DATA_IN_0_PRECISION_1 - 1:0] exp_min; | ||
| logic [DATA_IN_0_PRECISION_1 - 1:0] exp_max; | ||
|
|
||
| logic [DATA_IN_0_PRECISION_1 - 1:0] mdata_in_shift_value; | ||
| logic [DATA_IN_0_PRECISION_1 - 1:0] mdata_in_real_shift_value; | ||
| logic [DATA_IN_0_PRECISION_1 - 1:0] mdata_out_shift_value; | ||
| logic [DATA_IN_0_PRECISION_1 - 1:0] mdata_out_real_shift_value; | ||
|
|
||
| logic [DATA_IN_0_PRECISION_0 - 1:0] shifted_mdata_in_list [BLOCK_SIZE - 1:0][DATA_IN_0_PRECISION_0 - 1:0]; | ||
| logic [DATA_OUT_0_PRECISION_0 - 1:0] shifted_mdata_out_list [BLOCK_SIZE - 1:0][DATA_OUT_0_PRECISION_0 - 1:0]; | ||
|
|
||
| assign no_value_in_register =(counter == 0 || (data_out_0_valid && data_out_0_ready && data_in_0_valid)); | ||
| assign exp_min = ($signed(edata_out_0) > $signed(edata_in_0)) ? edata_in_0 : edata_out_0; | ||
| assign exp_max = ($signed(edata_out_0) < $signed(edata_in_0)) ? edata_in_0 : edata_out_0; | ||
| // counter | ||
| always_ff @(posedge clk) | ||
| if (rst) counter <= 0; | ||
|
|
@@ -58,43 +66,51 @@ module mxint_accumulator #( | |
| end else if (data_in_0_valid && data_in_0_ready) counter <= counter + 1; | ||
| end | ||
| // mantissa | ||
| always_comb begin | ||
| mdata_in_shift_value = $signed(exp_max) - $signed(edata_in_0); | ||
| mdata_in_real_shift_value = (mdata_in_shift_value < DATA_IN_0_PRECISION_0)? mdata_in_shift_value: DATA_IN_0_PRECISION_0 - 1; | ||
| mdata_out_shift_value = $signed(exp_max) - $signed(edata_out_0); | ||
| mdata_out_real_shift_value = (mdata_out_shift_value < DATA_OUT_0_PRECISION_0)? mdata_out_shift_value: DATA_OUT_0_PRECISION_0 - 1; | ||
| end | ||
|
|
||
| for (genvar i = 0; i < BLOCK_SIZE; i++) begin : mantissa_block | ||
| // mantissa shift | ||
| for (genvar j = 0; j < 2 ** DATA_IN_0_PRECISION_1; j++) begin : static_shift | ||
| for (genvar i = 0; i < BLOCK_SIZE; i++) begin : optimize_variable_shift | ||
| for (genvar j = 0; j < DATA_IN_0_PRECISION_0; j++) begin : data_in_shift | ||
| always_comb begin | ||
| shifted_mdata_in_list[i][j] = no_value_in_register ? $signed(mdata_in_0[i]) : | ||
| $signed(mdata_in_0[i]) >>> j; | ||
| end | ||
| end | ||
| for (genvar k = 0; k < DATA_OUT_0_PRECISION_0; k++) begin : data_out_shift | ||
| always_comb begin | ||
| if (($signed(edata_in_0) - $signed(exp_min)) == j) | ||
| shifted_mdata_in_0[i] = no_value_in_register ? $signed( | ||
| mdata_in_0[i] | ||
| ) : $signed( | ||
| mdata_in_0[i] | ||
| ) <<< j; | ||
| if (($signed(edata_out_0) - $signed(exp_min)) == j) | ||
| shifted_mdata_out_0[i] = $signed(mdata_out_0[i]) <<< j; | ||
| shifted_mdata_out_list[i][k] = $signed(mdata_out_0[i]) >>> k; | ||
| end | ||
| end | ||
| // mantissa out | ||
| assign shifted_mdata_in_0[i] = shifted_mdata_in_list[i][mdata_in_real_shift_value]; | ||
| assign shifted_mdata_out_0[i] = shifted_mdata_out_list[i][mdata_out_real_shift_value]; | ||
| end | ||
|
|
||
| for (genvar i = 0; i < BLOCK_SIZE; i++) begin : mantissa_block | ||
| always_ff @(posedge clk) | ||
| if (rst) mdata_out_0[i] <= '0; | ||
| else begin | ||
| if (data_out_0_valid) begin | ||
| if (data_out_0_ready) begin | ||
| if (data_in_0_valid) mdata_out_0[i] <= shifted_mdata_in_0[i]; | ||
| if (data_in_0_valid) mdata_out_0[i] <= $signed(shifted_mdata_in_0[i]); | ||
| else mdata_out_0[i] <= '0; | ||
| end | ||
| end else if (data_in_0_valid && data_in_0_ready) | ||
| mdata_out_0[i] <= $signed(shifted_mdata_out_0[i]) + $signed(shifted_mdata_in_0[i]); | ||
| end | ||
| end | ||
| localparam signed [DATA_IN_0_PRECISION_1 - 1:0] MAXIMUM_EXPONENTIAL = 2**(DATA_IN_0_PRECISION_1 - 1) - 1; | ||
| localparam signed [DATA_IN_0_PRECISION_1 - 1:0] MINIMUM_EXPONENTIAL = - 2**(DATA_IN_0_PRECISION_1 - 1); | ||
| // exponent | ||
| always_ff @(posedge clk) | ||
| if (rst) edata_out_0 <= MAXIMUM_EXPONENTIAL; | ||
| if (rst) edata_out_0 <= MINIMUM_EXPONENTIAL; | ||
| else if (data_out_0_valid) begin | ||
| if (data_out_0_ready) begin | ||
| if (data_in_0_valid) edata_out_0 <= edata_in_0; | ||
| else edata_out_0 <= MAXIMUM_EXPONENTIAL; | ||
| else edata_out_0 <= MINIMUM_EXPONENTIAL; | ||
| end | ||
| end else if (data_in_0_valid && data_in_0_ready) edata_out_0 <= exp_min; | ||
| end else if (data_in_0_valid && data_in_0_ready) edata_out_0 <= exp_max; | ||
|
|
||
| endmodule | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just delete this?