Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

d-loop

D-loop : New method for optimizing loop

This topic is 5200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, http://www.onversity.com/load/d-loop.pdf If you have any questions, feel free to post them here .

Share this post


Link to post
Share on other sites
Advertisement
i''m interested in how this could work together with ... the while() { switch() {} } thing.. to optimize loops..

an interesting read, for sure. thanks for sharing.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
duff''s device, or something, it''s called




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
hy:D




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
yes, and for making it having less branches, too.

with help of duffs device, you can do something 8 times, then reloop if needed, and again, 8 times. you just have to jump into the right beginning, so that you, in the end, process all items you want.

that way, you have only 1/8th branch "per iteration".

of course, you can do this for 8, 16, or only 4 times.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
so lets "d-loopify" this function::::::


#include<math.h>
typedef unsigned long ulong;
inline bool isPrime(ulong n)
{
if ( (n % 2 == 0) || (n % 5 == 0))
return false;
ulong sqr = sqrt(n);
for (ulong x = 3; (x <= sqr); x +=2)
if(n % x == 0)
return false;
return true;
}

Share this post


Link to post
Share on other sites
quote:
Original post by davepermen
i''m interested in how this could work together with ... the while() { switch() {} } thing.. to optimize loops..

an interesting read, for sure. thanks for sharing.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net


hi,

As I wrote in the pdf, using d-loop is not always simple or a good idea. With switch condition (or nested if ...) I doubt in most cases you will gain in execution time, but you can make a d-loop version. It will looks like that :

while(x)
{
switch(n)
{
case a :
case b :
case ... :
}
}


become (something like that)

while(x)
{
while(a)
{
}
switch(n)
{
case b :
case ... :
}
}

Where a is the most executed condition



Share this post


Link to post
Share on other sites
quote:
Original post by vaneger
so lets "d-loopify" this function::::::


#include<math.h>
typedef unsigned long ulong;
inline bool isPrime(ulong n)
{
if ( (n % 2 == 0) || (n % 5 == 0))
return false;
ulong sqr = sqrt(n);
for (ulong x = 3; (x <= sqr); x +=2)
if(n % x == 0)
return false;
return true;
}



hi,

D-loop is usefull when the inner loop is the bottleneck. in your case, the bottleneck is the modulo function. A second point is that d-loop works when a sequential read of a table occur, there is no sequential read because there is no table.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!