All projects

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

Input controllers Crossbar Output controllers PE U2D D2U L2R R2L PE U2D D2U L2R R2L
Figure 1. Router block diagram. Each input and output controller holds one single-packet buffer per virtual channel (the two small boxes). Each output has a separate round-robin arbiter per virtual channel.

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 & ro reacts 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.

clk polarity link even odd even odd even crossbar odd even odd even odd
Figure 2. The link and the crossbar always serve opposite virtual channels. Simplified timing; the exact polarity-to-VC mapping follows the spec.

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.

Table 1. Routing fields: course spec compared with my internal header
FieldCourse spec (ring)My header (mesh)
Direction1 direction bitX and Y direction bits
DistanceUnary hop countSeparate 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.

Table 2. Router test results, Icarus Verilog
TestWhat it checksResult
ResetEvery ready output is 1, every send is 0, polarity is 0Pass
PE to every outputAll paths out of the local port, on both VCsPass
Hop latencyUncontended hop takes 2 cyclesPass
Mesh pathsEvery input going straight, turning X to Y, or delivering to PEPass
Contention4 inputs requesting the PE output at oncePass
Back-pressureOne output held not-readyPass
Random traffic400 random legal packets with random stalls on every output; scoreboard checks loss, duplication, and corruptionPass
Two-router handshakeCycle-by-cycle trace with the sink stalled and released; 10 packets in orderPass
Arbiter4, then 2, then 1 requester; winner and pointer checked for each of 21 grantsPass
4×4 mesh, all-to-all240 packets across both VCs, each to the correct node240 / 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.

Figure 3. 4×4 mesh simulation traces, sampled just before each rising clock edge. Router rN is node N, numbered row by row from the top left; r1→r2 is the link from router 1 to router 2.

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.