NoC router for a 4×4 mesh
A 5-port packet router in synthesizable Verilog, built for a 16-node mesh multicore in USC's VLSI System Design course.
- Dates
- Aug 2026 to present
- Tools
- Verilog, Icarus Verilog
- Team
- 2 people. I designed the router, the round-robin arbiter, the internal header format, and the router testbenches. My partner built the network interface and the mesh top module.
- Results
- From RTL simulation. Synthesis, timing, and area come later in the course.
Overview
From a ring spec to a mesh
The course's architecture spec describes a router for a 4-node bidirectional ring: two ring directions plus a local port. This semester the target is a 4×4 mesh, so I redesigned the router for four mesh directions plus the local processing-element (PE) port.
The grader compiles our RTL unmodified against its own testbench. That fixes the top-level module, its 16 sets of node ports, the 64-bit packet format, and the local-port timing, so every internal choice had to fit those rules.
Architecture
Five ports, two virtual channels
Each packet is one 64-bit phit, buffered whole in a single-slot buffer, so the router uses virtual cut-through with no credits. Every port has a ready/send handshake.
- Input controller: two VC buffers with full bits. Its ready output depends only on stored state, so it's a Moore output. It requests one output port based on the routing decision.
- Output controller: two VC output buffers, plus a round-robin arbiter for each VC. The grant is combinational, so a transfer finishes on the next clock edge.
so = buf_full & roreacts to back-pressure in the same cycle. - Round-robin arbiter: a parameterized N-input rotating-priority arbiter built from two barrel shifters around a fixed-priority picker. The pointer moves past the winner only when there is contention.
- Capacity: up to 20 packets per router (5 ports, 2 VCs, input and output buffers).
Flow control
Time-sharing each link between two virtual channels
A global polarity bit toggles every cycle. In each cycle, one VC moves through the crossbar inside the router while the other VC crosses the links between routers. Each link carries a packet every cycle, and an uncontended hop takes 2 cycles.
Back-pressure propagates hop by hop. A full output buffer stops granting, a full input buffer drops its ready signal, and the upstream send signal stays low until space frees up.
Routing
XY routing with separate hop counters
Packets finish all X hops, then all Y hops, then eject to the PE. Dimension-order routing is deadlock-free in a mesh because no cycle of channel dependencies can form.
I replaced the spec's single direction bit and unary hop count with my own internal header. It carries separate X and Y hop counters, and each hop counts the active one down, so the remaining distance is always in the packet.
| Field | Course spec (ring) | My header (mesh) |
|---|---|---|
| Direction | 1 direction bit | X and Y direction bits |
| Distance | Unary hop count | Separate 4-bit hop-X and hop-Y counters, decremented each hop |
A code review found that packets injected in the grader's format were being misrouted. The fix is a translator at each PE port in the mesh top. It computes the internal fields when a packet is injected and restores the original format on delivery, so packets leave bit-identical to how they entered.
Verification
Layered, self-checking tests
Every testbench checks its own results, so a regression shows up immediately. Testing moved from directed checks to contention, then to cycle-by-cycle handshakes, and finally to constrained-random traffic with a scoreboard keyed by packet ID.
| Test | What it checks | Result |
|---|---|---|
| Reset | Every ready output is 1, every send is 0, polarity is 0 | Pass |
| PE to every output | All paths out of the local port, on both VCs | Pass |
| Hop latency | Uncontended hop takes 2 cycles | Pass |
| Mesh paths | Every input going straight, turning X to Y, or delivering to PE | Pass |
| Contention | 4 inputs requesting the PE output at once | Pass |
| Back-pressure | One output held not-ready | Pass |
| Random traffic | 400 random legal packets with random stalls on every output; scoreboard checks loss, duplication, and corruption | Pass |
| Two-router handshake | Cycle-by-cycle trace with the sink stalled and released; 10 packets in order | Pass |
| Arbiter | 4, then 2, then 1 requester; winner and pointer checked for each of 21 grants | Pass |
| 4×4 mesh, all-to-all | 240 packets across both VCs, each to the correct node | 240 / 240 |
Waveforms
Watch packets cross the mesh
These are Icarus Verilog traces from four of the full 4×4 mesh tests: XY routing, both virtual channels on one link, four packets fighting for one output, and a node that stops accepting packets. Pick a numbered event to jump to it, or move the cursor to read every signal in that cycle. Packets are labeled with their ID, source, destination and VC.
The interactive waveform needs JavaScript. It shows four mesh tests: a packet routed from node 1 to node 14, two virtual channels sharing one link, four packets arbitrated at node 5, and node 14 holding off six packets for 40 cycles before they drain.
Hardest bug
Ready and valid must look at opposite buffers
The input controller first used the same VC buffer for both its ready signal and its crossbar request. Because the two VCs are always in opposite phases, ready has to look at the buffer for the VC that's on the link this cycle, while the crossbar request has to look at the other one. Fixing the indexing so each signal reads its own buffer made the random-traffic test pass with no loss or duplication.
The lesson I took from it: with time-multiplexed resources, write down which phase each signal belongs to before writing the RTL.
Next
What's left
- Arbitration shown for every output with all of its inputs requesting at once.
- SystemVerilog assertions and functional coverage on the router.
- Synthesis with Synopsys Design Compiler, equivalence checking, timing, and place and route later in the course.
Source code isn't posted while the course is running, in line with USC's academic integrity policy. I'm happy to walk through the design in an interview.