-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Primitives] Add multiport memory (#1254)
* [Primitives] Add multiport memory primitive * [MLIR] Add support for multiport memory --------- Co-authored-by: rsetaluri <[email protected]>
- Loading branch information
Showing
11 changed files
with
309 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from magma.bits import Bits | ||
from magma.bitutils import clog2 | ||
from magma.clock import Enable | ||
from magma.clock_io import ClockIO | ||
from magma.generator import Generator2 | ||
from magma.interface import IO | ||
from magma.t import In, Out, Kind | ||
|
||
|
||
class MultiportMemory(Generator2): | ||
def __init__( | ||
self, | ||
height: int, | ||
T: Kind, | ||
num_read_ports: int = 1, | ||
num_write_ports: int = 1, | ||
has_read_enable: bool = False | ||
): | ||
if num_read_ports < 1: | ||
raise ValueError("At least one read port is required") | ||
if num_write_ports < 0: | ||
raise ValueError("Number of write ports must be non-negative") | ||
|
||
self.num_read_ports = num_read_ports | ||
self.has_read_enable = has_read_enable | ||
self.num_write_ports = num_write_ports | ||
self.T = T | ||
self.height = height | ||
|
||
addr_width = clog2(height) | ||
|
||
self.io = ClockIO() | ||
for i in range(num_read_ports): | ||
self.io += IO(**{ | ||
f"RADDR_{i}": In(Bits[addr_width]), | ||
f"RDATA_{i}": Out(T) | ||
}) | ||
if has_read_enable: | ||
self.io += IO(**{f"RE_{i}": In(Enable)}) | ||
for i in range(num_write_ports): | ||
self.io += IO(**{ | ||
f"WADDR_{i}": In(Bits[addr_width]), | ||
f"WDATA_{i}": In(T), | ||
f"WE_{i}": In(Enable) | ||
}) | ||
self.primitive = True |
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,20 @@ | ||
module attributes {circt.loweringOptions = "locationInfoStyle=none"} { | ||
hw.module @multiport_memory(%raddr_0: i2, %raddr_1: i2, %waddr_0: i2, %wdata_0: i5, %we_0: i1, %waddr_1: i2, %wdata_1: i5, %we_1: i1, %clk: i1) -> (rdata_0: i5, rdata_1: i5) { | ||
%2 = sv.reg name "MultiportMemory_inst0" : !hw.inout<!hw.array<4xi5>> | ||
%3 = sv.array_index_inout %2[%raddr_0] : !hw.inout<!hw.array<4xi5>>, i2 | ||
%4 = sv.array_index_inout %2[%raddr_1] : !hw.inout<!hw.array<4xi5>>, i2 | ||
%0 = sv.read_inout %3 : !hw.inout<i5> | ||
%1 = sv.read_inout %4 : !hw.inout<i5> | ||
%5 = sv.array_index_inout %2[%waddr_0] : !hw.inout<!hw.array<4xi5>>, i2 | ||
%6 = sv.array_index_inout %2[%waddr_1] : !hw.inout<!hw.array<4xi5>>, i2 | ||
sv.alwaysff(posedge %clk) { | ||
sv.if %we_0 { | ||
sv.passign %5, %wdata_0 : i5 | ||
} | ||
sv.if %we_1 { | ||
sv.passign %6, %wdata_1 : i5 | ||
} | ||
} | ||
hw.output %0, %1 : i5, i5 | ||
} | ||
} |
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,26 @@ | ||
// Generated by CIRCT circtorg-0.0.0-1773-g7abbc4313 | ||
module multiport_memory( | ||
input [1:0] raddr_0, | ||
raddr_1, | ||
waddr_0, | ||
input [4:0] wdata_0, | ||
input we_0, | ||
input [1:0] waddr_1, | ||
input [4:0] wdata_1, | ||
input we_1, | ||
clk, | ||
output [4:0] rdata_0, | ||
rdata_1 | ||
); | ||
|
||
reg [3:0][4:0] MultiportMemory_inst0; | ||
always_ff @(posedge clk) begin | ||
if (we_0) | ||
MultiportMemory_inst0[waddr_0] <= wdata_0; | ||
if (we_1) | ||
MultiportMemory_inst0[waddr_1] <= wdata_1; | ||
end // always_ff @(posedge) | ||
assign rdata_0 = MultiportMemory_inst0[raddr_0]; | ||
assign rdata_1 = MultiportMemory_inst0[raddr_1]; | ||
endmodule | ||
|
30 changes: 30 additions & 0 deletions
30
tests/test_backend/test_mlir/golds/multiport_memory_re.mlir
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,30 @@ | ||
module attributes {circt.loweringOptions = "locationInfoStyle=none"} { | ||
hw.module @multiport_memory_re(%raddr_0: i2, %raddr_1: i2, %waddr_0: i2, %wdata_0: i5, %we_0: i1, %waddr_1: i2, %wdata_1: i5, %we_1: i1, %clk: i1, %re_0: i1, %re_1: i1) -> (rdata_0: i5, rdata_1: i5) { | ||
%2 = sv.reg name "MultiportMemory_inst0" : !hw.inout<!hw.array<4xi5>> | ||
%3 = sv.array_index_inout %2[%raddr_0] : !hw.inout<!hw.array<4xi5>>, i2 | ||
%4 = sv.array_index_inout %2[%raddr_1] : !hw.inout<!hw.array<4xi5>>, i2 | ||
%5 = sv.read_inout %3 : !hw.inout<i5> | ||
%6 = sv.reg name "read_reg_0" : !hw.inout<i5> | ||
%0 = sv.read_inout %6 : !hw.inout<i5> | ||
%7 = sv.read_inout %4 : !hw.inout<i5> | ||
%8 = sv.reg name "read_reg_1" : !hw.inout<i5> | ||
%1 = sv.read_inout %8 : !hw.inout<i5> | ||
%9 = sv.array_index_inout %2[%waddr_0] : !hw.inout<!hw.array<4xi5>>, i2 | ||
%10 = sv.array_index_inout %2[%waddr_1] : !hw.inout<!hw.array<4xi5>>, i2 | ||
sv.alwaysff(posedge %clk) { | ||
sv.if %we_0 { | ||
sv.passign %9, %wdata_0 : i5 | ||
} | ||
sv.if %we_1 { | ||
sv.passign %10, %wdata_1 : i5 | ||
} | ||
sv.if %re_0 { | ||
sv.passign %6, %5 : i5 | ||
} | ||
sv.if %re_1 { | ||
sv.passign %8, %7 : i5 | ||
} | ||
} | ||
hw.output %0, %1 : i5, i5 | ||
} | ||
} |
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,34 @@ | ||
// Generated by CIRCT circtorg-0.0.0-1773-g7abbc4313 | ||
module multiport_memory_re( | ||
input [1:0] raddr_0, | ||
raddr_1, | ||
waddr_0, | ||
input [4:0] wdata_0, | ||
input we_0, | ||
input [1:0] waddr_1, | ||
input [4:0] wdata_1, | ||
input we_1, | ||
clk, | ||
re_0, | ||
re_1, | ||
output [4:0] rdata_0, | ||
rdata_1 | ||
); | ||
|
||
reg [3:0][4:0] MultiportMemory_inst0; | ||
reg [4:0] read_reg_0; | ||
reg [4:0] read_reg_1; | ||
always_ff @(posedge clk) begin | ||
if (we_0) | ||
MultiportMemory_inst0[waddr_0] <= wdata_0; | ||
if (we_1) | ||
MultiportMemory_inst0[waddr_1] <= wdata_1; | ||
if (re_0) | ||
read_reg_0 <= MultiportMemory_inst0[raddr_0]; | ||
if (re_1) | ||
read_reg_1 <= MultiportMemory_inst0[raddr_1]; | ||
end // always_ff @(posedge) | ||
assign rdata_0 = read_reg_0; | ||
assign rdata_1 = read_reg_1; | ||
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