Skip to content

cranelift: wrong edges in a compiled scheduler with more than 64 events (128-bit masks) #2102

Closed

Description

@tignear

Summary

With more than 64 events, the compiled scheduler's event masks (levels, exit_arg, fire masks) are 128 bits or wider (#2012, #2084). The Cranelift backend computes the wrong edges for such a scheduler unit: flip-flop domains fire on falling edges and on edges of other clocks. The native, interpreter, tiered (native tier) and Wasm backends run the same SIR unit correctly.

#2084 makes Cranelift keep the runtime's round loop for these designs (the behavior before #2012), so the bug is unreachable until it is fixed.

Reproduction

The design from scheduler::tests::more_than_64_events_run_on_every_backend (crates/celox/src/scheduler.rs, #2084) has 70 clocks c0..c69. Each clocks a counter always_ff @(posedge cN) nN <= nN + 1, and 7 processes always #p begin cA = ~cA; ... end toggle them, 10 clocks per period p = 1..7. To reproduce, remove the fallback in SharedJitCode and run it with build_cranelift():

  • run_until(100) gives n0 = 88 (expected 50: rising edges at 1, 3, 5, ...).
  • In SchedulerMode::Differential the run fails with the scheduler diverged from the reference in the step from time 0: state byte 49 (n1).
  • Up to t = 7 every counter increments at every step, including falling edges and steps where its own clock does not move.

What was ruled out:

  • Optimization: it fails at O0 and with every SIR pass disabled one at a time, so it comes from the Cranelift translation of the unit.
  • One-word masks: with 60 clocks the same design runs correctly on Cranelift.
  • Basic 128-bit operations: in combinational logic, Cranelift agrees with native on -, &, ^ with all ones, |, ?:, ==, !=, x & (x - 1) == 0 and 128-bit immediates with bits at and above 64.

The scheduler unit is large, so a lead to check first is the memory-spilled chunking in the translator (translate_spilled_chunk): wide registers and block parameters carried across chunks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions