Skip to content

Commit e1ffd2d

Browse files
committed
bugfix minimize expression
1 parent f27d970 commit e1ffd2d

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

crates/filament/src/ir_passes/schedule/solve.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,15 @@ impl Visitor for Solve {
342342
self.sol.assert(self.sol.lte(src_start, dst_start)).unwrap();
343343

344344
// We can create a register that will extend the lifetime of the source port to the destination port. Given a src port valid from [a, b], and a dest port from [c, d], we need a register that holds from [b-1, d].
345-
// The number of FFs necessary to do this is thus d - b - 1
346-
let reg_expr = self
347-
.sol
348-
.sub(self.sol.sub(dst_end, src_end), self.sol.numeral(1));
345+
// The number of FFs necessary to do this is thus d - b
346+
let reg_expr = self.sol.sub(dst_end, src_end);
347+
// reg_expr cannot be negative
348+
let reg_expr = self.sol.ite(
349+
self.sol.gte(reg_expr, self.sol.numeral(0)),
350+
reg_expr,
351+
self.sol.numeral(0),
352+
);
353+
349354
// multiply by the width of the port
350355
let reg_expr = self.sol.times(reg_expr, self.sol.numeral(width));
351356

tests/schedule/multi-event.expect

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"out": {"0": [3, 3], "1": [6, 6]}, "cycles": 4}
2+

tests/schedule/multi-event.fil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import "primitives/core.fil";
2+
3+
#[schedule=1]
4+
comp main<'G: 2>(
5+
go: interface['G],
6+
in0: ['G, 'G+2] 32,
7+
in1: ['G, 'G+2] 32,
8+
) -> (
9+
out: ['G, 'G+2] 32
10+
)
11+
{
12+
sum := new Add[32]<'G, 'G+2>(in0, in1);
13+
14+
out = sum.out;
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"in0": [
3+
1, 2
4+
],
5+
"in1": [
6+
2, 4
7+
]
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Add]
2+
combinational = true
3+
ports.out = 0.4

0 commit comments

Comments
 (0)