Speed of dividing operation

- Many micros use a series of subtraction operations to divide. If this is the case on the ST7, decreasing the size of the denominator would lead to more subtractions and hence longer execution times.

Another common implementation is to right-shift (divide by two) repeatedly and then use the method above on a common factor of the denominator. Here a smaller denominator is not as important as one which easily multiplies with a power of two (eg 2, 4, 8, 16, 32 etc.).

I would try both to see which leads to shorter execution times.

are you using C or ASM? What kind of numbers are you trying to divide (char, int, float)?

Generally speaking:

- division is not hardware assisted on st7, therefore it will always be slow

- division should be avoided in ISR; take special care if you are using the Cosmic compiler (need to save extra registers in some cases)

- you can easily simulate whatever division routine you are using and get the numbers you are looking for.

Hope it hels.

Regards,

Luca (Cosmic)Quote: What do u mean telling "take special care if you are using the Cosmic compiler (need to save extra registers in some cases)" ?

When you use 32 bit math (long, float) in interrupt routines you need to specify @svlreg, see a quote from the manual belowQuote:

The c_lreg area is not saved implicitely in such a case, in order to keep the interrupt function as efficient as possible. If any function called by the interrupt function uses longs or floats, the c_lreg area can be saved by using the type qualifier @svlreg on the interrupt function definition.

About your table: the numbers give a pretty good idea about the average time you can expect, but, if you need to calculate the worst possible case (which is often the most interesting info for an interrupt routine), you need either to test all possible cases or to understand the division algorithm (the source is in your compiler installation, but it's not trivial) and deduce what values for a32, b16, and c32 (reference to you table) would cause the slowest calculation. I'll try to ask the person who wrote the algorithm and then let you know.

Regards,

Luca

I would like to know speed of dividing. Is there any tables that show speeds of different operations.

Now i'm optimizing ISRs, where dividing exists. Whether it helps, if i decrease denominator (not size, but value)?