issie icon indicating copy to clipboard operation
issie copied to clipboard

Make simulations work for times longer than given by an `int32` time.

Open tomcl opened this issue 11 months ago • 0 comments

Is your feature request related to a problem? Please describe.

Currently simulations cannot continue for more than approx 2,000,000,000 clock cycles (2^31 - 1) because time is represented by an int32. This limit can be reached within a few minutes on a small circuit.

Describe the solution you'd like

Make this limit arbitrary by using bigint not int to represent times. Note that although time is now bigint indexes into the (limited size) circular array are still int.

Describe alternatives you've considered

  • It would be possible to use uint32 for an easy doubling of range - that is not really enough
  • It would be possible to use int64 - but the JS translation of int64 is bigint anyway!

Additional context

  • This is relatively easy refactoring but will require understanding of the simulator code in some detail
  • The code that calls the simulator is currently very messy - with layers of functions calling the underlying top-level simulation function FastRun.runFastSimulation
  • As part of the refactoring these functions should be traced and fully documented to make future changes this code easier.

Refactoring Notes

  • The simulation time is held inside the fast simulation record as a mutable fs.ClockTick. That means changing the type of ClockTick will probably via the compiler lead to the necessary refactoring of simulation times.
  • Most problematic will be the display functions for time which will need to be changed. Displaying int64 would however be enough since practically we cannot get beyond max int64 clock ticks.
  • The simulator is called from a number of other top-level functions in FastRun. Those must all be checked for possible necessary refactoring of the simulation time type.

tomcl avatar Mar 28 '24 15:03 tomcl