On Thursday, 14 April 2016 at 09:46:34 UTC, Marc Schütz wrote:
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.
I've done this manually on simple microcontrollers. You add up
the time taken for instructions on each path and balance them
with nops. Probably impossible on a cpu instruction set which
might be run on many different processors with different pipeline
lengths, parellel processing units etc. Definitely need
hypertheading off :)