digitalmars.D - Does DMD unroll loops?
- Jascha Wetzel (15/15) Mar 10 2007 is there a way to make DMD unroll loops?
- Walter Bright (2/3) Mar 12 2007 Sorry, no.
- Daniel Keep (9/53) Mar 13 2007 Note: not tested, but you should be able to do something like the
- Jascha Wetzel (2/59) Mar 13 2007
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]; } }
Mar 10 2007
Jascha Wetzel wrote:is there a way to make DMD unroll loops?Sorry, no.
Mar 12 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/
Mar 13 2007
ah, that's nice (and works) Daniel Keep wrote: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
Mar 13 2007