I started to write a little tutorial to optimize things for the gp32, and I've got something about divisions that might be useful I hope...
Here it is:
Here it is:
Optimizing code for GP32 handheld
1) - Divisions
As you must already know, the ARM 9 hasn't got the divide operation.
Which means that if you use the / operation, the compiler will convert
it into some c code that will do the operation. But this is very slow.
a) Bitwise shifts
Bitwize shift operation (<< and >>) just decays the bits of the given value
either left (<<) or right (>>). Shifting right a value of one bit (x >> 1)
will divide the value by 2. (x >> 2) will divide by 4, etc...
Just be careful to only divide a positive value with this.
Be careful also, the >> operation has the lowest priority, so always enclose it with ().
B) Fixed operand divison
If you have to divide a value by a fixed operand, (w / 24) for example,
you can also use the bitwise shift, which is much more useful than only
dividing by powers of 2.
To do that, you have to use your calculator before, and be careful also
for a few things.
The trick is that we will multiply the value by a constant first, and then
divide by another constant that will be a power of 2.
ex: (213 / 24) = (213 x constant) / 65536
I often choose 65536 as it gives good precision, and leaves some good margin.
Just calculate your constant (here 65536 / 24), which gives ~ 2731
The your code would be:
result = ( (w * 2731) >> 16);
213 / 24 would give 8, and result would also contain 8.
Be careful:
-The value you will divide should be positive, but also should fit into an
integer when multiplied by the constant (which limits precision sometimes...).
-The constant should always be rounded to the upper value (2105.12 would give 2106).
c) Divison with a common operand
When you will have to do many divisions with the same value (which is variable),
you can use the same trick, by storing the constant into a global variable.
ex: (witdh / zoom) => when the same zoom value will be used for the whole display
constant = 65536 / zoom;
Then to divide by zoom:
w = ( (width * constant) >> 16);