Does DMD unroll loops?
Daniel Keep
daniel.keep.lists at gmail.com
Tue Mar 13 02:11:34 PDT 2007
Jascha Wetzel wrote:
> is there a way to make DMD unroll loops?
> i can use mixins instead, but it's ugly...
>
> struct Vec(T,int dim)
> {
> alias Vec!(T,dim) vec_t;
>
> T[dim] data;
>
> void opAddAssign(vec_t v)
> {
> foreach ( int i, inout d; data )
> d += v.data[i];
> // alternatively:
> // for ( int i = 0; i < dim; ++i )
> // data[i] += v.data[i];
> }
> }
> template Tuple(T...)
> {
> alias T Tuple;
> }
>
> template Range(int n)
> {
> static if( n < 1 )
> alias Tuple!() Range;
> else
> alias Tuple!(Range!(n-1), n) Range;
> }
>
> struct Vec(T,int dim)
> {
> alias Vec!(T,dim) vec_t;
>
> T[dim] data;
>
> void opAddAssign(vec_t v)
> {
> // foreach ( int i, inout d; data )
> // d += v.data[i];
> // alternatively:
> // for ( int i = 0; i < dim; ++i )
> // data[i] += v.data[i];
> foreach( i ; Range!(dim) )
> data[i] += v.data[i];
> }
> }
Note: not tested, but you should be able to do something like the
above... :P
-- Daniel
--
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d
mailing list