digitalmars.D.learn - Unrolling loops
- Simen Kjaeraas (3/3) Mar 10 2008 Is it possible to unroll loops in D2.0? I have a templated struct with a...
- Jarrett Billingsley (11/19) Mar 10 2008 In the presentation Walter and Andrei gave at the D con last year, they
- BCS (2/27) Mar 10 2008 you can do it with tuple a foreach, but it's not very clean
- Robert Fraser (5/10) Mar 10 2008 If the compiler knows it to be 4 elements at the code generation stage
- downs (6/11) Mar 10 2008 Use a union :)
- Bill Baxter (4/9) Mar 10 2008 Also I believe GDC can do automatic loop unrolling. At least it happily...
Is it possible to unroll loops in D2.0? I have a templated struct with a static array with length set through a template parameter. Does that get automatically unrolled with 4 elements (I doubt it), do I have to use some magic string mixin, or could I fix this with tuples and their automatic loop unrolling? Actually, that latter one is worth a question of its own. Can I convert a static array into a tuplem and if so, how? -- Simen
Mar 10 2008
"Simen Kjaeraas" <simen.kjaras gmail.com> wrote in message news:fr4ec8$kd3$1 digitalmars.com...Is it possible to unroll loops in D2.0? I have a templated struct with a static array with length set through a template parameter. Does that get automatically unrolled with 4 elements (I doubt it), do I have to use some magic string mixin, or could I fix this with tuples and their automatic loop unrolling? Actually, that latter one is worth a question of its own. Can I convert a static array into a tuplem and if so, how? -- SimenIn the presentation Walter and Andrei gave at the D con last year, they presented a "static loop" feature that would unroll the loop at compile time. static foreach(blah; something) { //... } So it's "in the works" for D2, I guess, but who knows when it'll actually be implemented.
Mar 10 2008
Reply to Jarrett,"Simen Kjaeraas" <simen.kjaras gmail.com> wrote in message news:fr4ec8$kd3$1 digitalmars.com...you can do it with tuple a foreach, but it's not very cleanIs it possible to unroll loops in D2.0? I have a templated struct with a static array with length set through a template parameter. Does that get automatically unrolled with 4 elements (I doubt it), do I have to use some magic string mixin, or could I fix this with tuples and their automatic loop unrolling? Actually, that latter one is worth a question of its own. Can I convert a static array into a tuplem and if so, how? -- SimenIn the presentation Walter and Andrei gave at the D con last year, they presented a "static loop" feature that would unroll the loop at compile time. static foreach(blah; something) { //... } So it's "in the works" for D2, I guess, but who knows when it'll actually be implemented.
Mar 10 2008
Simen Kjaeraas wrote:Is it possible to unroll loops in D2.0? I have a templated struct with a static array with length set through a template parameter. Does that get automatically unrolled with 4 elements (I doubt it), do I have to use some magic string mixin, or could I fix this with tuples and their automatic loop unrolling? Actually, that latter one is worth a question of its own. Can I convert a static array into a tuplem and if so, how? -- SimenIf the compiler knows it to be 4 elements at the code generation stage (which it will if it's a static array - template resolution is done in the semantic pass, so it doesn't matter if it's from a template or coded directly in), it should probably unroll it. Check the assembly.
Mar 10 2008
Simen Kjaeraas wrote:Is it possible to unroll loops in D2.0? I have a templated struct with a static array with length set through a template parameter. Does that get automatically unrolled with 4 elements (I doubt it), do I have to use some magic string mixin, or could I fix this with tuples and their automatic loop unrolling? Actually, that latter one is worth a question of its own. Can I convert a static array into a tuplem and if so, how?Use a union :) union TupleAndStaticArrayTest { uint[4] whee; Repeat!(uint, 4) whoo; }-- Simen
Mar 10 2008
Simen Kjaeraas wrote:Is it possible to unroll loops in D2.0? I have a templated struct with a static array with length set through a template parameter. Does that get automatically unrolled with 4 elements (I doubt it), do I have to use some magic string mixin, or could I fix this with tuples and their automatic loop unrolling? Actually, that latter one is worth a question of its own. Can I convert a static array into a tuplem and if so, how? -- SimenAlso I believe GDC can do automatic loop unrolling. At least it happily accepts the flag "-funroll-loops". --bb
Mar 10 2008