D-loop : New method for optimizing loop

Started by
24 comments, last by d-loop 20 years ago
Hi, http://www.onversity.com/load/d-loop.pdf If you have any questions, feel free to post them here .
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
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

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

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
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

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

nice article indeed.
hi dave :D
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
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

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

duff''s device is for unrolling loops.

http://www.lysator.liu.se/c/duffs-device.html
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
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

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

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;}
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



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.

This topic is closed to new replies.

Advertisement