Timing & Clock Domains
Inspired by Filament, every hardware logic value in Neo carries both a cycle timing and a clock domain. This lets Neo statically catch pipeline misalignment (e.g., combining cycle t with cycle t + 1) and accidental clock-domain crossings (CDC) at compile time.
The Timing Lattice
Neo's timings form a partial order (lattice):
Constant <= SingleCycle(trigger, offset, clock) <= Dynamic(clock)1. Constant (Bottom)
- Written by omitting the timing annotation (e.g.,
logic mask: Bits(4) = "1010";), or produced by literals (42#32,"0101",0,1, enum variants, payload-less union variants,b.toBits()). - Compatible with every timing and crosses every clock domain safely because constant values never change.
- A
Constant-timed target can only be assigned from aConstantsource.
2. SingleCycle(trigger, offset, clock)
- Represents a value valid at
trigger + offsetcycles relative toclock. - Introduced by:
- A
t: Timingmodule/interface parameter (clock domainAny, polymorphic over the caller's clock domain). Timing()— creates a fresh single-cycle trigger in the__defaultClockdomain.Timing(clk)— creates a fresh single-cycle trigger bound to an explicitClock-typed signalclk.- Arithmetic
t + nwheret: Timingandn: UInt.
- A
- A
SingleCycle(t1, o1, c1)target accepts:Constant, orSingleCycle(t2, o2, c2)ifft1 == t2,c1andc2are compatible clock domains, and Z3 proveso1 == o2.
SingleCycle <- Dynamicis forbidden: you cannot assign an untimedDynamicvalue into a cycle-timedSingleCyclesignal.
3. Dynamic(clock) (Top within a clock domain)
- Written
(*)for domain-polymorphic dynamic timing (ClockDomain::Any), or(Dynamic(clk))to bind a dynamic signal to a specificClock-typed signalclk. - Useful for asynchronous/stalled handshakes (such as
Decoupled(T)'sreadyandreq), state machines, and control signals not tied to a fixed pipeline cycle. - Accepts
Constant,SingleCycle(in a compatible clock domain), orDynamic(in a compatible clock domain).
Timing Joins (Least Upper Bound)
When combining signals in binary operators (a + b, a & b, a == b), concatenation (a ## b), struct literals (.{ a, b }), tuple literals ((a, b)), Array.select(idx), or if/case/match branches, Neo computes the least upper bound (LUB) of their timings:
join(Constant, x) = xjoin(Dynamic(c1), x(c2)) = Dynamic(merge(c1, c2))(if clocks are compatible)join(SingleCycle(t1, o1, c1), SingleCycle(t2, o2, c2)) = SingleCycle(t1, o1, merge(c1, c2))ifft1 == t2, clocks are compatible, and Z3 proveso1 == o2(otherwisetiming_mismatch).- Combining non-constant signals from incompatible clock domains produces
clock_domain_mismatch.
Cycle Advancement (seq and Reg)
- Inside a
seqorseq clkblock, assigning a source expression to a non-local register target advances the source timing by+1cycle (SingleCycle(t, off, clk) -> SingleCycle(t, off + 1, clk);ConstantandDynamicremainConstantandDynamic). - A local
logicsignal declared inside aseqblock is a combinational temporary and does not advance cycles. Reg(expr)registersexpron__defaultClockand returns a value with timing advanced by+1cycle.
@top
module Pipeline(t: Timing) {
input x(t): Int(32),
output y(t + 2): Int(32),
} {
logic s1(t + 1): Int(32);
seq {
logic doubled(t): Int(32) = x + x; // seq-local combinational temp
s1 = doubled; // t -> t + 1
}
assign y = Reg(s1); // t + 1 -> t + 2
}Clock Domains & CDC Verification
Every non-constant timing carries a ClockDomain:
ClockDomain::Default: The module's implicit__defaultClock(created byTiming(),seq { ... }, andReg(...)).ClockDomain::Signal(clk): A specificClock-typed port or wire (created byTiming(clk),Dynamic(clk), andseq clk { ... }).ClockDomain::Any: Domain-polymorphic timing ((*)or symbolict: Timingparameters), compatible with any single clock domain and refined when merged with a concrete domain.
Two clock domains are compatible iff either is Any or both refer to the exact same clock.
Static CDC Error Detection
Neo catches clock-domain crossings automatically:
- Cross-domain reads (
clock_domain_mismatch):- Reading a signal from clock domain
clk_ainsideseq clk_b { ... }(or inside default-clockedseq { ... }/Reg(...)). - Combining two signals from different clock domains in an expression (e.g.,
a_fast + b_slow) or assigning a signal fromclk_ato a target inclk_b.
- Reading a signal from clock domain
- Cross-domain writes (
seq_block_clock_mismatch):- Assigning to a register target whose timing belongs to
clk_ainside aseq clk_b { ... }block.
- Assigning to a register target whose timing belongs to
@top
module DualClock {
input clk_a: Clock,
input clk_b: Clock,
input in_a(Dynamic(clk_a)): Bits(8),
output out_a(Dynamic(clk_a)): Bits(8),
input in_b(Dynamic(clk_b)): Bits(8),
output out_b(Dynamic(clk_b)): Bits(8),
} {
// No __defaultClock is emitted because only explicit custom clocks are used!
seq clk_a {
out_a = in_a; // OK: clk_a -> clk_a
// out_a = in_b; // ERROR (clock_domain_mismatch): reading clk_b inside seq clk_a
// out_b = in_a; // ERROR (seq_block_clock_mismatch): writing clk_b inside seq clk_a
}
seq clk_b {
out_b = in_b; // OK: clk_b -> clk_b
}
}Because DualClock uses only explicit clk_a and clk_b (no implicit seq { ... } or Reg(...)), Neo emits no __defaultClock port on the generated SystemVerilog or FIRRTL module.