2005-09-16 03:19 AM
2005-09-15 01:50 AM
Hi All.
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)?2005-09-15 02:34 AM
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.2005-09-15 04:29 AM
2005-09-15 08:53 PM
I am using Cosmis C compiler. i divide 16 and 32 bit int numbers. i know--it is terrible, but now i can not see another solution. now i am about testing speed of division by myself. i will post results.
2005-09-15 08:55 PM
To _luca:
What do u mean telling ''take special care if you are using the Cosmic compiler (need to save extra registers in some cases)'' ?2005-09-15 10:27 PM
See results in the attachment.
Сonclusion: as smaller numerator and as bigger denominator as faster division for same size of operands. ________________ Attachments : div_speed.xls : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I09y&d=%2Fa%2F0X0000000bUY%2FuzKp3Jt0ukUTmUypkExJeLkSrWbOwTcwuONgl1f4hR4&asPdf=false2005-09-16 02:52 AM
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, Luca2005-09-16 03:19 AM
Tnx for information.
As for my case i had 2 ways : - use big value of denominator - split denominator on 2 parts: smaller denominator( for division) and some power of 2 (for right shift). After my investigation i decided to take one big denominator. Am i right? Waiting for a news...