-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share cells in more situations (#1753)
* Sharing fixes * `is_some_and` not stable in 1.67 * Suggested changes * Treat all invokes as writes * Test empty invokes
- Loading branch information
Showing
8 changed files
with
244 additions
and
32 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,58 @@ | ||
import "primitives/core.futil"; | ||
component write_one<"state_share"=1>(@go go: 1, @clk clk: 1, @reset reset: 1) -> (out: 32, @done done: 1) { | ||
cells { | ||
@data x = std_reg(32); | ||
} | ||
wires { | ||
group invoke0<"promote_static"=1> { | ||
x.write_en = 1'd1; | ||
invoke0[done] = x.done; | ||
x.in = 32'd1; | ||
} | ||
out = x.out; | ||
} | ||
control { | ||
@promote_static invoke0; | ||
} | ||
} | ||
component main(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { | ||
cells { | ||
@external @data mem = std_mem_d1(32, 2, 1); | ||
@data x = write_one(); | ||
} | ||
wires { | ||
group invoke0 { | ||
x.go = 1'd1; | ||
invoke0[done] = x.done; | ||
} | ||
group invoke1 { | ||
x.go = 1'd1; | ||
invoke1[done] = x.done; | ||
} | ||
group invoke2<"promote_static"=1> { | ||
mem.write_en = 1'd1; | ||
invoke2[done] = mem.done; | ||
mem.addr0 = 1'd0; | ||
mem.write_data = x.out; | ||
} | ||
group invoke3 { | ||
x.go = 1'd1; | ||
invoke3[done] = x.done; | ||
} | ||
group invoke4<"promote_static"=1> { | ||
mem.write_en = 1'd1; | ||
invoke4[done] = mem.done; | ||
mem.addr0 = 1'd1; | ||
mem.write_data = x.out; | ||
} | ||
} | ||
control { | ||
seq { | ||
invoke0; | ||
invoke1; | ||
@promote_static invoke2; | ||
invoke3; | ||
@promote_static invoke4; | ||
} | ||
} | ||
} |
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,33 @@ | ||
// -p pre-opt -p post-opt | ||
import "primitives/core.futil"; | ||
|
||
component write_one() -> (out: 32) { | ||
cells { | ||
x = std_reg(32); | ||
} | ||
wires { | ||
out = x.out; | ||
} | ||
control { | ||
invoke x(in = 32'd1)(); | ||
} | ||
} | ||
|
||
component main() -> () { | ||
cells { | ||
@external mem = std_mem_d1(32, 2, 1); | ||
// these should be shared | ||
x = write_one(); | ||
y = write_one(); | ||
} | ||
wires {} | ||
control { | ||
seq { | ||
invoke x()(); | ||
invoke y()(); // x is dead here | ||
invoke mem(addr0 = 1'd0, write_data = y.out)(); | ||
invoke x()(); | ||
invoke mem(addr0 = 1'd1, write_data = x.out)(); | ||
} | ||
} | ||
} |
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,66 @@ | ||
import "primitives/core.futil"; | ||
component my_reg<"state_share"=1>(@data in: 32, @go go: 1, @clk clk: 1, @reset reset: 1) -> (@stable out: 32, @done done: 1) { | ||
cells { | ||
@data r = std_reg(32); | ||
} | ||
wires { | ||
group invoke0<"promote_static"=1> { | ||
r.write_en = 1'd1; | ||
invoke0[done] = r.done; | ||
r.in = in; | ||
} | ||
out = r.out; | ||
} | ||
control { | ||
@promote_static invoke0; | ||
} | ||
} | ||
static<4> component main(@go go: 1, @clk clk: 1, @reset reset: 1) -> (@done done: 1) { | ||
cells { | ||
@external @data mem = std_mem_d1(32, 2, 1); | ||
@generated r = std_reg(32); | ||
} | ||
wires { | ||
static<1> group invoke00 { | ||
r.write_en = 1'd1; | ||
r.in = 32'd0; | ||
} | ||
static<1> group invoke10 { | ||
mem.write_en = 1'd1; | ||
mem.addr0 = 1'd0; | ||
mem.write_data = r.out; | ||
} | ||
static<1> group invoke20 { | ||
r.write_en = 1'd1; | ||
r.in = 32'd1; | ||
} | ||
static<1> group invoke30 { | ||
mem.write_en = 1'd1; | ||
mem.addr0 = 1'd1; | ||
mem.write_data = r.out; | ||
} | ||
static<1> group no-op { | ||
} | ||
static<2> group no-op0 { | ||
} | ||
static<3> group no-op1 { | ||
} | ||
} | ||
control { | ||
static<4> par { | ||
invoke00; | ||
static<2> seq { | ||
no-op; | ||
invoke10; | ||
} | ||
static<3> seq { | ||
no-op0; | ||
invoke20; | ||
} | ||
static<4> seq { | ||
no-op1; | ||
invoke30; | ||
} | ||
} | ||
} | ||
} |
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,32 @@ | ||
// -p pre-opt -p post-opt | ||
import "primitives/core.futil"; | ||
|
||
component my_reg<"state_share"=1>(@data in: 32) -> (@stable out: 32) { | ||
cells { | ||
r = std_reg(32); | ||
} | ||
wires { | ||
out = r.out; | ||
} | ||
control { | ||
invoke r(in = in)(); | ||
} | ||
} | ||
|
||
component main() -> () { | ||
cells { | ||
@external mem = std_mem_d1(32, 2, 1); | ||
// the two `std_reg` created after inlining should be shared | ||
@inline r0 = my_reg(); | ||
@inline r1 = my_reg(); | ||
} | ||
wires {} | ||
control { | ||
seq { | ||
invoke r0(in = 32'd0)(); | ||
invoke mem(addr0 = 1'd0, write_data = r0.out)(); | ||
invoke r1(in = 32'd1)(); | ||
invoke mem(addr0 = 1'd1, write_data = r1.out)(); | ||
} | ||
} | ||
} |
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