Forums

implementing division on tms-dsp-processors

Started by rambiz October 5, 2008
hi all,
i wrote a C programm in code composer studio and used division of
float variables in it.
but the compiler seemed to be unable to translate the programm to
appropraite assembly, so that the processor
couldn't "understand" it. there were no errors in compiling or
building but the programm simply didn't work. was it because ti-dsp
can only perform multiplication and no division at all?!
how can i get around the problem, please?
thx in advance
rambiz wrote:
> hi all, > i wrote a C programm in code composer studio and used division of > float variables in it. > but the compiler seemed to be unable to translate the programm to > appropraite assembly, so that the processor > couldn't "understand" it. there were no errors in compiling or > building but the programm simply didn't work. was it because ti-dsp > can only perform multiplication and no division at all?! > how can i get around the problem, please? > thx in advance
Does your processor handle floating-point natively? If not, did you invoke the proper library? Jerry -- Engineering is the art of making what you want from things you can get. ����������������������������������������������������������������������� ** Posted from http://www.teranews.com **
"Jerry Avins" <jya@ieee.org> wrote in message 
news:5b412$48e980c9$2412@news.teranews.com...
> rambiz wrote: >> hi all, >> i wrote a C programm in code composer studio and used division of >> float variables in it. >> but the compiler seemed to be unable to translate the programm to >> appropraite assembly, so that the processor >> couldn't "understand" it. there were no errors in compiling or >> building but the programm simply didn't work. was it because ti-dsp >> can only perform multiplication and no division at all?! >> how can i get around the problem, please? >> thx in advance > > Does your processor handle floating-point natively? If not, did you invoke > the proper library?
Some TMS series DSPs implement floating point in hardware, but I don't think any of them have an operation for floating point division. Try simplifying the problem as much as possible, something like int i; float a[1]; for ( i = 0; i < 10; i++) { a[i] = 1.0f / (float)(i+1); } Turn on the highest levels of error checking for the compiler, assembler and linker. Look at the assembly code generated, and see what the compiler tries to do to implement division. Check if you intend to use floats or doubles... Best wishes, --Phil Martel
> > Jerry > -- > Engineering is the art of making what you want from things you can get. > &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095; > ** Posted from http://www.teranews.com **
hi again,
first of all i'd like for all the good sugestions you have made.
secondly i regret to tell you that i have made a mistake to report
that the programm
had been built! it couldn't be built at all! sorry guys!
meanwhile i have talked to some people who told me that division is
not supported by
TI's dsp-chips. not very sure about this point but somehow it seems to
be plausible since division is a somehow complicated process.
thank you all again
rambiz
rambiz wrote:
> hi again, > first of all i'd like for all the good sugestions you have made. > secondly i regret to tell you that i have made a mistake to report > that the programm > had been built! it couldn't be built at all! sorry guys! > meanwhile i have talked to some people who told me that division is > not supported by > TI's dsp-chips. not very sure about this point but somehow it seems to > be plausible since division is a somehow complicated process. > thank you all again
With proper programming, you can implement division on an 8-bit processor that has no multiply or divide hardware. Jerry -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;
rambiz <rambiz@gmail.com> writes:

> hi again, > first of all i'd like for all the good sugestions you have made. > secondly i regret to tell you that i have made a mistake to report > that the programm > had been built! it couldn't be built at all! sorry guys! > meanwhile i have talked to some people who told me that division is > not supported by > TI's dsp-chips. not very sure about this point but somehow it seems to > be plausible since division is a somehow complicated process. > thank you all again > rambiz
See rules for fixed-point division in http://www.digitalsignallabs.com/fp.pdf You can make the relevent data types and constants half as big if you only need a 16x16 divide. --RY #include <stdint.h> uint64_t Divide32(uint32_t y, uint32_t x) { uint16_t n; uint64_t answer; uint64_t remainder; uint64_t divisor; answer = 0; remainder = x; divisor = (uint64_t)y << 32; for (n = 0; n < 32; n++) { divisor = divisor >> 1; if (remainder >= divisor) { remainder -= divisor; answer |= (uint64_t)1 << (63 - n); } } for (n = 0; n < 32; n++) { remainder = remainder << 1; if (remainder >= divisor) { remainder -= divisor; answer |= (uint64_t)1 << (31 - n); } } return answer; -- % Randy Yates % "Watching all the days go by... %% Fuquay-Varina, NC % Who are you and who am I?" %%% 919-577-9882 % 'Mission (A World Record)', %%%% <yates@ieee.org> % *A New World Record*, ELO http://www.digitalsignallabs.com

rambiz wrote:

> hi again, > first of all i'd like for all the good sugestions you have made.
First of all RTFM.
> secondly i regret to tell you that i have made a mistake to report > that the programm > had been built! it couldn't be built at all! sorry guys! > meanwhile i have talked to some people who told me that division is > not supported by TI's dsp-chips.
Don't talk to some people, they won't teach you any good. JFYI: TI processors have the division primitive instruction.
> not very sure about this point but somehow it seems to > be plausible since division is a somehow complicated process.
Sure the division is very complicated, since they lean how to do it it in the 2nd grade of the elementary school. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
There are two common methods of implementing division in a fixed-point
DSP that doesn't have division instructions.
1) Using repeated substraction method (long division type). An example
is given in post by randy yates above. In most TI dsp's there is an
instruction "subc" (conditional subtraction) specifically meant for
this. Please check the manual.
2) The second method is to write a table-based inverse function (for
denominator) and use multiplication after inverting.

Depending on the context you can use either of the above.

Regards
Piyush

On Oct 6, 4:57&#2013266080;am, rambiz <ram...@gmail.com> wrote:
> hi all, > i wrote a C programm in code composer studio and used division of > float variables in it. > but the compiler seemed to be unable to translate the programm to > appropraite assembly, so that the processor > couldn't "understand" it. there were no errors in compiling or > building but the programm simply didn't work. was it because ti-dsp > can only perform multiplication and no division at all?! > how can i get around the problem, please? > thx in advance
Piyush Kaul wrote:
> There are two common methods of implementing division in a fixed-point > DSP that doesn't have division instructions. > 1) Using repeated substraction method (long division type). An example > is given in post by randy yates above. In most TI dsp's there is an > instruction "subc" (conditional subtraction) specifically meant for > this. Please check the manual. > 2) The second method is to write a table-based inverse function (for > denominator) and use multiplication after inverting. > > Depending on the context you can use either of the above.
"subc" is particularly useful with the shift-and-subtract algorithm of division. Simple successive subtraction os O(n), whereas long division is O(log(n)). On many processors, it is possible to shift the quotient into the same register that the divisor is shifted out of. Jerry -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;