generated from TinyTapeout/tt09-verilog-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Committing rn for history, this is PE with mixed precision support an…
…d an array of PEs
- Loading branch information
1 parent
7be90ff
commit 7ec8d04
Showing
2 changed files
with
74 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,47 @@ | ||
module processing_element( | ||
module processing_element #( | ||
parameter INPUT_WIDTH = 8, | ||
parameter OUTPUT_WIDTH = 32 | ||
parameter REG_FILE_DEPTH = 8, //number of registers in file | ||
parameter REG_FILE_WIDTH = 3 //bit width of each register | ||
)( | ||
input wire clk, | ||
input wire rst, | ||
input wire [15:0] data_in_2, | ||
input wire [15:0] data_in_1, | ||
output wire [31:0] data_out | ||
input wire [INPUT_WIDTH-1:0] data_in_2, | ||
input wire [INPUT_WIDTH-1:0] data_in_1, | ||
output reg [OUTPUT_WIDTH-1:0] data_out | ||
); | ||
|
||
reg [31:0] acc ; | ||
reg [OUTPUT_WIDTH-1:0] acc; | ||
|
||
always @(posedge clk or posedge rst) begin | ||
|
||
if (rst) begin | ||
acc <= 32'b0; | ||
data_out <= 32'b0; | ||
acc <= {output_width{1'b0}}; | ||
data_out <= {output_width{1'b0}}; | ||
end else begin | ||
acc <= acc + $signed(data_in_1) + $signed(data_in_2); | ||
data_out <= acc; | ||
end | ||
end | ||
|
||
|
||
//to sign extend we: | ||
//1. convert the input to signed | ||
//2. add the sign bit to the rest of the bits, that is (output_Width-input_width) times | ||
//ie. if ur output is 16 bits but ur input is 8 bits then u need to add 4 bits to the left | ||
//those 4 bits are of the same sign | ||
//check 222 again | ||
//3. assign the result to the acc | ||
|
||
wire sign_bit1 = data_in_1[INPUT_WIDTH-1]; | ||
wire sign_bit2 = data_in_2[INPUT_WIDTH-1]; | ||
localparam LENGTH_EXTEND = OUTPUT_WIDTH - INPUT_WIDTH; | ||
//locaparam is used to define a constant value that can be used in the module, better for compile time | ||
|
||
|
||
acc <= acc | ||
+ $signed({{LENGTH_EXTEND{sign_bit1}}, data_in_1}) | ||
* $signed({{LENGTH_EXTEND{sign_bit2}}, data_in_2}); | ||
|
||
end | ||
end | ||
|
||
endmodule | ||
always @(posedge clk) begin | ||
data_out <= acc; | ||
end | ||
endmodule |
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