Compile time loop unrolling

Daniel Keep daniel.keep.lists at gmail.com
Wed Aug 29 03:17:51 PDT 2007


I've done loop unrolling in a few places using Tuples and foreach.

template Tuple(T...) { alias T Tuple; }

template Range(uint n)
{
    static if( n == 0 )
        alias Tuple!() Range;
    else
        alias Tuple!(Range!(n-1), n-1) Range;
}

void copy_four(int[] src, int[] dst)
{
    foreach( i,_ ; Range!(4) )
        src[i] = dst[i];
}


Which *should* unroll the loop.  Note that I haven't checked the
assembly to make sure of this, but since it works when you have tuples
inside the loop, I'd assume that it would have to :)

	-- Daniel



More information about the Digitalmars-d mailing list