Skip to content

Commit 31406f2

Browse files
committed
parameter functions
1 parent d67d592 commit 31406f2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

primitives/param-funcs.fil

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Computes the number of bits needed to represent the constant [N].
3+
* Usage:
4+
* ```filament
5+
* BN := new BitsNeeded[N];
6+
* let Bits = BN::Out; // Out represents number of bits for [N]
7+
* ```
8+
*/
9+
comp BitsNeeded[N]<'G:1>() -> () with {
10+
some Out where Out == log2(N)+1, Out > 0;
11+
} {
12+
let Bits = log2(N)+1; assume Bits > 0;
13+
Out := Bits;
14+
}

primitives/reshape.fil

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "primitives/core.fil";
2+
import "primitives/param-funcs.fil";
23

34
// A highly parameterized serializer. The parameters are:
45
// * W: The width of the inputs
@@ -201,7 +202,8 @@ comp CollectValid[W, N]<'G:1>(
201202
out[N]: ['G, 'G+1] W,
202203
block_valid: ['G, 'G+1] 1
203204
) where W > 0 {
204-
let Bits = log2(N)+1; assume Bits > 0;
205+
BN := new BitsNeeded[N];
206+
let Bits = BN::Out;
205207

206208
// Increment the index if the value on the stream is valid
207209
idx := new Prev[Bits, 1]<'G>(reset.out);

0 commit comments

Comments
 (0)