Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 10, 2007 Does DMD unroll loops? | ||||
---|---|---|---|---|
| ||||
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]; } } |
March 13, 2007 Re: Does DMD unroll loops? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jascha Wetzel | Jascha Wetzel wrote:
> is there a way to make DMD unroll loops?
Sorry, no.
|
March 13, 2007 Re: Does DMD unroll loops? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jascha Wetzel | 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/ |
March 13, 2007 Re: Does DMD unroll loops? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Keep | 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
>
|
Copyright © 1999-2021 by the D Language Foundation