@@ -491,6 +491,66 @@ def test_different_rates(self):
491491 assert slow_vals [- 1 ] == 5 , f"Expected slow_count=5, got { slow_vals [- 1 ]} "
492492
493493
494+ def _make_mixed_edge_single_clock () -> Module :
495+ """Two counters sharing one clock, one posedge and one negedge."""
496+ return Module (
497+ name = "mixed_edge" ,
498+ ports = (
499+ Port (Signal ("clk" , Shape (1 )), PortDirection .INPUT ),
500+ Port (Signal ("pos_count" , Shape (8 ), init = 0 ), PortDirection .OUTPUT ),
501+ Port (Signal ("neg_count" , Shape (8 ), init = 0 ), PortDirection .OUTPUT ),
502+ ),
503+ clock_domains = (
504+ ClockDomain ("pos" , clk = "clk" , edge = EdgePolarity .POSEDGE ),
505+ ClockDomain ("neg" , clk = "clk" , edge = EdgePolarity .NEGEDGE ),
506+ ),
507+ seq_blocks = (
508+ SeqBlock (
509+ "pos" ,
510+ stmts = (
511+ Assign (
512+ "pos_count" ,
513+ Binary (
514+ Shape (8 ),
515+ BinaryOp .ADD ,
516+ SignalRef (Shape (8 ), "pos_count" ),
517+ Const (Shape (8 ), 1 ),
518+ ),
519+ ),
520+ ),
521+ ),
522+ SeqBlock (
523+ "neg" ,
524+ stmts = (
525+ Assign (
526+ "neg_count" ,
527+ Binary (
528+ Shape (8 ),
529+ BinaryOp .ADD ,
530+ SignalRef (Shape (8 ), "neg_count" ),
531+ Const (Shape (8 ), 1 ),
532+ ),
533+ ),
534+ ),
535+ ),
536+ ),
537+ )
538+
539+
540+ class TestMixedClockEdges :
541+ def test_posedge_and_negedge_domains_progress_equally (self ):
542+ """Both domains should tick once per full period on shared clock."""
543+ m = _make_mixed_edge_single_clock ()
544+ cm = compile_module (m )
545+ traces = cm .run (cycles = 8 )
546+
547+ pos_vals = [v for _ , v in traces ["pos_count" ]]
548+ neg_vals = [v for _ , v in traces ["neg_count" ]]
549+
550+ assert pos_vals [- 1 ] == 8 , f"Expected pos_count=8, got { pos_vals [- 1 ]} "
551+ assert neg_vals [- 1 ] == 8 , f"Expected neg_count=8, got { neg_vals [- 1 ]} "
552+
553+
494554class TestLongRunCounter :
495555 def test_100_cycle_counter (self ):
496556 """Simulate 4-bit counter with reset for 100 cycles."""
0 commit comments