Opportunity: Software Execution Time Determinism

Marc Schütz via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 14 02:46:34 PDT 2016


On Thursday, 14 April 2016 at 00:31:34 UTC, Simen Kjaeraas wrote:
> @constanttime functions can only call other functions marked
> @constanttime, and may not contain conditionals, gotos or
> while-loops.
>
> @constanttime functions may contain for and foreach-loops, iff
> the number of iterations are known at compile-time, and 'break'
> is never used.
>
> The part about conditionals seems a bit harsh, but it's got to
> be there for determinism.

It can be relaxed: All alternative branches must take the same 
number of cycles, though this can be hard to determine.

Recursion is an interesting problem, though: to reliably detect 
it, the compiler has to know the entire call graph, i.e. not 
extern functions are allowed. On the other hand, without 
conditionals, recursion will always result in an endless loop, 
which will immediately be recognized in testing.


More information about the Digitalmars-d mailing list