Skip to content

Commit 429b3d4

Browse files
committed
new primitives to implement space and time decimation. also, a counter
1 parent edf1b31 commit 429b3d4

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

primitives/reshape.fil

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,34 @@ comp SplitWire[W, N, ?L=1]<'G: L>(
156156
spl := new SplitWire[W, N-1, L]<'G>(rem.out);
157157
out{1..N} = spl.out{0..N-1};
158158
}
159-
}
159+
}
160+
161+
// Decimates inputs in space. A module provides N inputs and this module
162+
// returns the first one as its output.
163+
comp DecimateSpace[W, N]<'G: 1>(
164+
in[W]: ['G, 'G+1] W
165+
) -> (
166+
out: ['G, 'G+1] W
167+
) where N > 0 {
168+
out = in{0};
169+
}
170+
171+
// Decimates inputs in time using a valid tag. Valid is asserted every N
172+
// cycles an input is sent into the module (i.e., `en` is asserted).
173+
comp DecimateTime[W, N]<'G: 1>(
174+
en: interface['G],
175+
in: ['G, 'G+1] W
176+
) -> (
177+
out: ['G, 'G+1] W,
178+
valid: ['G, 'G+1] 1
179+
) where W > 0, N > 0 {
180+
let Bits = log2(N) + 1;
181+
assume Bits > 0;
182+
183+
counter := new Counter[Bits, N]<'G>();
184+
one := new Const[Bits, 1]<'G>();
185+
eq := new Eq[Bits]<'G>(counter.out, one.out);
186+
187+
out = in;
188+
valid = eq.out;
189+
}

primitives/state.fil

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,31 @@ comp Shift[W, D, ?N=1]<'G: 1>(
7575
out_split := new SplitWire[W, N]<'G+D>(f{D});
7676
out{0..N} = out_split.out{0..N};
7777
}
78-
/* ANCHOR_END: shift */
78+
/* ANCHOR_END: shift */
79+
80+
// A counter that counts up by one every time `en` is asserted and resets
81+
// when it reaches the value `N`.
82+
comp Counter[W, N]<'G:1>(
83+
en: interface['G]
84+
) -> (out: ['G, 'G+1] W) with {
85+
let Out = log2(N) + 1;
86+
} where W > 0 {
87+
// Needed to ensure that N can fit within W.
88+
let Bits = log2(N)+1;
89+
assume Bits > 0;
90+
assume W >= Bits;
91+
92+
one := new Const[Bits, 1]<'G>();
93+
counter := new Prev[Bits, 1]<'G>(mux.out);
94+
add := new Add[Bits]<'G>(counter.prev, one.out);
95+
96+
max := new Const[Bits, N]<'G>();
97+
eq := new Eq[Bits]<'G>(counter.prev, max.out);
98+
99+
zero := new Const[Bits, 0]<'G>();
100+
mux := new Mux[Bits]<'G>(eq.out, counter.prev, zero.out);
101+
102+
resized := new ZeroExtend[Bits, W]<'G>(counter.prev);
103+
104+
out = resized.out;
105+
}

0 commit comments

Comments
 (0)