Forum : ST7/STM8
Post Information | Post |
---|---|
June 21, 2010 - 9:07am
|
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? 3) I have a problem about page0 keyword. The code is like below: for(a=0; a<3; i++) 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. What is the cause of this unsuccessful multiplication? Thanks! |
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