From 478cc0cd59de2638051a63ad776c31d7a5caa074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Thu, 1 Oct 2026 10:10:38 +0200 Subject: [PATCH 01/10] asap7/chi_async_bridge: XiangShan's asynchronous CHI bridge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A new test design with one concern: an asynchronous clock crossing, constrained without exceptions that hide a path, and implemented by the flow as constrained. It is XiangShan's CHI bridge between its tile and its network-on-chip, both halves in one block: six flit channels, each a rocket-chip async queue, with their link credits, handshakes and a reset synchroniser per domain, as readable parameterised SystemVerilog read by slang. constraint.sdc bounds every crossing with set_max_delay -ignore_clock_latency, budgets the ports per domain as the platform's constraints.sdc budgets a macro's, keeps synchroniser hops short, and checks the names it constrains against the synthesised netlist, stopping the flow if they are wrong. The core period, 300 ps, is where XiangShan's own bridge, elaborated from its Chisel and hardened alone through this flow, just fails at global route; this design fails there on the same path, within 1.5 %. README.md has the numbers. base is XiangShan's bridge as it is; FLOW_VARIANT=small|medium are faster rungs. Signed-off-by: Øyvind Harboe Co-Authored-By: Claude Opus 5.5 --- flow/designs/asap7/chi_async_bridge/README.md | 193 ++++++++++++++++++ flow/designs/asap7/chi_async_bridge/config.mk | 30 +++ .../asap7/chi_async_bridge/constraint.sdc | 161 +++++++++++++++ .../src/chi_async_bridge/async_queue_sink.sv | 89 ++++++++ .../chi_async_bridge/async_queue_source.sv | 99 +++++++++ .../src/chi_async_bridge/chi_async_bridge.sv | 180 ++++++++++++++++ .../chi_async_bridge/chi_async_bridge_sink.sv | 182 +++++++++++++++++ .../chi_async_bridge_source.sv | 176 ++++++++++++++++ .../designs/src/chi_async_bridge/reset_gen.sv | 27 +++ .../src/chi_async_bridge/shadow_buffer.sv | 63 ++++++ .../src/chi_async_bridge/sync_shift_reg.sv | 34 +++ 11 files changed, 1234 insertions(+) create mode 100644 flow/designs/asap7/chi_async_bridge/README.md create mode 100644 flow/designs/asap7/chi_async_bridge/config.mk create mode 100644 flow/designs/asap7/chi_async_bridge/constraint.sdc create mode 100644 flow/designs/src/chi_async_bridge/async_queue_sink.sv create mode 100644 flow/designs/src/chi_async_bridge/async_queue_source.sv create mode 100644 flow/designs/src/chi_async_bridge/chi_async_bridge.sv create mode 100644 flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv create mode 100644 flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv create mode 100644 flow/designs/src/chi_async_bridge/reset_gen.sv create mode 100644 flow/designs/src/chi_async_bridge/shadow_buffer.sv create mode 100644 flow/designs/src/chi_async_bridge/sync_shift_reg.sv diff --git a/flow/designs/asap7/chi_async_bridge/README.md b/flow/designs/asap7/chi_async_bridge/README.md new file mode 100644 index 0000000000..8b6a1f3025 --- /dev/null +++ b/flow/designs/asap7/chi_async_bridge/README.md @@ -0,0 +1,193 @@ +# chi_async_bridge + +The asynchronous bridge that carries XiangShan's CHI link between the +core's clock and the network-on-chip's. Six flit channels, each an +asynchronous queue, cross from one clock domain to the other, with their +link credits and handshakes. Both halves of the bridge are in this one +block, so timing analysis sees both ends of every crossing. + +The design exists to measure one thing: whether the flow implements an +asynchronous crossing the way its constraints describe it. Every path +from one clock to the other meets its budget, nothing tries to fix hold +across the asynchronous boundary, each synchroniser's flops stay +together, and what is left to fail is the logic inside each domain. + +## The crossing + +```mermaid +flowchart LR + subgraph T[core clock: the tile half, in XSTileWrap] + L2[tile's CHI port] --> SB[shadow buffer] + SB --> MEM[queue memory] + SB --> WP[write pointer, Gray] + RS[read pointer synchroniser] + TS[rx queue sink] --> L2 + end + subgraph N[NoC clock: the NoC half, in XSNoCTop] + WS[write pointer synchroniser] --> MUX[read mux] + MUX --> DQ[deq_bits_reg] + RP[read pointer, Gray] + DQ --> NOC[NoC's CHI port] + end + WP -->|crosses| WS + MEM -->|crosses| MUX + RP -->|crosses| RS +``` + +That is one tx channel; the rx channels are the mirror image, and every +link credit is a queue of its own with no memory, only pointers. + +Three kinds of path cross: + +| path | from | to | what it must do | +|---|---|---|---| +| a pointer | a Gray-coded pointer flop | the first flop of a synchroniser | all its bits arrive within one period of the writing clock, so the reader never sees a code that was never written | +| the data | the queue memory, written on one clock | `deq_bits_reg`, through the read mux, on the other | arrive before the pointer that announces it has been synchronised | +| a handshake | a link-level signal | the first flop of a synchroniser | arrive; it is a level | + +None of them can be timed against the other clock's edges, because the +clocks have no phase relation. Each is bounded instead by a delay +measured from its first flop's clock pin to its last flop's data pin. + +## Constraints + +`constraint.sdc` sets the two clocks and says, in order: + +- the clocks are asynchronous to each other, and paths between them are + still timed (`set_clock_groups -asynchronous -allow_paths`); +- a path from one clock to the other must take less than one period of + the clock it starts on, ignoring clock latency + (`set_max_delay -ignore_clock_latency`): the Gray-code bound, which + also covers the data; +- there is no hold check between the clocks (`set_false_path -hold`); +- each domain's ports are budgeted as `$PLATFORM_DIR/constraints.sdc` + budgets a single-clock macro's, with `set_max_delay`, at that domain's + period; +- the step from one synchroniser flop to the next is short. This is the + only constraint that has to name instances. + +The last one is why the file checks itself. A name in an SDC is +written against the RTL and read against the synthesised netlist, and +OpenSTA treats a name that matches nothing as a warning and drops the +whole constraint. So `constraint.sdc` counts the flops it names and +checks that each synchroniser flop drives the next one and nothing +else; if synthesis has renamed or restructured them, the flow stops at +the synthesis stage with an error saying which. + +What synthesis does to the names, on this design: + +| in the RTL | in the netlist | +|---|---| +| `sync_shift_reg ridx_gray`, its `bit_[2]`, flop `sync[1]` | `sink.asyncQSource_dat_flit.ridx_gray.bit_[2].sync[1]$_DFF_PP0_`: the hierarchy flattened with `.`, yosys's cell type appended | +| the register `ridx_gray` that drives the output `async_ridx` | `...async_ridx[0]$_DFF_PP0_`: a flop takes the name of the net it drives, not of the variable that holds it | +| the same flop, in the database and in timing analysis | `bit_\[2\].sync\[1\]` in ODB, `bit_[2].sync[1]` from `get_full_name` | +| one flop driving the next | a flop, an inverter, a flop: asap7's flop with asynchronous set and reset, `DFFASRHQNx1`, has only an inverted output | + +The check is written against the right-hand column, and fails the +build when it stops being true. + +## Where it comes from + +XiangShan's tile is wrapped in `XSTileWrap` (`xiangshan/XSTileWrap.scala`), +which puts the tile half of the bridge, XSCache's `CHIAsyncBridgeSource`, +beside it on the core clock. The NoC half, `CHIAsyncBridgeSink`, is in +`XSNoCTop` on the NoC clock. Both are in XSCache's +`xscache/chi/AsyncBridge.scala`, built from rocket-chip's `AsyncQueue` +and `AsyncResetSynchronizerShiftReg`; the source files cite the lines +each piece models. The queue parameters are XiangShan's own +(`AsyncQueueParams(depth = 16, sync = 3, safe = false)`), and the flit +widths are those of its default CHI configuration: 125 bits for a +request, 51 for a response, 385 for data, 88 for a snoop. + +Everything a hardened XSTile sees at its CHI pins is this bridge: every +signal the tile sends ends at a flop in it, and every signal the tile +receives leaves from one (one handshake through a gate after it). That +is why +a block like XSTile is constrained with `set_max_delay` budgets on its +ports rather than with input and output delays, and why only its +register-to-register paths can fail timing closure. + +Not modelled: the NoC's CHI link layer beyond the bridge (link-state +machines and the credit managers), which is logic of the NoC's own +domain. Its ready signals and credits are ports here. + +## Results + +The core clock is set where the flow stops keeping up: given 420, 380 +or 340 ps it closes, each time within a few picoseconds of the target; +given 300 ps, the worst path just fails. That path is the core half's async queue sink, from the read +pointer through the read-mux select, buffered out to every bit of a +385-bit data flit, into `deq_bits_reg`: the queue's own logic, as in +XiangShan. + +This design reproduces XiangShan's bridge. Both were run through the +same flow and constraints at the same targets, to global route; the +XiangShan side is XiangShan's own `CHIAsyncBridgeSource` and +`CHIAsyncBridgeSink`, elaborated from its Chisel with its parameters +and hardened alone. + +| at global route | target | this design | XiangShan's bridge | +|---|---|---|---| +| core clock, min period | 340 ps | 339.7 ps | 340.0 ps | +| core clock, min period | 300 ps | 305.9 ps | 301.4 ps | +| worst path, at 300 ps | | async queue sink read, rx dat | the same | +| its logic / inserted buffers / wire | | 163 / 80 / 22 ps | 159 / 76 / 22 ps | +| flops | | 35,106 | 35,043 | + +Through the rest of the flow, base ends at final with a worst slack of +-23.1 ps (core clock min period 323.1 ps), on the shadow buffer's read +pointer into the async queue's memory write, the class that comes +second at global route. Detailed routing also leaves 149 max-slew +violations on 9 nets, all of them a queue's entry write-enable or read +select, decoded once and buffered out across a 385-bit entry, which +global route did not report. + +The NoC half is not calibrated: XiangShan's NoC link layer, left out +here, is in its NoC domain's worst path. Both NoC domains keep more than +200 ps of slack at the NoC period, so neither limits the design. + +The clock trees are the ones OpenROAD's CTS builds: clusters of sinks +under an H-tree, no mesh, and no on-chip-variation derates in this flow. +At final the core tree is 261 ps deep, most of a 300 ps period. That is +an ordinary tree at a 1,000 ps period and not what a core aimed at +300 ps would get, which is a clock mesh or a multi-source tree that +keeps paths diverging late. It does not touch what this design tests: +the crossing is timed without clock latency and without a hold check, +so the depth of either tree does not enter it. What the tree does move +is the same-clock paths, the synchroniser hops among them, and with them +the 300 ps; XiangShan's bridge was measured through the same trees. + +## Variants + +| FLOW_VARIANT | flits (req/rsp/dat/snp bits) | queue depth | flops | core clock min period at 300 ps, global route | to global route | +|---|---|---|---|---|---| +| base | 125 / 51 / 385 / 88, XiangShan's | 16 | 35,106 | 305.9 ps, fails | 30 min | +| medium | 125 / 51 / 385 / 88 | 4 | 21,846 | 299.5 ps, closes | 20 min | +| small | 32 / 16 / 64 / 24 | 4 | 4,621 | 298.5 ps, closes | 5 min | + +The worst core-clock path is the same on every rung, the async queue +sink's read; only base, with XiangShan's sixteen entries behind the +read mux, reproduces XiangShan's period. The smaller rungs keep the +structure for iterating on a change in minutes. + +## Try this + +```sh +make DESIGN_CONFIG=./designs/asap7/chi_async_bridge/config.mk +make DESIGN_CONFIG=./designs/asap7/chi_async_bridge/config.mk FLOW_VARIANT=small +make DESIGN_CONFIG=./designs/asap7/chi_async_bridge/config.mk gui_grt +``` + +To see the constraints check themselves, change a synchroniser in +`src/chi_async_bridge/sync_shift_reg.sv` and run synthesis. Rename its +`sync` register and it stops with + +``` +constraint.sdc: synchronisers: unexpected cell name sink.asyncQSink_dat_flit.widx_gray.bit_[0].stage[0]$_DFF_PP0_ +``` + +or put a gate between two of its flops and it stops with + +``` +constraint.sdc: synchronisers: sink.asyncQSink_dat_flit.widx_gray.bit_[0].sync[2]$_DFF_PP0_ does not drive sink.asyncQSink_dat_flit.widx_gray.bit_[0].sync[1]$_DFF_PP0_ alone +``` diff --git a/flow/designs/asap7/chi_async_bridge/config.mk b/flow/designs/asap7/chi_async_bridge/config.mk new file mode 100644 index 0000000000..161fc151c3 --- /dev/null +++ b/flow/designs/asap7/chi_async_bridge/config.mk @@ -0,0 +1,30 @@ +# chi_async_bridge: XiangShan's asynchronous CHI bridge between its tile +# and its network-on-chip. README.md says what it is for and where it +# comes from. +export PLATFORM = asap7 +export DESIGN_NAME = chi_async_bridge +export DESIGN_NICKNAME = chi_async_bridge + +export VERILOG_FILES = $(sort $(wildcard $(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/*.sv)) +export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/constraint.sdc + +# Readable, parameterised SystemVerilog, read by slang. +export SYNTH_HDL_FRONTEND = slang + +# All three threshold voltages, as for the core this bridge serves. +export ASAP7_USE_VT = RVT LVT SLVT + +export CORE_UTILIZATION = 40 +export CORE_MARGIN = 2 + +# A ladder, FLOW_VARIANT=small|medium. base, ORFS's default variant, is +# XiangShan's bridge as it is: its flit widths and its queue depth of 16 +# (system/SoC.scala:127), the only rung that reproduces XiangShan's +# period. medium keeps the flit widths at a depth of 4, small also +# narrows the flits; both are for iterating, in minutes. +export VERILOG_TOP_PARAMS = DEPTH 16 +ifeq ($(FLOW_VARIANT),small) +export VERILOG_TOP_PARAMS = REQ_W 32 RSP_W 16 DAT_W 64 SNP_W 24 DEPTH 4 +else ifeq ($(FLOW_VARIANT),medium) +export VERILOG_TOP_PARAMS = DEPTH 4 +endif diff --git a/flow/designs/asap7/chi_async_bridge/constraint.sdc b/flow/designs/asap7/chi_async_bridge/constraint.sdc new file mode 100644 index 0000000000..b44d30b335 --- /dev/null +++ b/flow/designs/asap7/chi_async_bridge/constraint.sdc @@ -0,0 +1,161 @@ +# chi_async_bridge: two clocks with no phase relation, and the bridge +# between them. README.md says what each constraint is for. +set sdc_version 2.0 + +# The core clock: the period at which XiangShan's own bridge, hardened +# alone through this flow, just fails at global route (-1.4 ps, on the +# core half's async queue sink read path), and so does this design +# (README.md, Results). Above it both close; the flow meets every target +# down to here. +set clk_period 300 +# The NoC clock: an unrelated period, about half the core's frequency. +# The two never align, and nothing here depends on the ratio. +set noc_clk_period 1021 + +create_clock -name clk -period $clk_period [get_ports clock] +create_clock -name noc_clk -period $noc_clk_period [get_ports noc_clock] + +# ---- The crossing ---------------------------------------------------- +# The clocks are asynchronous, but the paths between them are still +# timed: each must take less than one period of the clock it starts on, +# measured from its first flop's clock pin, without the clock tree. For +# a Gray-coded pointer that keeps every bit within one write of the +# others; the data, read only after its pointer has been synchronised, +# meets it with room to spare. No hold check between the clocks: there +# is no edge to hold against. +set_clock_groups -asynchronous -allow_paths -group clk -group noc_clk +set_max_delay -ignore_clock_latency $clk_period \ + -from [get_clocks clk] -to [get_clocks noc_clk] +set_max_delay -ignore_clock_latency $noc_clk_period \ + -from [get_clocks noc_clk] -to [get_clocks clk] +set_false_path -hold -from [get_clocks clk] -to [get_clocks noc_clk] +set_false_path -hold -from [get_clocks noc_clk] -to [get_clocks clk] + +# noc_reset is asynchronous; each half releases it through its own +# reset synchroniser (reset_gen.sv), whose flops it sets directly. +set_false_path -from [get_ports noc_reset] + +# ---- The ports ------------------------------------------------------- +# As $PLATFORM_DIR/constraints.sdc budgets a single-clock macro's ports, +# with that file's ratio, but per domain: the tile's ports at the core +# period, the NoC's (noc_*) at the NoC period. That file creates one +# clock, so it is not sourced here. +set tile_in {} +set noc_in {} +foreach p [all_inputs -no_clocks] { + set name [get_full_name $p] + if { $name eq "noc_reset" } { + continue + } elseif { [string match noc_* $name] } { + lappend noc_in $p + } else { + lappend tile_in $p + } +} +set tile_out {} +set noc_out {} +foreach p [all_outputs] { + if { [string match noc_* [get_full_name $p]] } { + lappend noc_out $p + } else { + lappend tile_out $p + } +} +foreach {ins outs period} [list $tile_in $tile_out $clk_period \ + $noc_in $noc_out $noc_clk_period] { + set_max_delay -ignore_clock_latency [expr { $period * 0.8 }] \ + -from $ins -to [all_registers] + set_max_delay -ignore_clock_latency [expr { $period * 0.8 }] \ + -from [all_registers] -to $outs +} + +group_path -name in2reg -from [all_inputs -no_clocks] -to [all_registers] +group_path -name reg2out -from [all_registers] -to [all_outputs] +group_path -name reg2reg -from [all_registers] -to [all_registers] + +# ---- The synchronisers ------------------------------------------------ +# A synchroniser's flops resolve metastability in the time a period +# leaves them, so the step from one to the next is kept short: a +# clock-to-output, one inverter (asap7's flop with asynchronous set and +# reset has only an inverted output) and a setup, about four FO4 at this +# flow's 14.37 ps. Five FO4 is the budget. +set sync_hop_max 72 + +# This is the one constraint that names instances, and a name that +# matches nothing would make OpenSTA warn and drop it (STA-0101, +# STA-0471). So the names are checked first, against the netlist this +# file is read with, which is the synthesised one: the flow stops here +# if synthesis has renamed, merged or restructured a synchroniser. +# +# In that netlist a chain flop is named, as timing analysis spells it, +# .bit_[].sync[]$_DFF_PP_ +# (flattened with '.', yosys's cell type appended; the database escapes +# the brackets, timing analysis does not); sync[SYNC-1] takes the +# asynchronous input, sync[0] is the output. +set sync_stages 3 +set depth 16 +if { [info exists ::env(VERILOG_TOP_PARAMS)] } { + foreach {k v} $::env(VERILOG_TOP_PARAMS) { + if { $k eq "DEPTH" } { set depth $v } + } +} +# 6 flit queues and 6 credit queues, each with a pointer synchroniser in +# both halves, of log2(DEPTH)+1 bits; and 7 handshakes into each half. +set pointer_bits [expr { int(round(log($depth) / log(2))) + 1 }] +set expect_chains [expr { 2 * 12 * $pointer_bits + 2 * 7 }] + +proc sync_check_fail { msg } { + error "constraint.sdc: synchronisers: $msg" +} + +# The one input pin an output pin's net drives, or {} if it drives more. +proc sync_only_load { pin } { + set loads [get_pins -quiet -of_objects [get_nets -of_objects $pin] \ + -filter "direction == input"] + if { [llength $loads] != 1 } { return {} } + return $loads +} + +proc sync_output { cell } { + return [get_pins -of_objects $cell -filter "direction == output"] +} + +set chains [dict create] +foreach cell [get_cells -quiet {*_gray.bit_* *sync_link.bit_*}] { + set name [get_full_name $cell] + if { ![regexp {^(.*)\.sync\[([0-9]+)\]} $name -> chain stage] } { + sync_check_fail "unexpected cell name $name" + } + dict set chains $chain $stage $cell +} +if { [dict size $chains] != $expect_chains } { + sync_check_fail "expected $expect_chains chains, found [dict size $chains]" +} +set sync_hops {} +dict for {chain stages} $chains { + if { [dict size $stages] != $sync_stages } { + sync_check_fail "$chain has [dict size $stages] stages, not $sync_stages" + } + for { set s [expr { $sync_stages - 1 }] } { $s > 0 } { incr s -1 } { + set from [dict get $stages $s] + set to [get_full_name [dict get $stages [expr { $s - 1 }]]] + # The output, at most one single-input cell, then the next flop, + # and nothing else on the way. + set load [sync_only_load [sync_output $from]] + if { $load ne {} && [get_full_name [get_cells -of_objects $load]] ne $to } { + set inv [get_cells -of_objects $load] + if { [llength [get_pins -of_objects $inv -filter "direction == input"]] == 1 } { + set load [sync_only_load [sync_output $inv]] + } else { + set load {} + } + } + if { $load eq {} || [get_full_name [get_cells -of_objects $load]] ne $to } { + sync_check_fail "[get_full_name $from] does not drive $to alone" + } + lappend sync_hops $from [dict get $stages [expr { $s - 1 }]] + } +} +foreach {from to} $sync_hops { + set_max_delay -ignore_clock_latency $sync_hop_max -from $from -to $to +} diff --git a/flow/designs/src/chi_async_bridge/async_queue_sink.sv b/flow/designs/src/chi_async_bridge/async_queue_sink.sv new file mode 100644 index 0000000000..a51636c605 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/async_queue_sink.sv @@ -0,0 +1,89 @@ +// The reading half of an asynchronous queue: rocket-chip's AsyncQueueSink +// (util/AsyncQueue.scala:148-179 at a2df1a4), safe = false, narrow = false. +// +// The source's write pointer arrives through a SYNC-deep synchroniser +// (widx_gray). Once it says an entry is there, the entry is read with a +// mux over all DEPTH entries of the source's memory, straight into +// deq_bits_reg. That mux is the data crossing: it starts at flops on the +// source's clock and ends at a flop on this one. Rocket-chip's comment +// states the contract: "the mux is safe because timing analysis ensures +// ridx has reached the register". constraint.sdc is that timing analysis. +module async_queue_sink #( + parameter int WIDTH = 8, + parameter int DEPTH = 16, + parameter int SYNC = 3, + parameter bit PULSE = 1'b0, + localparam int BITS = $clog2(DEPTH) +) ( + input logic clock, + input logic reset, + output logic deq_valid, + input logic deq_ready, + output logic [ WIDTH-1:0] deq_bits, + input logic [DEPTH*WIDTH-1:0] async_mem, + output logic [ BITS:0] async_ridx, + input logic [ BITS:0] async_widx +); + // AsyncQueueParams requires a power-of-two depth (util/AsyncQueue.scala:19); + // the Gray pointers and the read index assume it. + if (DEPTH < 2 || (DEPTH & (DEPTH - 1)) != 0) begin : depth_check + $error("async_queue_sink: DEPTH must be a power of 2 and at least 2"); + end + + logic fire; + assign fire = deq_valid && deq_ready; + + logic [BITS:0] ridx_bin, ridx_inc, ridx; + assign ridx_inc = ridx_bin + (BITS + 1)'(fire); + assign ridx = ridx_inc ^ (ridx_inc >> 1); + always_ff @(posedge clock or posedge reset) begin + if (reset) ridx_bin <= '0; + else ridx_bin <= ridx_inc; + end + + logic [BITS:0] widx; + sync_shift_reg #( + .WIDTH(BITS + 1), + .SYNC (SYNC) + ) widx_gray ( + .clock(clock), + .reset(reset), + .d (async_widx), + .q (widx) + ); + + logic valid; + assign valid = ridx != widx; + + logic valid_reg; + always_ff @(posedge clock or posedge reset) begin + if (reset) valid_reg <= 1'b0; + else valid_reg <= valid; + end + assign deq_valid = valid_reg; + + logic [BITS:0] ridx_gray; + always_ff @(posedge clock or posedge reset) begin + if (reset) ridx_gray <= '0; + else ridx_gray <= ridx; + end + assign async_ridx = ridx_gray; + + if (PULSE) begin : no_mem + assign deq_bits = '0; + end else begin : mem_ + logic [BITS-1:0] index; + if (BITS == 1) begin : one + assign index = ridx[0] ^ ridx[1]; + end else begin : many + assign index = ridx[BITS-1:0] ^ {ridx[BITS], {(BITS - 1) {1'b0}}}; + end + // ClockCrossingReg (util/SynchronizerReg.scala): not reset, loads + // only when the entry it selects is valid. + logic [WIDTH-1:0] deq_bits_reg; + always_ff @(posedge clock) begin + if (valid) deq_bits_reg <= async_mem[index*WIDTH+:WIDTH]; + end + assign deq_bits = deq_bits_reg; + end +endmodule diff --git a/flow/designs/src/chi_async_bridge/async_queue_source.sv b/flow/designs/src/chi_async_bridge/async_queue_source.sv new file mode 100644 index 0000000000..b55c3b2b3c --- /dev/null +++ b/flow/designs/src/chi_async_bridge/async_queue_source.sv @@ -0,0 +1,99 @@ +// The writing half of an asynchronous queue: rocket-chip's +// AsyncQueueSource (util/AsyncQueue.scala:70-104 at a2df1a4) with +// safe = false and narrow = false, which is how XiangShan's CHI bridge +// configures it (AsyncQueueParams(depth = 16, sync = 3, safe = false), +// system/SoC.scala:127). +// +// What crosses to the reading domain, all of it straight from a flop: +// mem DEPTH entries of WIDTH bits, written in this domain, never reset; +// widx the write pointer in Gray code (widx_gray). +// What comes back: ridx, the reader's Gray pointer, through a SYNC-deep +// synchroniser (ridx_gray). +// +// PULSE = 1 is rocket-chip's AsyncQueueSource(UInt(0.W)): no data, the +// queue only counts events. The CHI bridge returns link credits this way. +module async_queue_source #( + parameter int WIDTH = 8, + parameter int DEPTH = 16, + parameter int SYNC = 3, + parameter bit PULSE = 1'b0, + localparam int BITS = $clog2(DEPTH) +) ( + input logic clock, + input logic reset, + input logic enq_valid, + output logic enq_ready, + input logic [ WIDTH-1:0] enq_bits, + output logic [DEPTH*WIDTH-1:0] async_mem, + input logic [ BITS:0] async_ridx, + output logic [ BITS:0] async_widx +); + // AsyncQueueParams requires a power-of-two depth (util/AsyncQueue.scala:19); + // the Gray pointers and the full test assume it. + if (DEPTH < 2 || (DEPTH & (DEPTH - 1)) != 0) begin : depth_check + $error("async_queue_source: DEPTH must be a power of 2 and at least 2"); + end + + logic fire; + assign fire = enq_valid && enq_ready; + + // GrayCounter (AsyncQueue.scala:49-56): a binary register, and the Gray + // code of the value it is about to take. + logic [BITS:0] widx_bin, widx_inc, widx; + assign widx_inc = widx_bin + (BITS + 1)'(fire); + assign widx = widx_inc ^ (widx_inc >> 1); + always_ff @(posedge clock or posedge reset) begin + if (reset) widx_bin <= '0; + else widx_bin <= widx_inc; + end + + logic [BITS:0] ridx; + sync_shift_reg #( + .WIDTH(BITS + 1), + .SYNC (SYNC) + ) ridx_gray ( + .clock(clock), + .reset(reset), + .d (async_ridx), + .q (ridx) + ); + + // Full when the write pointer is one lap ahead of the read pointer: in + // Gray code, the top two bits inverted. + logic ready; + assign ready = widx != (ridx ^ (BITS + 1)'(DEPTH | (DEPTH >> 1))); + + logic ready_reg; + always_ff @(posedge clock or posedge reset) begin + if (reset) ready_reg <= 1'b0; + else ready_reg <= ready; + end + assign enq_ready = ready_reg; + + logic [BITS:0] widx_gray; + always_ff @(posedge clock or posedge reset) begin + if (reset) widx_gray <= '0; + else widx_gray <= widx; + end + assign async_widx = widx_gray; + + if (PULSE) begin : no_mem + assign async_mem = '0; + end else begin : mem_ + // The entry being written, from the registered Gray pointer. + logic [BITS-1:0] index; + if (BITS == 1) begin : one + assign index = widx_gray[0] ^ widx_gray[1]; + end else begin : many + assign index = widx_gray[BITS-1:0] ^ {widx_gray[BITS], {(BITS - 1) {1'b0}}}; + end + // Reg(Vec(depth, gen)): one register per entry, as firtool emits it. + for (genvar i = 0; i < DEPTH; i++) begin : mem + logic [WIDTH-1:0] entry; + always_ff @(posedge clock) begin + if (fire && index == BITS'(i)) entry <= enq_bits; + end + assign async_mem[i*WIDTH+:WIDTH] = entry; + end + end +endmodule diff --git a/flow/designs/src/chi_async_bridge/chi_async_bridge.sv b/flow/designs/src/chi_async_bridge/chi_async_bridge.sv new file mode 100644 index 0000000000..f694b0b2b0 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/chi_async_bridge.sv @@ -0,0 +1,180 @@ +// chi_async_bridge: the asynchronous CHI bridge between XiangShan's tile +// and its network-on-chip, both halves in one block. README.md (beside +// config.mk) tells the story; this file only wires the halves together. +// +// clock the core clock: the tile half, chi_async_bridge_source.sv, +// which XiangShan puts in XSTileWrap beside XSTile. +// noc_clock the NoC clock: the NoC half, chi_async_bridge_sink.sv, +// which XiangShan puts in XSNoCTop. +// +// Every wire between the halves, the a_* signals below, crosses from one +// clock domain to the other. In XiangShan they are the pins between two +// separately built blocks; here they are nets inside one, so timing +// analysis sees both ends of every crossing. +// +// The tile side's ports keep the halves' own names; the NoC side's are +// prefixed noc_. Both halves are reset by noc_reset, each through its own +// reset synchroniser (XSTileWrap.scala:112, XSNoCTop.scala:84). +module chi_async_bridge #( + parameter int REQ_W = 125, + parameter int RSP_W = 51, + parameter int DAT_W = 385, + parameter int SNP_W = 88, + parameter int DEPTH = 16, + parameter int SYNC = 3, + localparam int B = $clog2(DEPTH) +) ( + input logic clock, + input logic noc_clock, + input logic noc_reset, + input logic tx_req_flitv, + input logic [REQ_W-1:0] tx_req_flit, + output logic tx_req_lcrdv, + input logic tx_rsp_flitv, + input logic [RSP_W-1:0] tx_rsp_flit, + output logic tx_rsp_lcrdv, + input logic tx_dat_flitv, + input logic [DAT_W-1:0] tx_dat_flit, + output logic tx_dat_lcrdv, + output logic rx_rsp_flitv, + output logic [RSP_W-1:0] rx_rsp_flit, + input logic rx_rsp_lcrdv, + output logic rx_dat_flitv, + output logic [DAT_W-1:0] rx_dat_flit, + input logic rx_dat_lcrdv, + output logic rx_snp_flitv, + output logic [SNP_W-1:0] rx_snp_flit, + input logic rx_snp_lcrdv, + input logic [2:0] tx_flitpend, + output logic [2:0] rx_flitpend, + input logic tx_linkactivereq, + output logic tx_linkactiveack, + output logic rx_linkactivereq, + input logic rx_linkactiveack, + input logic txsactive, + output logic rxsactive, + input logic syscoreq, + output logic syscoack, + output logic noc_tx_req_flitv, + output logic [REQ_W-1:0] noc_tx_req_flit, + input logic noc_tx_req_ready, + input logic noc_tx_req_lcrdv, + output logic noc_tx_rsp_flitv, + output logic [RSP_W-1:0] noc_tx_rsp_flit, + input logic noc_tx_rsp_ready, + input logic noc_tx_rsp_lcrdv, + output logic noc_tx_dat_flitv, + output logic [DAT_W-1:0] noc_tx_dat_flit, + input logic noc_tx_dat_ready, + input logic noc_tx_dat_lcrdv, + input logic noc_rx_rsp_flitv, + input logic [RSP_W-1:0] noc_rx_rsp_flit, + output logic noc_rx_rsp_lcrdv, + input logic noc_rx_dat_flitv, + input logic [DAT_W-1:0] noc_rx_dat_flit, + output logic noc_rx_dat_lcrdv, + input logic noc_rx_snp_flitv, + input logic [SNP_W-1:0] noc_rx_snp_flit, + output logic noc_rx_snp_lcrdv, + output logic [2:0] noc_tx_flitpend, + input logic [2:0] noc_rx_flitpend, + output logic noc_tx_linkactivereq, + input logic noc_tx_linkactiveack, + input logic noc_rx_linkactivereq, + output logic noc_rx_linkactiveack, + output logic noc_txsactive, + input logic noc_rxsactive, + output logic noc_syscoreq, + input logic noc_syscoack +); + logic tile_reset, noc_side_reset; + reset_gen tile_reset_sync ( + .clock(clock), .reset(noc_reset), .o_reset(tile_reset)); + reset_gen noc_reset_sync ( + .clock(noc_clock), .reset(noc_reset), .o_reset(noc_side_reset)); + + // The crossing. + logic [DEPTH*REQ_W-1:0] a_tx_req_mem; + logic [B:0] a_tx_req_widx; + logic [B:0] a_tx_req_ridx; + logic [DEPTH*RSP_W-1:0] a_tx_rsp_mem; + logic [B:0] a_tx_rsp_widx; + logic [B:0] a_tx_rsp_ridx; + logic [DEPTH*DAT_W-1:0] a_tx_dat_mem; + logic [B:0] a_tx_dat_widx; + logic [B:0] a_tx_dat_ridx; + logic [DEPTH*RSP_W-1:0] a_rx_rsp_mem; + logic [B:0] a_rx_rsp_widx; + logic [B:0] a_rx_rsp_ridx; + logic [DEPTH*DAT_W-1:0] a_rx_dat_mem; + logic [B:0] a_rx_dat_widx; + logic [B:0] a_rx_dat_ridx; + logic [DEPTH*SNP_W-1:0] a_rx_snp_mem; + logic [B:0] a_rx_snp_widx; + logic [B:0] a_rx_snp_ridx; + logic [2:0][B:0] a_tx_lcrdv_widx; + logic [2:0][B:0] a_tx_lcrdv_ridx; + logic [2:0][B:0] a_rx_lcrdv_widx; + logic [2:0][B:0] a_rx_lcrdv_ridx; + logic [2:0] a_tx_flitpend; + logic [2:0] a_rx_flitpend; + logic a_tx_linkactivereq; + logic a_tx_linkactiveack; + logic a_rx_linkactivereq; + logic a_rx_linkactiveack; + logic a_txsactive; + logic a_rxsactive; + logic a_syscoreq; + logic a_syscoack; + + chi_async_bridge_source #( + .REQ_W(REQ_W), .RSP_W(RSP_W), .DAT_W(DAT_W), .SNP_W(SNP_W), + .DEPTH(DEPTH), .SYNC(SYNC) + ) source ( + .clock(clock), + .reset(tile_reset), + .reset_finish(), + .* + ); + + chi_async_bridge_sink #( + .REQ_W(REQ_W), .RSP_W(RSP_W), .DAT_W(DAT_W), .SNP_W(SNP_W), + .DEPTH(DEPTH), .SYNC(SYNC) + ) sink ( + .clock(noc_clock), + .reset(noc_side_reset), + .tx_req_flitv(noc_tx_req_flitv), + .tx_req_flit(noc_tx_req_flit), + .tx_req_ready(noc_tx_req_ready), + .tx_req_lcrdv(noc_tx_req_lcrdv), + .tx_rsp_flitv(noc_tx_rsp_flitv), + .tx_rsp_flit(noc_tx_rsp_flit), + .tx_rsp_ready(noc_tx_rsp_ready), + .tx_rsp_lcrdv(noc_tx_rsp_lcrdv), + .tx_dat_flitv(noc_tx_dat_flitv), + .tx_dat_flit(noc_tx_dat_flit), + .tx_dat_ready(noc_tx_dat_ready), + .tx_dat_lcrdv(noc_tx_dat_lcrdv), + .rx_rsp_flitv(noc_rx_rsp_flitv), + .rx_rsp_flit(noc_rx_rsp_flit), + .rx_rsp_lcrdv(noc_rx_rsp_lcrdv), + .rx_dat_flitv(noc_rx_dat_flitv), + .rx_dat_flit(noc_rx_dat_flit), + .rx_dat_lcrdv(noc_rx_dat_lcrdv), + .rx_snp_flitv(noc_rx_snp_flitv), + .rx_snp_flit(noc_rx_snp_flit), + .rx_snp_lcrdv(noc_rx_snp_lcrdv), + .tx_flitpend(noc_tx_flitpend), + .rx_flitpend(noc_rx_flitpend), + .tx_linkactivereq(noc_tx_linkactivereq), + .tx_linkactiveack(noc_tx_linkactiveack), + .rx_linkactivereq(noc_rx_linkactivereq), + .rx_linkactiveack(noc_rx_linkactiveack), + .txsactive(noc_txsactive), + .rxsactive(noc_rxsactive), + .syscoreq(noc_syscoreq), + .syscoack(noc_syscoack), + .reset_finish(), + .* + ); +endmodule diff --git a/flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv b/flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv new file mode 100644 index 0000000000..d8d1190c57 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv @@ -0,0 +1,182 @@ +// The NoC's half of the bridge, on the NoC clock: XSCache's +// CHIAsyncBridgeSink (xscache/chi/AsyncBridge.scala:227-341 at 300515b), +// which XSNoCTop instantiates (XSNoCTop.scala:275-276). The mirror image +// of chi_async_bridge_source.sv: tx flits arrive through async queue +// sinks, rx rsp and dat leave through shadow buffers and async queue +// sources, rx snp through an async queue source alone. +// +// Not modelled: the NoC link layer at AsyncBridge.scala:297-339 (the +// link-state machines and the L-credit managers that return rx credits +// early and hold tx flits back). It is logic of the NoC's own clock +// domain on the far side of the crossing; here its ready and credits are +// ports, and rx credits cross back the way snp's always do. +module chi_async_bridge_sink #( + parameter int REQ_W = 125, + parameter int RSP_W = 51, + parameter int DAT_W = 385, + parameter int SNP_W = 88, + parameter int DEPTH = 16, + parameter int SYNC = 3, + localparam int B = $clog2(DEPTH) +) ( + input logic clock, + input logic reset, + + // The NoC's CHI port. + output logic tx_req_flitv, + output logic [REQ_W-1:0] tx_req_flit, + input logic tx_req_ready, + input logic tx_req_lcrdv, + output logic tx_rsp_flitv, + output logic [RSP_W-1:0] tx_rsp_flit, + input logic tx_rsp_ready, + input logic tx_rsp_lcrdv, + output logic tx_dat_flitv, + output logic [DAT_W-1:0] tx_dat_flit, + input logic tx_dat_ready, + input logic tx_dat_lcrdv, + input logic rx_rsp_flitv, + input logic [RSP_W-1:0] rx_rsp_flit, + output logic rx_rsp_lcrdv, + input logic rx_dat_flitv, + input logic [DAT_W-1:0] rx_dat_flit, + output logic rx_dat_lcrdv, + input logic rx_snp_flitv, + input logic [SNP_W-1:0] rx_snp_flit, + output logic rx_snp_lcrdv, + output logic [ 2:0] tx_flitpend, // req, rsp, dat + input logic [ 2:0] rx_flitpend, // rsp, dat, snp + output logic tx_linkactivereq, + input logic tx_linkactiveack, + input logic rx_linkactivereq, + output logic rx_linkactiveack, + output logic txsactive, + input logic rxsactive, + output logic syscoreq, + input logic syscoack, + output logic reset_finish, + + // The asynchronous side, to the tile half. + input logic [DEPTH*REQ_W-1:0] a_tx_req_mem, + input logic [ B:0] a_tx_req_widx, + output logic [ B:0] a_tx_req_ridx, + input logic [DEPTH*RSP_W-1:0] a_tx_rsp_mem, + input logic [ B:0] a_tx_rsp_widx, + output logic [ B:0] a_tx_rsp_ridx, + input logic [DEPTH*DAT_W-1:0] a_tx_dat_mem, + input logic [ B:0] a_tx_dat_widx, + output logic [ B:0] a_tx_dat_ridx, + output logic [DEPTH*RSP_W-1:0] a_rx_rsp_mem, + output logic [ B:0] a_rx_rsp_widx, + input logic [ B:0] a_rx_rsp_ridx, + output logic [DEPTH*DAT_W-1:0] a_rx_dat_mem, + output logic [ B:0] a_rx_dat_widx, + input logic [ B:0] a_rx_dat_ridx, + output logic [DEPTH*SNP_W-1:0] a_rx_snp_mem, + output logic [ B:0] a_rx_snp_widx, + input logic [ B:0] a_rx_snp_ridx, + output logic [ 2:0][B:0] a_tx_lcrdv_widx, + input logic [ 2:0][B:0] a_tx_lcrdv_ridx, + input logic [ 2:0][B:0] a_rx_lcrdv_widx, + output logic [ 2:0][B:0] a_rx_lcrdv_ridx, + input logic [ 2:0] a_tx_flitpend, + output logic [ 2:0] a_rx_flitpend, + input logic a_tx_linkactivereq, + output logic a_tx_linkactiveack, + output logic a_rx_linkactivereq, + input logic a_rx_linkactiveack, + input logic a_txsactive, + output logic a_rxsactive, + input logic a_syscoreq, + output logic a_syscoack +); + // ---- tx: async queue sink, held back by the NoC's ready ------------- + `define CHI_TX(ch, W) \ + logic ch``_valid; \ + async_queue_sink #(.WIDTH(W), .DEPTH(DEPTH), .SYNC(SYNC)) \ + asyncQSink_``ch``_flit ( \ + .clock(clock), .reset(reset), \ + .deq_valid(ch``_valid), .deq_ready(tx_``ch``_ready), \ + .deq_bits(tx_``ch``_flit), .async_mem(a_tx_``ch``_mem), \ + .async_ridx(a_tx_``ch``_ridx), .async_widx(a_tx_``ch``_widx)); \ + assign tx_``ch``_flitv = ch``_valid && tx_``ch``_ready; + `CHI_TX(req, REQ_W) + `CHI_TX(rsp, RSP_W) + `CHI_TX(dat, DAT_W) + `undef CHI_TX + + // ---- rx: shadow buffer and async queue source (snp: no buffer) ------ + `define CHI_RX_BUF(ch, W) \ + logic ch``_sb_valid, ch``_sb_ready; \ + logic [W-1:0] ch``_sb_bits; \ + shadow_buffer #(.WIDTH(W)) shadowBuffer_``ch``_flit ( \ + .clock(clock), .reset(reset), \ + .enq_valid(rx_``ch``_flitv), .enq_ready(), .enq_bits(rx_``ch``_flit), \ + .deq_valid(ch``_sb_valid), .deq_ready(ch``_sb_ready), \ + .deq_bits(ch``_sb_bits)); \ + async_queue_source #(.WIDTH(W), .DEPTH(DEPTH), .SYNC(SYNC)) \ + asyncQSource_``ch``_flit ( \ + .clock(clock), .reset(reset), \ + .enq_valid(ch``_sb_valid), .enq_ready(ch``_sb_ready), \ + .enq_bits(ch``_sb_bits), .async_mem(a_rx_``ch``_mem), \ + .async_ridx(a_rx_``ch``_ridx), .async_widx(a_rx_``ch``_widx)); + `CHI_RX_BUF(rsp, RSP_W) + `CHI_RX_BUF(dat, DAT_W) + `undef CHI_RX_BUF + async_queue_source #(.WIDTH(SNP_W), .DEPTH(DEPTH), .SYNC(SYNC)) + asyncQSource_snp_flit ( + .clock(clock), .reset(reset), + .enq_valid(rx_snp_flitv), .enq_ready(), .enq_bits(rx_snp_flit), + .async_mem(a_rx_snp_mem), .async_ridx(a_rx_snp_ridx), + .async_widx(a_rx_snp_widx)); + + // ---- link credits, as pulse queues ---------------------------------- + logic [2:0] tx_lcrdv, rx_lcrdv; + assign tx_lcrdv = {tx_dat_lcrdv, tx_rsp_lcrdv, tx_req_lcrdv}; + for (genvar c = 0; c < 3; c++) begin : lcrdv + async_queue_source #(.WIDTH(1), .DEPTH(DEPTH), .SYNC(SYNC), .PULSE(1'b1)) + asyncQBitSource_tx_lcrdv ( + .clock(clock), .reset(reset), + .enq_valid(tx_lcrdv[c]), .enq_ready(), .enq_bits(1'b0), + .async_mem(), .async_ridx(a_tx_lcrdv_ridx[c]), + .async_widx(a_tx_lcrdv_widx[c])); + async_queue_sink #(.WIDTH(1), .DEPTH(DEPTH), .SYNC(SYNC), .PULSE(1'b1)) + asyncQBitSink_rx_lcrdv ( + .clock(clock), .reset(reset), + .deq_valid(rx_lcrdv[c]), .deq_ready(1'b1), .deq_bits(), + .async_mem('0), .async_ridx(a_rx_lcrdv_ridx[c]), + .async_widx(a_rx_lcrdv_widx[c])); + end + assign {rx_snp_lcrdv, rx_dat_lcrdv, rx_rsp_lcrdv} = rx_lcrdv; + + // ---- link handshakes ------------------------------------------------ + // Out: straight through (AsyncBridge.scala:258-264). + assign a_rxsactive = rxsactive; + assign a_tx_linkactiveack = tx_linkactiveack; + assign a_rx_linkactivereq = rx_linkactivereq; + assign a_syscoack = syscoack; + assign a_rx_flitpend = rx_flitpend; + + // In: synchronised (AsyncBridge.scala:277-284). + logic [6:0] in_sync; + sync_shift_reg #(.WIDTH(7), .SYNC(SYNC)) sync_link ( + .clock(clock), .reset(reset), + .d({a_tx_flitpend, a_syscoreq, a_tx_linkactivereq, a_rx_linkactiveack, + a_txsactive}), + .q(in_sync)); + assign txsactive = in_sync[0]; + assign rx_linkactiveack = in_sync[1] && reset_finish; + assign tx_linkactivereq = in_sync[2] && reset_finish; + assign syscoreq = in_sync[3]; + assign tx_flitpend = in_sync[6:4]; + + // resetFinish: 100 cycles after reset (AsyncBridge.scala:286-292). + localparam int RESET_FINISH_MAX = 100; + logic [7:0] reset_finish_counter; + always_ff @(posedge clock or posedge reset) begin + if (reset) reset_finish_counter <= '0; + else if (reset_finish_counter < 8'(RESET_FINISH_MAX)) + reset_finish_counter <= reset_finish_counter + 1'b1; + end + assign reset_finish = reset_finish_counter >= 8'(RESET_FINISH_MAX); +endmodule diff --git a/flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv b/flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv new file mode 100644 index 0000000000..cb6f73153a --- /dev/null +++ b/flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv @@ -0,0 +1,176 @@ +// The tile's half of the bridge, on the core clock: XSCache's +// CHIAsyncBridgeSource (xscache/chi/AsyncBridge.scala:157-225 at +// 300515b), which XSTileWrap instantiates beside XSTile +// (XSTileWrap.scala:190-196). +// +// tx req, rsp, dat: flits from the tile's L2 enter a shadow buffer and +// an async queue source; the NoC half returns a link credit for +// each through a pulse queue. +// rx rsp, dat, snp: flits from the NoC leave an async queue sink; the +// tile's link credits go back through pulse queues. +// link handshakes from the NoC half cross through SYNC-deep +// synchronisers; those going out pass straight through. +module chi_async_bridge_source #( + parameter int REQ_W = 125, + parameter int RSP_W = 51, + parameter int DAT_W = 385, + parameter int SNP_W = 88, + parameter int DEPTH = 16, + parameter int SYNC = 3, + localparam int B = $clog2(DEPTH) +) ( + input logic clock, + input logic reset, + + // The tile's CHI port (CoupledL2's link layer, registered outside). + input logic tx_req_flitv, + input logic [REQ_W-1:0] tx_req_flit, + output logic tx_req_lcrdv, + input logic tx_rsp_flitv, + input logic [RSP_W-1:0] tx_rsp_flit, + output logic tx_rsp_lcrdv, + input logic tx_dat_flitv, + input logic [DAT_W-1:0] tx_dat_flit, + output logic tx_dat_lcrdv, + output logic rx_rsp_flitv, + output logic [RSP_W-1:0] rx_rsp_flit, + input logic rx_rsp_lcrdv, + output logic rx_dat_flitv, + output logic [DAT_W-1:0] rx_dat_flit, + input logic rx_dat_lcrdv, + output logic rx_snp_flitv, + output logic [SNP_W-1:0] rx_snp_flit, + input logic rx_snp_lcrdv, + input logic [ 2:0] tx_flitpend, // req, rsp, dat + output logic [ 2:0] rx_flitpend, // rsp, dat, snp + input logic tx_linkactivereq, + output logic tx_linkactiveack, + output logic rx_linkactivereq, + input logic rx_linkactiveack, + input logic txsactive, + output logic rxsactive, + input logic syscoreq, + output logic syscoack, + output logic reset_finish, + + // The asynchronous side, to the NoC half. + output logic [DEPTH*REQ_W-1:0] a_tx_req_mem, + output logic [ B:0] a_tx_req_widx, + input logic [ B:0] a_tx_req_ridx, + output logic [DEPTH*RSP_W-1:0] a_tx_rsp_mem, + output logic [ B:0] a_tx_rsp_widx, + input logic [ B:0] a_tx_rsp_ridx, + output logic [DEPTH*DAT_W-1:0] a_tx_dat_mem, + output logic [ B:0] a_tx_dat_widx, + input logic [ B:0] a_tx_dat_ridx, + input logic [DEPTH*RSP_W-1:0] a_rx_rsp_mem, + input logic [ B:0] a_rx_rsp_widx, + output logic [ B:0] a_rx_rsp_ridx, + input logic [DEPTH*DAT_W-1:0] a_rx_dat_mem, + input logic [ B:0] a_rx_dat_widx, + output logic [ B:0] a_rx_dat_ridx, + input logic [DEPTH*SNP_W-1:0] a_rx_snp_mem, + input logic [ B:0] a_rx_snp_widx, + output logic [ B:0] a_rx_snp_ridx, + // Link credits: tx credits arrive, rx credits leave. + input logic [ 2:0][B:0] a_tx_lcrdv_widx, + output logic [ 2:0][B:0] a_tx_lcrdv_ridx, + output logic [ 2:0][B:0] a_rx_lcrdv_widx, + input logic [ 2:0][B:0] a_rx_lcrdv_ridx, + output logic [ 2:0] a_tx_flitpend, + input logic [ 2:0] a_rx_flitpend, + output logic a_tx_linkactivereq, + input logic a_tx_linkactiveack, + input logic a_rx_linkactivereq, + output logic a_rx_linkactiveack, + output logic a_txsactive, + input logic a_rxsactive, + output logic a_syscoreq, + input logic a_syscoack +); + // ---- tx: shadow buffer, then async queue source --------------------- + `define CHI_TX(ch, W) \ + logic ch``_sb_valid, ch``_sb_ready; \ + logic [W-1:0] ch``_sb_bits; \ + shadow_buffer #(.WIDTH(W)) shadowBuffer_``ch``_flit ( \ + .clock(clock), .reset(reset), \ + .enq_valid(tx_``ch``_flitv), .enq_ready(), .enq_bits(tx_``ch``_flit), \ + .deq_valid(ch``_sb_valid), .deq_ready(ch``_sb_ready), \ + .deq_bits(ch``_sb_bits)); \ + async_queue_source #(.WIDTH(W), .DEPTH(DEPTH), .SYNC(SYNC)) \ + asyncQSource_``ch``_flit ( \ + .clock(clock), .reset(reset), \ + .enq_valid(ch``_sb_valid), .enq_ready(ch``_sb_ready), \ + .enq_bits(ch``_sb_bits), .async_mem(a_tx_``ch``_mem), \ + .async_ridx(a_tx_``ch``_ridx), .async_widx(a_tx_``ch``_widx)); + `CHI_TX(req, REQ_W) + `CHI_TX(rsp, RSP_W) + `CHI_TX(dat, DAT_W) + `undef CHI_TX + + // ---- rx: async queue sink, always ready ----------------------------- + `define CHI_RX(ch, W) \ + logic ch``_valid; \ + async_queue_sink #(.WIDTH(W), .DEPTH(DEPTH), .SYNC(SYNC)) \ + asyncQSink_``ch``_flit ( \ + .clock(clock), .reset(reset), \ + .deq_valid(ch``_valid), .deq_ready(1'b1), .deq_bits(rx_``ch``_flit), \ + .async_mem(a_rx_``ch``_mem), .async_ridx(a_rx_``ch``_ridx), \ + .async_widx(a_rx_``ch``_widx)); \ + assign rx_``ch``_flitv = ch``_valid; + `CHI_RX(rsp, RSP_W) + `CHI_RX(dat, DAT_W) + `CHI_RX(snp, SNP_W) + `undef CHI_RX + + // ---- link credits, as pulse queues ---------------------------------- + logic [2:0] tx_lcrdv, rx_lcrdv; + assign rx_lcrdv = {rx_snp_lcrdv, rx_dat_lcrdv, rx_rsp_lcrdv}; + for (genvar c = 0; c < 3; c++) begin : lcrdv + async_queue_sink #(.WIDTH(1), .DEPTH(DEPTH), .SYNC(SYNC), .PULSE(1'b1)) + asyncQBitSink_tx_lcrdv ( + .clock(clock), .reset(reset), + .deq_valid(tx_lcrdv[c]), .deq_ready(1'b1), .deq_bits(), + .async_mem('0), .async_ridx(a_tx_lcrdv_ridx[c]), + .async_widx(a_tx_lcrdv_widx[c])); + async_queue_source #(.WIDTH(1), .DEPTH(DEPTH), .SYNC(SYNC), .PULSE(1'b1)) + asyncQBitSource_rx_lcrdv ( + .clock(clock), .reset(reset), + .enq_valid(rx_lcrdv[c]), .enq_ready(), .enq_bits(1'b0), + .async_mem(), .async_ridx(a_rx_lcrdv_ridx[c]), + .async_widx(a_rx_lcrdv_widx[c])); + end + assign {tx_dat_lcrdv, tx_rsp_lcrdv, tx_req_lcrdv} = tx_lcrdv; + + // ---- link handshakes ------------------------------------------------ + // Out: straight through (AsyncBridge.scala:187-193). + assign a_txsactive = txsactive; + assign a_rx_linkactiveack = rx_linkactiveack; + assign a_tx_linkactivereq = tx_linkactivereq; + assign a_syscoreq = syscoreq; + assign a_tx_flitpend = tx_flitpend; + + // In: synchronised (AsyncBridge.scala:206-213). The NoC may only bring + // the receive link up once this half has been out of reset a while. + logic [6:0] in_sync; + sync_shift_reg #(.WIDTH(7), .SYNC(SYNC)) sync_link ( + .clock(clock), .reset(reset), + .d({a_rx_flitpend, a_syscoack, a_rx_linkactivereq, a_tx_linkactiveack, + a_rxsactive}), + .q(in_sync)); + assign rxsactive = in_sync[0]; + assign tx_linkactiveack = in_sync[1]; + assign rx_linkactivereq = in_sync[2] && reset_finish; + assign syscoack = in_sync[3]; + assign rx_flitpend = in_sync[6:4]; + + // resetFinish: 100 cycles after reset (AsyncBridge.scala:215-221). + localparam int RESET_FINISH_MAX = 100; + logic [7:0] reset_finish_counter; + always_ff @(posedge clock or posedge reset) begin + if (reset) reset_finish_counter <= '0; + else if (reset_finish_counter < 8'(RESET_FINISH_MAX)) + reset_finish_counter <= reset_finish_counter + 1'b1; + end + assign reset_finish = reset_finish_counter >= 8'(RESET_FINISH_MAX); +endmodule diff --git a/flow/designs/src/chi_async_bridge/reset_gen.sv b/flow/designs/src/chi_async_bridge/reset_gen.sv new file mode 100644 index 0000000000..3f661bb54b --- /dev/null +++ b/flow/designs/src/chi_async_bridge/reset_gen.sv @@ -0,0 +1,27 @@ +// A reset synchroniser: asserts asynchronously, releases SYNC clocks +// later on this domain's clock. XiangShan's ResetGen +// (utility/ResetGen.scala at eb8e12b), without its DFT muxes. +// +// XSTileWrap gives the bridge's tile half a ResetGen of noc_reset on the +// core clock (XSTileWrap.scala:112) and XSNoCTop gives the NoC half one +// on the NoC clock (XSNoCTop.scala:84), so each half leaves reset on its +// own clock. +module reset_gen #( + parameter int SYNC = 3 +) ( + input logic clock, + input logic reset, + output logic o_reset +); + // A reset synchroniser has at least two flops. + if (SYNC < 2) begin : sync_check + $error("reset_gen: SYNC must be at least 2"); + end + + logic [SYNC-1:0] pipe_reset; + always_ff @(posedge clock or posedge reset) begin + if (reset) pipe_reset <= {SYNC{1'b1}}; + else pipe_reset <= {pipe_reset[SYNC-2:0], 1'b0}; + end + assign o_reset = pipe_reset[SYNC-1]; +endmodule diff --git a/flow/designs/src/chi_async_bridge/shadow_buffer.sv b/flow/designs/src/chi_async_bridge/shadow_buffer.sv new file mode 100644 index 0000000000..39b75abca2 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/shadow_buffer.sv @@ -0,0 +1,63 @@ +// The bridge's shadow buffer: a Chisel Queue(entries = 16, flow = true, +// pipe = false) in front of each outgoing CHI flit channel's async queue +// (ToAsyncBundleWithBuf, xscache/chi/AsyncBridge.scala:67-94 at XSCache +// 300515b). It accepts every flit the link layer sends -- CHI's link +// credits guarantee room -- and, being a flow queue, passes a flit +// through in the same cycle when it is empty. +module shadow_buffer #( + parameter int WIDTH = 8, + parameter int ENTRIES = 16, + localparam int PW = $clog2(ENTRIES) +) ( + input logic clock, + input logic reset, + input logic enq_valid, + output logic enq_ready, + input logic [WIDTH-1:0] enq_bits, + output logic deq_valid, + input logic deq_ready, + output logic [WIDTH-1:0] deq_bits +); + // The pointers wrap by overflowing PW bits, which is only right for a + // power-of-two depth; Chisel's Queue wraps explicitly instead. + if (ENTRIES < 2 || (ENTRIES & (ENTRIES - 1)) != 0) begin : entries_check + $error("shadow_buffer: ENTRIES must be a power of 2 and at least 2"); + end + + // Chisel's Queue keeps its entries in a Mem with a combinational read, + // which firtool emits as one register per entry. + logic [ENTRIES-1:0][WIDTH-1:0] ram; + logic [PW-1:0] enq_ptr, deq_ptr; + logic maybe_full; + + logic ptr_match, empty, full; + assign ptr_match = enq_ptr == deq_ptr; + assign empty = ptr_match && !maybe_full; + assign full = ptr_match && maybe_full; + + assign enq_ready = !full; + assign deq_valid = !empty || enq_valid; + assign deq_bits = empty ? enq_bits : ram[deq_ptr]; + + // In flow, a flit taken while the queue is empty never enters it. + logic do_enq, do_deq; + assign do_enq = enq_valid && enq_ready && !(empty && deq_ready); + assign do_deq = deq_valid && deq_ready && !empty; + + for (genvar i = 0; i < ENTRIES; i++) begin : entry + always_ff @(posedge clock) begin + if (do_enq && enq_ptr == PW'(i)) ram[i] <= enq_bits; + end + end + always_ff @(posedge clock or posedge reset) begin + if (reset) begin + enq_ptr <= '0; + deq_ptr <= '0; + maybe_full <= 1'b0; + end else begin + if (do_enq) enq_ptr <= enq_ptr + 1'b1; + if (do_deq) deq_ptr <= deq_ptr + 1'b1; + if (do_enq != do_deq) maybe_full <= do_enq; + end + end +endmodule diff --git a/flow/designs/src/chi_async_bridge/sync_shift_reg.sv b/flow/designs/src/chi_async_bridge/sync_shift_reg.sv new file mode 100644 index 0000000000..84011f3761 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/sync_shift_reg.sv @@ -0,0 +1,34 @@ +// A synchroniser: WIDTH independent chains of SYNC flops, each bit +// clocked into the destination domain. Rocket-chip's +// AsyncResetSynchronizerShiftReg (util/SynchronizerReg.scala at a2df1a4, +// the commit XiangShan pins), which wraps its chains in their own module +// "to allow for backend flows to replace or constrain them properly when +// used for CDC synchronization, rather than buffering". constraint.sdc +// does exactly that, by these names. +// +// The chain is rocket-chip's: sync[SYNC-1] takes the asynchronous input, +// sync[0] is the output, every flop is asynchronously reset to INIT. +module sync_shift_reg #( + parameter int WIDTH = 1, + parameter int SYNC = 3, + parameter bit INIT = 1'b0 +) ( + input logic clock, + input logic reset, + input logic [WIDTH-1:0] d, + output logic [WIDTH-1:0] q +); + // A synchroniser has at least two flops (util/SynchronizerReg.scala:82). + if (SYNC < 2) begin : sync_check + $error("sync_shift_reg: SYNC must be at least 2"); + end + + for (genvar i = 0; i < WIDTH; i++) begin : bit_ + logic [SYNC-1:0] sync; + always_ff @(posedge clock or posedge reset) begin + if (reset) sync <= {SYNC{INIT}}; + else sync <= {d[i], sync[SYNC-1:1]}; + end + assign q[i] = sync[0]; + end +endmodule From d8069b1ba0881a6257a1d84ee97ff2e4a240a562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 07:25:01 +0200 Subject: [PATCH 02/10] asap7/chi_async_bridge: say the port budgets are this file's, not the platform's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment and README said the ports are budgeted with $PLATFORM_DIR/constraints.sdc's ratio. That file has no ratio: it gives a single-clock macro a fixed 80 ps per port path. The budgets here are 80 % of each domain's period, a choice of this file; say so. The constraints themselves are unchanged, so the README's results stand. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/README.md | 6 +++--- flow/designs/asap7/chi_async_bridge/constraint.sdc | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/flow/designs/asap7/chi_async_bridge/README.md b/flow/designs/asap7/chi_async_bridge/README.md index 8b6a1f3025..4113871515 100644 --- a/flow/designs/asap7/chi_async_bridge/README.md +++ b/flow/designs/asap7/chi_async_bridge/README.md @@ -60,9 +60,9 @@ measured from its first flop's clock pin to its last flop's data pin. (`set_max_delay -ignore_clock_latency`): the Gray-code bound, which also covers the data; - there is no hold check between the clocks (`set_false_path -hold`); -- each domain's ports are budgeted as `$PLATFORM_DIR/constraints.sdc` - budgets a single-clock macro's, with `set_max_delay`, at that domain's - period; +- each domain's ports are budgeted with `set_max_delay`, in the shape of + `$PLATFORM_DIR/constraints.sdc` but at 80 % of that domain's period + rather than that file's fixed 80 ps; - the step from one synchroniser flop to the next is short. This is the only constraint that has to name instances. diff --git a/flow/designs/asap7/chi_async_bridge/constraint.sdc b/flow/designs/asap7/chi_async_bridge/constraint.sdc index b44d30b335..92ace53f98 100644 --- a/flow/designs/asap7/chi_async_bridge/constraint.sdc +++ b/flow/designs/asap7/chi_async_bridge/constraint.sdc @@ -36,10 +36,12 @@ set_false_path -hold -from [get_clocks noc_clk] -to [get_clocks clk] set_false_path -from [get_ports noc_reset] # ---- The ports ------------------------------------------------------- -# As $PLATFORM_DIR/constraints.sdc budgets a single-clock macro's ports, -# with that file's ratio, but per domain: the tile's ports at the core -# period, the NoC's (noc_*) at the NoC period. That file creates one -# clock, so it is not sourced here. +# Budgeted with set_max_delay, in the shape of $PLATFORM_DIR/constraints.sdc +# but not with its numbers: that file gives a single-clock macro a fixed +# 80 ps per port path, sized for a small macro. Here each domain's ports +# get 80 % of that domain's period, a choice of this file: the tile's +# ports at the core period, the NoC's (noc_*) at the NoC period. That +# file creates one clock, so it is not sourced here. set tile_in {} set noc_in {} foreach p [all_inputs -no_clocks] { From 762750f9ced7bb2d3df3458581c61ff1e350a2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 07:28:24 +0200 Subject: [PATCH 03/10] asap7/chi_async_bridge: budget the port-to-port paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit noc_tx_{req,rsp,dat}_ready reach noc_tx_*_flitv through one gate (chi_async_bridge_sink.sv: tx_flitv = valid && tx_ready), and nothing constrained them: on the small variant's synthesised netlist they were the only port-to-port paths, required INF. Give each domain an in2out budget as the platform's constraints.sdc does, at the same 80 % of that domain's period as its other port paths, and an in2out path group. Now required 816.8 ps, met by 804 ps; every other path is unchanged. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/constraint.sdc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flow/designs/asap7/chi_async_bridge/constraint.sdc b/flow/designs/asap7/chi_async_bridge/constraint.sdc index 92ace53f98..dc2a5fc370 100644 --- a/flow/designs/asap7/chi_async_bridge/constraint.sdc +++ b/flow/designs/asap7/chi_async_bridge/constraint.sdc @@ -69,11 +69,15 @@ foreach {ins outs period} [list $tile_in $tile_out $clk_period \ -from $ins -to [all_registers] set_max_delay -ignore_clock_latency [expr { $period * 0.8 }] \ -from [all_registers] -to $outs + # Through a domain without a flop: the NoC's ready reaches its flitv + # through one gate (chi_async_bridge_sink.sv, tx_flitv). + set_max_delay [expr { $period * 0.8 }] -from $ins -to $outs } group_path -name in2reg -from [all_inputs -no_clocks] -to [all_registers] group_path -name reg2out -from [all_registers] -to [all_outputs] group_path -name reg2reg -from [all_registers] -to [all_registers] +group_path -name in2out -from [all_inputs -no_clocks] -to [all_outputs] # ---- The synchronisers ------------------------------------------------ # A synchroniser's flops resolve metastability in the time a period From b3cc97bdd1dcf925453193e4543c65a77e2fa03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 07:28:31 +0200 Subject: [PATCH 04/10] asap7/chi_async_bridge: the NoC clock is not half the core's frequency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1021 ps against 300 ps is 0.29 times the frequency, not half. Only the comment changes. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/constraint.sdc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow/designs/asap7/chi_async_bridge/constraint.sdc b/flow/designs/asap7/chi_async_bridge/constraint.sdc index dc2a5fc370..ee00ea6050 100644 --- a/flow/designs/asap7/chi_async_bridge/constraint.sdc +++ b/flow/designs/asap7/chi_async_bridge/constraint.sdc @@ -8,7 +8,7 @@ set sdc_version 2.0 # (README.md, Results). Above it both close; the flow meets every target # down to here. set clk_period 300 -# The NoC clock: an unrelated period, about half the core's frequency. +# The NoC clock: an unrelated period, about 0.3 times the core's frequency. # The two never align, and nothing here depends on the ratio. set noc_clk_period 1021 From af424a0af03173eb2a24a762d61b4e9bb18ba891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 07:29:42 +0200 Subject: [PATCH 05/10] asap7/chi_async_bridge: read SYNC from VERILOG_TOP_PARAMS, as DEPTH is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The synchroniser check parsed DEPTH from VERILOG_TOP_PARAMS but fixed the stage count at 3, so a flow that set SYNC stopped at synthesis: constraint.sdc: synchronisers: sink.asyncQSink_dat_flit.widx_gray.bit_[0] has 4 stages, not 3 Parse SYNC the same way, with the RTL's default. The small variant with SYNC 2, 3 and 4 now passes the check; with SYNC 4 it stopped before. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/constraint.sdc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flow/designs/asap7/chi_async_bridge/constraint.sdc b/flow/designs/asap7/chi_async_bridge/constraint.sdc index ee00ea6050..fc3e4119ed 100644 --- a/flow/designs/asap7/chi_async_bridge/constraint.sdc +++ b/flow/designs/asap7/chi_async_bridge/constraint.sdc @@ -98,11 +98,15 @@ set sync_hop_max 72 # (flattened with '.', yosys's cell type appended; the database escapes # the brackets, timing analysis does not); sync[SYNC-1] takes the # asynchronous input, sync[0] is the output. +# +# The defaults are chi_async_bridge.sv's; VERILOG_TOP_PARAMS overrides +# them as it overrides the RTL's. set sync_stages 3 set depth 16 if { [info exists ::env(VERILOG_TOP_PARAMS)] } { foreach {k v} $::env(VERILOG_TOP_PARAMS) { if { $k eq "DEPTH" } { set depth $v } + if { $k eq "SYNC" } { set sync_stages $v } } } # 6 flit queues and 6 credit queues, each with a pointer synchroniser in From 4ae1925d72af4231723aa88ef7abe1e572f0b603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 07:29:58 +0200 Subject: [PATCH 06/10] asap7/chi_async_bridge: say the synchroniser check guards synthesis only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit constraint.sdc is read once, by synth_odb.tcl against yosys's netlist; later stages read what write_sdc made of it, one set_max_delay per hop by cell name (172 on the small variant). So the check catches what synthesis does to a synchroniser, not a buffer that resizing or hold repair puts inside a hop afterwards, which the hop's budget still bounds. The README now says so. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/flow/designs/asap7/chi_async_bridge/README.md b/flow/designs/asap7/chi_async_bridge/README.md index 4113871515..2b5b2762ac 100644 --- a/flow/designs/asap7/chi_async_bridge/README.md +++ b/flow/designs/asap7/chi_async_bridge/README.md @@ -86,6 +86,14 @@ What synthesis does to the names, on this design: The check is written against the right-hand column, and fails the build when it stops being true. +It runs once. `constraint.sdc` is read only at synthesis, against the +netlist yosys wrote; from there on every stage reads the constraints as +OpenROAD wrote them back out (`1_synth.sdc` and its successors), with +the names already resolved, one `set_max_delay` per hop. So the check +guards against what synthesis does to a synchroniser. A buffer that +resizing or hold repair later puts inside a hop is still held to the +hop's budget, but nothing checks the hop again. + ## Where it comes from XiangShan's tile is wrapped in `XSTileWrap` (`xiangshan/XSTileWrap.scala`), From 19230128b6b615e44daf36e098dc7eec4c4381a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 07:32:06 +0200 Subject: [PATCH 07/10] asap7/chi_async_bridge: the licenses the SystemVerilog comes under MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SystemVerilog is rewritten from XiangShan's Chisel rather than generated from it, but it is still derived from that source and keeps its licenses. The async queue and synchroniser come from rocket-chip (Apache-2.0, LICENSE.SiFive); the bridge halves, shadow buffer, reset synchroniser and top-level wiring from XSCache, Utility and XiangShan (Mulan PSL v2). As picorv32 does: LICENSES/ holds both texts verbatim, SOURCE.md names each file's source, commit and license, and each file starts with its SPDX identifier, the upstream copyright lines and a note of what changed. The README points at them. No RTL changes. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/README.md | 6 + .../LICENSES/XiangShan-MulanPSL-2.0.txt | 132 ++++++++++++ .../LICENSES/rocket-chip-Apache-2.0.txt | 202 ++++++++++++++++++ flow/designs/src/chi_async_bridge/SOURCE.md | 31 +++ .../src/chi_async_bridge/async_queue_sink.sv | 5 + .../chi_async_bridge/async_queue_source.sv | 5 + .../src/chi_async_bridge/chi_async_bridge.sv | 6 + .../chi_async_bridge/chi_async_bridge_sink.sv | 6 + .../chi_async_bridge_source.sv | 6 + .../designs/src/chi_async_bridge/reset_gen.sv | 6 + .../src/chi_async_bridge/shadow_buffer.sv | 6 + .../src/chi_async_bridge/sync_shift_reg.sv | 5 + 12 files changed, 416 insertions(+) create mode 100644 flow/designs/src/chi_async_bridge/LICENSES/XiangShan-MulanPSL-2.0.txt create mode 100644 flow/designs/src/chi_async_bridge/LICENSES/rocket-chip-Apache-2.0.txt create mode 100644 flow/designs/src/chi_async_bridge/SOURCE.md diff --git a/flow/designs/asap7/chi_async_bridge/README.md b/flow/designs/asap7/chi_async_bridge/README.md index 2b5b2762ac..58015b1abc 100644 --- a/flow/designs/asap7/chi_async_bridge/README.md +++ b/flow/designs/asap7/chi_async_bridge/README.md @@ -115,6 +115,12 @@ a block like XSTile is constrained with `set_max_delay` budgets on its ports rather than with input and output delays, and why only its register-to-register paths can fail timing closure. +The SystemVerilog is rewritten from that Chisel, not generated from it, +and keeps its licenses: rocket-chip's Apache-2.0 for the async queue +and synchroniser, XiangShan's Mulan PSL v2 for the rest. +`src/chi_async_bridge/SOURCE.md` says which file comes from where, at +which commit, and `src/chi_async_bridge/LICENSES/` holds both texts. + Not modelled: the NoC's CHI link layer beyond the bridge (link-state machines and the credit managers), which is logic of the NoC's own domain. Its ready signals and credits are ports here. diff --git a/flow/designs/src/chi_async_bridge/LICENSES/XiangShan-MulanPSL-2.0.txt b/flow/designs/src/chi_async_bridge/LICENSES/XiangShan-MulanPSL-2.0.txt new file mode 100644 index 0000000000..68d8753110 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/LICENSES/XiangShan-MulanPSL-2.0.txt @@ -0,0 +1,132 @@ + + 木兰宽松许可证, 第2版 + + 木兰宽松许可证, 第2版 + 2020年1月 http://license.coscl.org.cn/MulanPSL2 + + + 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + + 0. 定义 + + “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + + “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + + “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + + “法人实体”是指提交贡献的机构及其“关联实体”。 + + “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + + 1. 授予版权许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + + 2. 授予专利许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + + 3. 无商标许可 + + “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + + 4. 分发限制 + + 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + + 5. 免责声明与责任限制 + + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + + 6. 语言 + “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + + 条款结束 + + 如何将木兰宽松许可证,第2版,应用到您的软件 + + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + + 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + + 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + + 3, 请将如下声明文本放入每个源文件的头部注释中。 + + Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences + Copyright (c) 2020-2021 Peng Cheng Laboratory + + XiangShan is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + + + Mulan Permissive Software License,Version 2 + + Mulan Permissive Software License,Version 2 (Mulan PSL v2) + January 2020 http://license.coscl.org.cn/MulanPSL2 + + Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + + 0. Definition + + Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + + Contribution means the copyrightable work licensed by a particular Contributor under this License. + + Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + + Legal Entity means the entity making a Contribution and all its Affiliates. + + Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + + 1. Grant of Copyright License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + + 2. Grant of Patent License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + + 3. No Trademark License + + No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. + + 4. Distribution Restriction + + You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + + 5. Disclaimer of Warranty and Limitation of Liability + + THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + 6. Language + + THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + + END OF THE TERMS AND CONDITIONS + + How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + + To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + + i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; + + ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; + + iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. + + + Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences + Copyright (c) 2020-2021 Peng Cheng Laboratory + + XiangShan is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. \ No newline at end of file diff --git a/flow/designs/src/chi_async_bridge/LICENSES/rocket-chip-Apache-2.0.txt b/flow/designs/src/chi_async_bridge/LICENSES/rocket-chip-Apache-2.0.txt new file mode 100644 index 0000000000..7e70933754 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/LICENSES/rocket-chip-Apache-2.0.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2016-2017 SiFive, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/flow/designs/src/chi_async_bridge/SOURCE.md b/flow/designs/src/chi_async_bridge/SOURCE.md new file mode 100644 index 0000000000..5ce56a8493 --- /dev/null +++ b/flow/designs/src/chi_async_bridge/SOURCE.md @@ -0,0 +1,31 @@ +# chi_async_bridge source + +- Top: `chi_async_bridge` +- Upstream sources, as XiangShan pins them: + - `OpenXiangShan/XiangShan`, commit + `aa6b52033add528a504bdb2c2b726100d89f070a` + - `OpenXiangShan/XSCache`, commit + `300515bc7b2f65ca988041a984204489d80ec2fb` + - `OpenXiangShan/Utility`, commit + `eb8e12b00a33e4716e7778175f6dd45b7a3a9ede` + - `OpenXiangShan/rocket-chip`, commit + `a2df1a42399cfe2b343eeb5293796268dc2bc211` + +The upstream RTL is Chisel. These files are not the Verilog it +generates: they were rewritten as readable SystemVerilog, module by +module, from that Chisel, and each file's header names the Scala source +and lines it models. They are derived from that source and keep its +license: + +| file | derived from | license | +|---|---|---| +| `async_queue_source.sv`, `async_queue_sink.sv` | rocket-chip `src/main/scala/util/AsyncQueue.scala` | Apache-2.0, `LICENSES/rocket-chip-Apache-2.0.txt` | +| `sync_shift_reg.sv` | rocket-chip `src/main/scala/util/SynchronizerReg.scala` | Apache-2.0, `LICENSES/rocket-chip-Apache-2.0.txt` | +| `chi_async_bridge_source.sv`, `chi_async_bridge_sink.sv`, `shadow_buffer.sv` | XSCache `src/main/scala/xscache/chi/AsyncBridge.scala` | Mulan PSL v2, `LICENSES/XiangShan-MulanPSL-2.0.txt` | +| `reset_gen.sv` | Utility `src/main/scala/utility/ResetGen.scala` | Mulan PSL v2, `LICENSES/XiangShan-MulanPSL-2.0.txt` | +| `chi_async_bridge.sv` | XiangShan `XSTileWrap.scala` and `XSNoCTop.scala`, which place the two halves | Mulan PSL v2, `LICENSES/XiangShan-MulanPSL-2.0.txt` | + +`LICENSES/rocket-chip-Apache-2.0.txt` is rocket-chip's `LICENSE.SiFive`, +to which those Scala files refer. `LICENSES/XiangShan-MulanPSL-2.0.txt` +is XSCache's `LICENSE`; the Utility and XiangShan sources carry the same +Mulan PSL v2 header. diff --git a/flow/designs/src/chi_async_bridge/async_queue_sink.sv b/flow/designs/src/chi_async_bridge/async_queue_sink.sv index a51636c605..084672dcd4 100644 --- a/flow/designs/src/chi_async_bridge/async_queue_sink.sv +++ b/flow/designs/src/chi_async_bridge/async_queue_sink.sv @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2016-2017 SiFive, Inc. +// Changed from the original: rewritten as readable SystemVerilog from +// rocket-chip's Chisel. SOURCE.md names the source and its license. +// // The reading half of an asynchronous queue: rocket-chip's AsyncQueueSink // (util/AsyncQueue.scala:148-179 at a2df1a4), safe = false, narrow = false. // diff --git a/flow/designs/src/chi_async_bridge/async_queue_source.sv b/flow/designs/src/chi_async_bridge/async_queue_source.sv index b55c3b2b3c..1bd30fb46e 100644 --- a/flow/designs/src/chi_async_bridge/async_queue_source.sv +++ b/flow/designs/src/chi_async_bridge/async_queue_source.sv @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2016-2017 SiFive, Inc. +// Changed from the original: rewritten as readable SystemVerilog from +// rocket-chip's Chisel. SOURCE.md names the source and its license. +// // The writing half of an asynchronous queue: rocket-chip's // AsyncQueueSource (util/AsyncQueue.scala:70-104 at a2df1a4) with // safe = false and narrow = false, which is how XiangShan's CHI bridge diff --git a/flow/designs/src/chi_async_bridge/chi_async_bridge.sv b/flow/designs/src/chi_async_bridge/chi_async_bridge.sv index f694b0b2b0..2cf6796c7c 100644 --- a/flow/designs/src/chi_async_bridge/chi_async_bridge.sv +++ b/flow/designs/src/chi_async_bridge/chi_async_bridge.sv @@ -1,3 +1,9 @@ +// SPDX-License-Identifier: MulanPSL-2.0 +// Copyright (c) 2024-2025 Beijing Institute of Open Source Chip (BOSC) +// Copyright (c) 2024-2025 Institute of Computing Technology, Chinese Academy of Sciences +// Changed from the original: rewritten as readable SystemVerilog from +// XiangShan's Chisel. SOURCE.md names the source and its license. +// // chi_async_bridge: the asynchronous CHI bridge between XiangShan's tile // and its network-on-chip, both halves in one block. README.md (beside // config.mk) tells the story; this file only wires the halves together. diff --git a/flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv b/flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv index d8d1190c57..b4ff26530a 100644 --- a/flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv +++ b/flow/designs/src/chi_async_bridge/chi_async_bridge_sink.sv @@ -1,3 +1,9 @@ +// SPDX-License-Identifier: MulanPSL-2.0 +// Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences +// Copyright (c) 2020-2021 Peng Cheng Laboratory +// Changed from the original: rewritten as readable SystemVerilog from +// XiangShan's Chisel. SOURCE.md names the source and its license. +// // The NoC's half of the bridge, on the NoC clock: XSCache's // CHIAsyncBridgeSink (xscache/chi/AsyncBridge.scala:227-341 at 300515b), // which XSNoCTop instantiates (XSNoCTop.scala:275-276). The mirror image diff --git a/flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv b/flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv index cb6f73153a..c9c1f88a58 100644 --- a/flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv +++ b/flow/designs/src/chi_async_bridge/chi_async_bridge_source.sv @@ -1,3 +1,9 @@ +// SPDX-License-Identifier: MulanPSL-2.0 +// Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences +// Copyright (c) 2020-2021 Peng Cheng Laboratory +// Changed from the original: rewritten as readable SystemVerilog from +// XiangShan's Chisel. SOURCE.md names the source and its license. +// // The tile's half of the bridge, on the core clock: XSCache's // CHIAsyncBridgeSource (xscache/chi/AsyncBridge.scala:157-225 at // 300515b), which XSTileWrap instantiates beside XSTile diff --git a/flow/designs/src/chi_async_bridge/reset_gen.sv b/flow/designs/src/chi_async_bridge/reset_gen.sv index 3f661bb54b..4533a2b2fd 100644 --- a/flow/designs/src/chi_async_bridge/reset_gen.sv +++ b/flow/designs/src/chi_async_bridge/reset_gen.sv @@ -1,3 +1,9 @@ +// SPDX-License-Identifier: MulanPSL-2.0 +// Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences +// Copyright (c) 2020-2021 Peng Cheng Laboratory +// Changed from the original: rewritten as readable SystemVerilog from +// XiangShan's Chisel. SOURCE.md names the source and its license. +// // A reset synchroniser: asserts asynchronously, releases SYNC clocks // later on this domain's clock. XiangShan's ResetGen // (utility/ResetGen.scala at eb8e12b), without its DFT muxes. diff --git a/flow/designs/src/chi_async_bridge/shadow_buffer.sv b/flow/designs/src/chi_async_bridge/shadow_buffer.sv index 39b75abca2..c76d9cbed4 100644 --- a/flow/designs/src/chi_async_bridge/shadow_buffer.sv +++ b/flow/designs/src/chi_async_bridge/shadow_buffer.sv @@ -1,3 +1,9 @@ +// SPDX-License-Identifier: MulanPSL-2.0 +// Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences +// Copyright (c) 2020-2021 Peng Cheng Laboratory +// Changed from the original: rewritten as readable SystemVerilog from +// XiangShan's Chisel. SOURCE.md names the source and its license. +// // The bridge's shadow buffer: a Chisel Queue(entries = 16, flow = true, // pipe = false) in front of each outgoing CHI flit channel's async queue // (ToAsyncBundleWithBuf, xscache/chi/AsyncBridge.scala:67-94 at XSCache diff --git a/flow/designs/src/chi_async_bridge/sync_shift_reg.sv b/flow/designs/src/chi_async_bridge/sync_shift_reg.sv index 84011f3761..b544fbdb26 100644 --- a/flow/designs/src/chi_async_bridge/sync_shift_reg.sv +++ b/flow/designs/src/chi_async_bridge/sync_shift_reg.sv @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2016-2017 SiFive, Inc. +// Changed from the original: rewritten as readable SystemVerilog from +// rocket-chip's Chisel. SOURCE.md names the source and its license. +// // A synchroniser: WIDTH independent chains of SYNC flops, each bit // clocked into the destination domain. Rocket-chip's // AsyncResetSynchronizerShiftReg (util/SynchronizerReg.scala at a2df1a4, From c4b171cc3637e4a278c36e162db96e387f9bc9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 08:14:17 +0200 Subject: [PATCH 08/10] asap7/chi_async_bridge: link hierarchically, the bridge's modules kept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OPENROAD_HIERARCHICAL=1, the -hier mode that is to become the default. A flat netlist gives -hier nothing to link, so SYNTH_KEEP_MODULES keeps what a clock-crossing bridge is usually kept as: the two clock-domain halves, their asynchronous queues and their shadow buffers. The synchroniser check in constraint.sdc now finds the chains with get_cells -hierarchical; their names are the kept instances joined with '/', e.g. sink/asyncQSink_dat_flit/widx_gray.bit_[0].sync[1]. On the small variant all 172 hops are found and written back by name. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/README.md | 8 +++++++- flow/designs/asap7/chi_async_bridge/config.mk | 9 +++++++++ flow/designs/asap7/chi_async_bridge/constraint.sdc | 10 ++++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/flow/designs/asap7/chi_async_bridge/README.md b/flow/designs/asap7/chi_async_bridge/README.md index 58015b1abc..6679a796fb 100644 --- a/flow/designs/asap7/chi_async_bridge/README.md +++ b/flow/designs/asap7/chi_async_bridge/README.md @@ -74,11 +74,17 @@ checks that each synchroniser flop drives the next one and nothing else; if synthesis has renamed or restructured them, the flow stops at the synthesis stage with an error saying which. +The design is linked hierarchically (`OPENROAD_HIERARCHICAL`), the way +a clock-crossing bridge is usually kept: its two clock-domain halves, +their asynchronous queues and their shadow buffers stay modules, and +everything inside them is flattened. The check looks for the +synchronisers at every level of that hierarchy. + What synthesis does to the names, on this design: | in the RTL | in the netlist | |---|---| -| `sync_shift_reg ridx_gray`, its `bit_[2]`, flop `sync[1]` | `sink.asyncQSource_dat_flit.ridx_gray.bit_[2].sync[1]$_DFF_PP0_`: the hierarchy flattened with `.`, yosys's cell type appended | +| `sync_shift_reg ridx_gray`, its `bit_[2]`, flop `sync[1]` | `sink/asyncQSource_dat_flit/ridx_gray.bit_[2].sync[1]$_DFF_PP0_`: the kept modules (`SYNTH_KEEP_MODULES`) joined with `/`, the hierarchy inside them flattened with `.`, yosys's cell type appended | | the register `ridx_gray` that drives the output `async_ridx` | `...async_ridx[0]$_DFF_PP0_`: a flop takes the name of the net it drives, not of the variable that holds it | | the same flop, in the database and in timing analysis | `bit_\[2\].sync\[1\]` in ODB, `bit_[2].sync[1]` from `get_full_name` | | one flop driving the next | a flop, an inverter, a flop: asap7's flop with asynchronous set and reset, `DFFASRHQNx1`, has only an inverted output | diff --git a/flow/designs/asap7/chi_async_bridge/config.mk b/flow/designs/asap7/chi_async_bridge/config.mk index 161fc151c3..1f9e2cda64 100644 --- a/flow/designs/asap7/chi_async_bridge/config.mk +++ b/flow/designs/asap7/chi_async_bridge/config.mk @@ -11,6 +11,15 @@ export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/constraint. # Readable, parameterised SystemVerilog, read by slang. export SYNTH_HDL_FRONTEND = slang +# OpenROAD links the netlist hierarchically (-hier), the mode that is to +# become the default, so this design tests it. A clock-crossing bridge +# keeps its structure by name: the two clock-domain halves, their +# asynchronous queues and their shadow buffers stay modules, so the +# crossing is visible in the hierarchy -hier links. +export OPENROAD_HIERARCHICAL = 1 +export SYNTH_KEEP_MODULES = chi_async_bridge_source chi_async_bridge_sink \ + async_queue_source async_queue_sink shadow_buffer + # All three threshold voltages, as for the core this bridge serves. export ASAP7_USE_VT = RVT LVT SLVT diff --git a/flow/designs/asap7/chi_async_bridge/constraint.sdc b/flow/designs/asap7/chi_async_bridge/constraint.sdc index fc3e4119ed..1a7fe9f0d6 100644 --- a/flow/designs/asap7/chi_async_bridge/constraint.sdc +++ b/flow/designs/asap7/chi_async_bridge/constraint.sdc @@ -95,9 +95,11 @@ set sync_hop_max 72 # # In that netlist a chain flop is named, as timing analysis spells it, # .bit_[].sync[]$_DFF_PP_ -# (flattened with '.', yosys's cell type appended; the database escapes -# the brackets, timing analysis does not); sync[SYNC-1] takes the -# asynchronous input, sync[0] is the output. +# (the kept modules (config.mk) joined with '/', the hierarchy inside +# each flattened with '.', yosys's cell type appended; the database +# escapes the brackets, timing analysis does not); sync[SYNC-1] takes +# the asynchronous input, sync[0] is the output. The chains sit inside +# kept modules, so they are found at every level of the hierarchy. # # The defaults are chi_async_bridge.sv's; VERILOG_TOP_PARAMS overrides # them as it overrides the RTL's. @@ -131,7 +133,7 @@ proc sync_output { cell } { } set chains [dict create] -foreach cell [get_cells -quiet {*_gray.bit_* *sync_link.bit_*}] { +foreach cell [get_cells -quiet -hierarchical {*_gray.bit_* *sync_link.bit_*}] { set name [get_full_name $cell] if { ![regexp {^(.*)\.sync\[([0-9]+)\]} $name -> chain stage] } { sync_check_fail "unexpected cell name $name" From bd2b7035d7d110236eb469a051b3a5b44841ab80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 08:35:08 +0200 Subject: [PATCH 09/10] asap7/chi_async_bridge: README says what it tests that no other design does MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An integration test: a timed asynchronous crossing, a self-checking constraint file, slang with SYNTH_KEEP_MODULES under -hier, instance names resolved through the hierarchy, three threshold voltages on a multi-clock design, and the top's parameters set from the flow. Checked against every config.mk and SDC under flow/designs. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/flow/designs/asap7/chi_async_bridge/README.md b/flow/designs/asap7/chi_async_bridge/README.md index 6679a796fb..232be43262 100644 --- a/flow/designs/asap7/chi_async_bridge/README.md +++ b/flow/designs/asap7/chi_async_bridge/README.md @@ -12,6 +12,25 @@ from one clock to the other meets its budget, nothing tries to fix hold across the asynchronous boundary, each synchroniser's flops stay together, and what is left to fail is the logic inside each domain. +## What it tests that no other design here does + +It is an integration test: one small block that takes a combination of +the flow's features through every stage together. Among the designs in +`flow/designs`, it is the only one with all of them, and the only one +with some of them at all: + +| feature | where | elsewhere in `flow/designs` | +|---|---|---| +| an asynchronous crossing that is timed: `set_clock_groups -asynchronous -allow_paths`, bounded by `set_max_delay -ignore_clock_latency` between the clocks, no hold check across | `constraint.sdc` | only `asap7/mock-cpu`; the other multi-clock designs declare their clocks exclusive or time only virtual IO clocks | +| a constraint file that checks the netlist it names and stops the flow if synthesis renamed, merged or restructured what it constrains | `constraint.sdc`, the synchronisers | none | +| the slang frontend, the hierarchy kept by name with `SYNTH_KEEP_MODULES` on slang's uniquified, parameterised modules, and linked with `OPENROAD_HIERARCHICAL` (`-hier`) | `config.mk` | none together; `asap7/mock-cpu` keeps its hierarchy with an RTL attribute and reads its Verilog with yosys | +| instance names in the constraints resolved through that hierarchy (`get_cells -hierarchical`) and written back by hierarchical name for every later stage | `constraint.sdc` | none | +| three threshold voltages, RVT, LVT and SLVT, on a multi-clock design | `ASAP7_USE_VT` | `asap7/cva6`, single-clock; the `_lvt` designs use LVT alone | +| the top's parameters set from the flow, one RTL for every variant | `VERILOG_TOP_PARAMS` | `asap7/uart` | + +A change to any of these shows up here first, in a design small enough +to run in minutes (`FLOW_VARIANT=small`). + ## The crossing ```mermaid From e3f84f8ce65097e4bd3e5e66b2955e8a9ffab100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 6 Oct 2026 08:48:32 +0200 Subject: [PATCH 10/10] asap7/chi_async_bridge: core clock 290 ps, so repair does not stop at grt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At 300 ps the worst slack reached +0.001 ps at global route (flat netlist), so repair stopped there. At 290 ps, linked hierarchically, the worst slack is -35.8 ps at CTS, -35.5 ps at global route and -30.1 ps at final, on the core half's async queue sink read, as in XiangShan. README.md's Results say so; the XiangShan calibration there is marked as measured on the flat netlist. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Øyvind Harboe --- flow/designs/asap7/chi_async_bridge/README.md | 46 ++++++++++--------- .../asap7/chi_async_bridge/constraint.sdc | 12 ++--- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/flow/designs/asap7/chi_async_bridge/README.md b/flow/designs/asap7/chi_async_bridge/README.md index 232be43262..af19367d79 100644 --- a/flow/designs/asap7/chi_async_bridge/README.md +++ b/flow/designs/asap7/chi_async_bridge/README.md @@ -152,20 +152,32 @@ domain. Its ready signals and credits are ports here. ## Results -The core clock is set where the flow stops keeping up: given 420, 380 -or 340 ps it closes, each time within a few picoseconds of the target; -given 300 ps, the worst path just fails. That path is the core half's async queue sink, from the read +The core clock is 290 ps, a little below what the flow closes, so the +worst slack stays negative through global route and repair keeps +working rather than stopping at zero: + +| base, core clock 290 ps | worst slack | +|---|---| +| CTS | -35.8 ps | +| global route | -35.5 ps | +| final | -30.1 ps | + +The worst path is the core half's async queue sink, from the read pointer through the read-mux select, buffered out to every bit of a 385-bit data flit, into `deq_bits_reg`: the queue's own logic, as in -XiangShan. +XiangShan. Detailed routing leaves 113 max-slew violations, all in the +NoC half's data flit channel: 57 in its shadow buffer, 56 in its async +queue sink. This design reproduces XiangShan's bridge. Both were run through the -same flow and constraints at the same targets, to global route; the -XiangShan side is XiangShan's own `CHIAsyncBridgeSource` and -`CHIAsyncBridgeSink`, elaborated from its Chisel with its parameters -and hardened alone. - -| at global route | target | this design | XiangShan's bridge | +same flow and constraints at the same targets, to global route, with +the netlist flattened; the XiangShan side is XiangShan's own +`CHIAsyncBridgeSource` and `CHIAsyncBridgeSink`, elaborated from its +Chisel with its parameters and hardened alone. Given 420, 380 or 340 ps +both close, each time within a few picoseconds of the target; given +300 ps, both just fail, on the same path. + +| at global route, flat | target | this design | XiangShan's bridge | |---|---|---|---| | core clock, min period | 340 ps | 339.7 ps | 340.0 ps | | core clock, min period | 300 ps | 305.9 ps | 301.4 ps | @@ -173,32 +185,24 @@ and hardened alone. | its logic / inserted buffers / wire | | 163 / 80 / 22 ps | 159 / 76 / 22 ps | | flops | | 35,106 | 35,043 | -Through the rest of the flow, base ends at final with a worst slack of --23.1 ps (core clock min period 323.1 ps), on the shadow buffer's read -pointer into the async queue's memory write, the class that comes -second at global route. Detailed routing also leaves 149 max-slew -violations on 9 nets, all of them a queue's entry write-enable or read -select, decoded once and buffered out across a 385-bit entry, which -global route did not report. - The NoC half is not calibrated: XiangShan's NoC link layer, left out here, is in its NoC domain's worst path. Both NoC domains keep more than 200 ps of slack at the NoC period, so neither limits the design. The clock trees are the ones OpenROAD's CTS builds: clusters of sinks under an H-tree, no mesh, and no on-chip-variation derates in this flow. -At final the core tree is 261 ps deep, most of a 300 ps period. That is +At final the core tree is about 260 ps deep, most of the period. That is an ordinary tree at a 1,000 ps period and not what a core aimed at 300 ps would get, which is a clock mesh or a multi-source tree that keeps paths diverging late. It does not touch what this design tests: the crossing is timed without clock latency and without a hold check, so the depth of either tree does not enter it. What the tree does move is the same-clock paths, the synchroniser hops among them, and with them -the 300 ps; XiangShan's bridge was measured through the same trees. +the period; XiangShan's bridge was measured through the same trees. ## Variants -| FLOW_VARIANT | flits (req/rsp/dat/snp bits) | queue depth | flops | core clock min period at 300 ps, global route | to global route | +| FLOW_VARIANT | flits (req/rsp/dat/snp bits) | queue depth | flops | core clock min period at 300 ps, global route, flat | to global route | |---|---|---|---|---|---| | base | 125 / 51 / 385 / 88, XiangShan's | 16 | 35,106 | 305.9 ps, fails | 30 min | | medium | 125 / 51 / 385 / 88 | 4 | 21,846 | 299.5 ps, closes | 20 min | diff --git a/flow/designs/asap7/chi_async_bridge/constraint.sdc b/flow/designs/asap7/chi_async_bridge/constraint.sdc index 1a7fe9f0d6..b229bf12f3 100644 --- a/flow/designs/asap7/chi_async_bridge/constraint.sdc +++ b/flow/designs/asap7/chi_async_bridge/constraint.sdc @@ -2,12 +2,12 @@ # between them. README.md says what each constraint is for. set sdc_version 2.0 -# The core clock: the period at which XiangShan's own bridge, hardened -# alone through this flow, just fails at global route (-1.4 ps, on the -# core half's async queue sink read path), and so does this design -# (README.md, Results). Above it both close; the flow meets every target -# down to here. -set clk_period 300 +# The core clock: a little below what the flow can close, so the worst +# slack stays negative through global route and repair keeps working +# instead of stopping at zero. XiangShan's own bridge, hardened alone +# through this flow, just fails at 300 ps on the core half's async queue +# sink read path, and so does this design (README.md, Results). +set clk_period 290 # The NoC clock: an unrelated period, about 0.3 times the core's frequency. # The two never align, and nothing here depends on the ratio. set noc_clk_period 1021