Topic : Dividing speed and page0 problems

Forum : ST7/STM8

Original Post
Post Information Post
June 21, 2010 - 9:07am
Guest

Hi,

I have some questions about the compiler:

1) I want to divide a variable to 2000 as fast as the STM8S microcontroller can. Is there a difference between the statements below in terms of speed?
x = y / 2000;
// and
x = (y >> 4) / 125; // (y >> 4) is equal to (y / 16)
2) Is there a difference in terms of speed between dividing a variable to a small number or to a big number of same type? For example:
a = b / 1000; //1000 is short
// and
a = b / 2000; //2000 is also short

3) I have a problem about page0 keyword. The code is like below:

static page0 signed int VariablesArray[3];
static page0 signed long SumOfSquaresArray[3];
...
...

for(a=0; a<3; i++)
{
SumOfSquaresArray[a] += (long) VariablesArray[a] * VariablesArray[a];
}

If a define SumOfSquaresArray in page0 like above, I see that the multiplication process does not execute. But if I remove the page0 keyword from the definition of SumOfSquaresArray, the multiplication executes successfully.
Instead of using SumOfSquaresArray, I used 3 different page0 variables and I saw that multiplication executed successfully.
If I use a page0 pointer instead of using SumOfSquaresArray, I see the same error.

What is the cause of this unsuccessful multiplication?
And I also want to learn whether I can define a pointer in page0 or not?

Thanks!

Replies
Post Information Post
+1
0
-1
June 21, 2010 - 2:50pm
Raisonance Support Team

Hi Volkan,

Difficult to answer your question as I do not have the type of your x and y variables.

1) Anyway in SPEED optimization mode the generated code will be the same, so you do not have to bother. If you are using "short" variables then the 16/16 division is free with the STM8.

2) There is NO difference. In SPEED mode, the compiler will perform all possible shift operations before performing the actual division, so dividing by 1000 or by 2000 is the same division (plus an extra shift for 2000).

Besides from these remarks, if you divide by a constant (such as 1000) you can find some very efficient algorithms, look at Hacker's delight for instance. Using such algorithms will speedup your code a lot, so I suggest that you eperiment a bit with these.

3) This looks like a side effect, possibly due to the static/page0 combination. Unfortunately we have not been able to reproduce this behavior in our labs.

Can you describe better what you mean by "the multiplication process does not execute"?

Also if you can send a project that shows the problem that would be great for reproduction here. If not possible, can you at least share the compiler listing that shows the failure ?

Regards,
Bruno