Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
minseongg committed Oct 2, 2024
1 parent 00ddf44 commit 70c2f9f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/docs/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Here is a list of all the people who have worked on HazardFlow:
- [Gieun Jeong](https://cp.kaist.ac.kr/gieun.jeong/)
- Jihoon Kim

**Previous Contributos**
**Previous Contributors**

- Seunghyeon Jeong
- Tanapoom Sermchaiwong
16 changes: 11 additions & 5 deletions doc/docs/tutorial/custom_fifo.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,28 @@ The FIFO Queue egress interface is a simple valid-ready interface `Vr<P>`. -->
Based on the above submodules, we can implement the custom FIFO in a concise and modular way:

```rust,noplayground
fn custom_fifo(ingress: [Vr<u32>; 5]) -> Vr<u32> {
fn custom_fifo(ingress: [Vr<u32>; N]) -> Vr<u32> {
ingress
.masked_merge()
.map_resolver::<((), FifoS<(u32, U<{ clog2(5) }>), 5>)>(|er| {
.map_resolver::<((), FifoS<(u32, U<{ clog2(N) }>), M>)>(|er| {
let (_, fifo_s) = er.inner;
fifo_s.inner.fold(Array::from([false; 5]), |acc, (_p, idx)| acc.set(idx, true))
range::<N>().fold(Array::from([false; N]), |acc, i| {
if i.resize() >= fifo_s.len {
acc
} else {
acc.set(fifo_s.inner[wrapping_add(fifo_s.raddr, i, M.into_u())].1, true)
}
})
})
.transparent_fifo()
.map(|(ip, _idx)| ip)
}
```

- We used `u32` for the payload type, and 5 for the number of ingress interfaces and FIFO size.
- We used `u32` for the payload type, `N` for the number of ingress interfaces and `M` for the FIFO size.
- `fifo_s.inner` represents the inner elements of the FIFO.
- We `fold` the inner elements of the FIFO in the `map_resolver` combinator:
- The initializer is a boolean array with all elements as `false` of size 5.
- The initializer is a boolean array with all elements as `false` of size `N`
- The index of the initializer array indicates the index of the ingress interfaces.
- We iterate through all the elements within the FIFO and set the accumulator's value at the index in each FIFO element to `true`.
- The final result indicates which ingress interfaces are present in the current FIFO.
Expand Down
6 changes: 3 additions & 3 deletions doc/docs/tutorial/fir_filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ As in the above figure, it can be divide into 3 submodules: `window`, `weight`,

* It keeps the weight vector `[b0, b1, b2]` persistent throughout the program.
* It takes the input vector `[v0, v1, v2]` and returns the output vector `[b0·v0, b1·v1, b2·v2]`.
* This submodule can be simply represented by a `map` combinator.

**`sum` submodule:**

Expand Down Expand Up @@ -88,9 +89,8 @@ impl<P: Copy + Default> Valid<P> {
It takes an `Valid<P>` and returns `Valid<Array<P, N>>`.
It tracks the latest `N` valid input signals.
The [`fsm_map` interface combinator](https://kaist-cp.github.io/hazardflow/docs/hazardflow_designs/std/hazard/struct.I.html#method.fsm_map) is provided by the HazardFlow HDL standard library.
It transforms the ingress payload to the egress payload, calculates the next state for the next clock cycle, and leaves the resolver signal untouched.
It takes an initial state, and an anonymous function, and returns a new interface.
The initial state is defined as `P::default().repeat::<N>()` in our example.
It computes the egress payload and the next state based on the ingress payload and the current state, and updates the state when the ingress tranfser happens.
The initial state is defined as `P::default().repeat::<{ N - 1 }>()` in our example.
The anonymous function is where we specify the fsm logic from the `(ingress payload, current state)` to the `(egress payload, next state)`.

<!--
Expand Down
17 changes: 13 additions & 4 deletions hazardflow-designs/src/examples/custom_fifo.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Masked Merge implementation
//! Custom FIFO implementation

use crate::prelude::*;
use crate::std::*;

const N: usize = 5;
const M: usize = 5;

/// Masked merge trait
pub trait MaskedMergeExt<P: Copy + Default, const N: usize>: Interface
where [(); clog2(N)]:
Expand Down Expand Up @@ -40,12 +43,18 @@ where [(); clog2(N)]:

/// Masked Merge Combinator
#[synthesize]
pub fn custom_fifo(ingress: [Vr<u32>; 5]) -> Vr<u32> {
pub fn custom_fifo(ingress: [Vr<u32>; N]) -> Vr<u32> {
ingress
.masked_merge()
.map_resolver::<((), FifoS<(u32, U<{ clog2(5) }>), 5>)>(|er| {
.map_resolver::<((), FifoS<(u32, U<{ clog2(N) }>), M>)>(|er| {
let (_, fifo_s) = er.inner;
fifo_s.inner.fold(Array::from([false; 5]), |acc, (_p, idx)| acc.set(idx, true))
range::<N>().fold(Array::from([false; N]), |acc, i| {
if i.resize() >= fifo_s.len {
acc
} else {
acc.set(fifo_s.inner[wrapping_add(fifo_s.raddr, i, M.into_u())].1, true)
}
})
})
.transparent_fifo()
.map(|(ip, _idx)| ip)
Expand Down

0 comments on commit 70c2f9f

Please sign in to comment.