DSPRelated.com
Forums

Usage of ldiv16

Started by rahul_mot February 11, 2009
Hello all,

I am implementing a division operation between two Q31 numbers as follows.
x -> Q31 number
y -> Q31 number
I need output of (x/y) division operation in Q31 format.

Here is the C code I wrote and it uses ldiv16 C55x DSPlib function to
implement the division.

main()
{
....

long int x, y, Out;
short OutR, OutEXP;

tempY = y >> 16;
ldiv16(&x, &tempY, &OutR, &OutEXP, 1);
Out = (long) (OutR * OutEXP);

.....
}
Can anyone please tell me if I am doing the right way or not?
Thank you all in advance,
Rahul
Rahul-

> I am implementing a division operation between two Q31 numbers as follows.
> x -> Q31 number
> y -> Q31 number
> I need output of (x/y) division operation in Q31 format.
>
> Here is the C code I wrote and it uses ldiv16 C55x DSPlib function to
> implement the division.
>
> main()
> {
> ....
>
> long int x, y, Out;
> short OutR, OutEXP;
>
> tempY = y >> 16;
> ldiv16(&x, &tempY, &OutR, &OutEXP, 1);
> Out = (long) (OutR * OutEXP);
>
> .....
> }
>
> Can anyone please tell me if I am doing the right way or not?

Why not just use the C compiler? I think the function is called ldiv, so something
like this:

long int a, b:
ldiv_t c;

c = ldiv(a, b);

The code gen tools are going to call a routine in rts55.lib that is fairly fast. If
that's not fast enough, then you could get the div.c code out of rts.src (source used
for rts55.lib) and hand-optimize in asm language.

But at this point, from the level of questions you're asking, it seems to me that you
should stick with "tried and true" methods and make sure your results are correct.
Then later worry about optimized operation.

-Jeff
--- In c..., Jeff Brower wrote:
>
> Rahul-
>
> > I am implementing a division operation between two Q31 numbers as
follows.
> > x -> Q31 number
> > y -> Q31 number
> > I need output of (x/y) division operation in Q31 format.
> >
> > Here is the C code I wrote and it uses ldiv16 C55x DSPlib function to
> > implement the division.
> >
> > main()
> > {
> > ....
> >
> > long int x, y, Out;
> > short OutR, OutEXP;
> >
> > tempY = y >> 16;
> > ldiv16(&x, &tempY, &OutR, &OutEXP, 1);
> > Out = (long) (OutR * OutEXP);
> >
> > .....
> > }
> >
> > Can anyone please tell me if I am doing the right way or not?
>
> Why not just use the C compiler? I think the function is called
ldiv, so something
> like this:
>
> long int a, b:
> ldiv_t c;
>
> c = ldiv(a, b);
>
> The code gen tools are going to call a routine in rts55.lib that is
fairly fast. If
> that's not fast enough, then you could get the div.c code out of
rts.src (source used
> for rts55.lib) and hand-optimize in asm language.
>
> But at this point, from the level of questions you're asking, it
seems to me that you
> should stick with "tried and true" methods and make sure your
results are correct.
> Then later worry about optimized operation.
>
> -Jeff
>

Hi Jeff,

Thanks a lot for the information. I found ldiv() function in rts55.lib
as you said. And you are correct that I am not worried about
optimization right now. I am just trying to get correct results first.

Thanks,
Rahul