Silly Question On Performance

Started by
15 comments, last by Spoonbender 18 years, 1 month ago
Quote:Original post by blaze02
Quote:Original post by ProphecyEye
You could possibly do some parallel processing with a single CPU that supports sse2:

http://www.gamedev.net/reference/articles/article1987.asp

Also, if you don't need the precision, I would use floats instead of doubles. Doing so can allow you to do 4 floating point operations at once. It's also just less data to move around not to mention 32bit cpus generally like 32bit vars.


It would be less data to move around, but 32 bit cpus don't execute anything with floats. They let the FPU handle that. And the FPU converts both 32bit and 64bit floats to 80bit floats before calculating anything. And what are you talking about (floats) would allow 4 floating point operations at once? I don't think the FPU knows how to do that.


I heard this a year ago and thought that the performance difference between floats and doubles would be almost non-existant because of this After seeing some benchmarks between floats and doubles my friend did with one of his projects though, I was shocked to find a huge difference. I don't know my x86 cpus well enough to know why there is such a big difference, I only know that there is one and it's well worth taking advantage of if possible.

If I were to guess though I would imagine it partly has to do with moving half the data around to/from memory and partly to do with compilers getting smart enough to generate SSE instructions for float calculations.
Advertisement
Don't discount "less data to move around". Especially with big datasets. Getting something from memory is really slow compared to doing pretty much anything once you have it at the processor. And for really big datasets, paging is really really really slow compared to processors. You can chew a lot of floats in the time it takes to take care of one page fault.
-Mike
Thanks for all the replies. I'll start looking into your suggestions this morning.
How much is MAX exactly? I certainly hope it's not > 2); xy = xy + 4)
{
array_result[xy + 0] = 0.5 * (array_1[xy + 0] + array_2[xy + 0]);
array_result[xy + 1] = 0.5 * (array_1[xy + 1] + array_2[xy + 1]);
array_result[xy + 2] = 0.5 * (array_1[xy + 2] + array_2[xy + 2]);
array_result[xy + 3] = 0.5 * (array_1[xy + 3] + array_2[xy + 3]);
}
// remainder, might not be needed
for (xy = 0; xy <
How much is MAX exactly? I certainly hope it's not under 32.

As for the loop itself, there's few things you can do.

First is looking into L1 data cache organization on the processor you're using. It may get you quite some performance increase, if you're using a single input, single output array, or even a single array for all the data.

Second, loop unroling. Some compilers may do this by themself, others might not. The for loop contains an if statement on every iteration. That can mess with pipeline, so this is almost always faster. Actual size of unrolled loop depends on available cache space.

for(xy = 0; xy < (4 * MAX); xy = xy + 4){  array_result[xy + 0] = 0.5 * (array_1[xy + 0] + array_2[xy + 0]);  array_result[xy + 1] = 0.5 * (array_1[xy + 1] + array_2[xy + 1]);  array_result[xy + 2] = 0.5 * (array_1[xy + 2] + array_2[xy + 2]);  array_result[xy + 3] = 0.5 * (array_1[xy + 3] + array_2[xy + 3]);}// remainder, might not be neededfor (xy = 0; xy < (MAX - (MAX && 0x3)); xy++) {  array_result[xy] = 0.5 * (array_1[xy] + array_2[xy]);}


Third, is converting the above either partially or fully into assembly, using one of the vector extensions.

Last, although perhaps it should be first, is what are you trying to acomplish in the first place. Do you really need to calculate the data like this, or could this all be processed while populating the arrays in the first place? How often is the code called? How many elements? Is it really a bottleneck?

Unless MAX is well over 1M, and you need to process this several times per second, performance of this loop shouldn't be the issue, and if it is, you'll need to aproach the problem differently.
Original post by Anonymous Poster
for(xy = 0; xy < (4 * MAX); xy = xy + 4)for (xy = 0; xy < (MAX - (MAX && 0x3)); xy++) {}


Both of your loops iterate wrongly. The first one goes 4 times too high, the second one starts from 0, uses logical AND etc..
Another thing you could try would be to always perform the multiplication on the data from the previous iteration. I'm not sure how much (if anything) you'd gain from it, but it would remove some dependencies from the loop body (the multiplication would no longer depend on the addition performed in the same iteration)

This topic is closed to new replies.

Advertisement