Reply by sotn...@scideco.ru April 29, 20102010-04-29
It seems that this is the only choice of a function for fractional numbers division. It is based on the two assembly division privitives, divs and divq, which have some limitations. As far as I know, one of the limitations is that the divisor must be positive otherwise the division produces erroneous results.
I'm not well acquainted with fractional division in Blackfin and can't spare much time on checking it by myself cause i have a lot of work these days, so all i can do is to give you some hints.

The code of div_s function is available in . Here it is:

static fract16 div_s(fract16 _a, fract16 _b) {
int x = (int)_a;
int y = (int)_b;
fract16 rtn;
int i;
int aq;
if (x==0) {
rtn = 0;
}
else if (x>=y) {
rtn = 0x7fff;
}
else {
x <<= 16;
x = divs(x, y, &aq);
for (i=0; i<15; i++) {
x = divq(x, y, &aq);
}
rtn = (fract16) x;
}
return rtn;
}

It doesn't check the sign of operands. The strange thing in your description of the problem is that the function returns zero for negative variables. I thought it had to give non-zero erroneous values. However I might be wrong. You can modify the function or write your own assembly code following the guidelines from the section of Blackfin Programming Reference Manual, which describes division primitives.

--
Alexander
>I need to divide fract16 in my LMS algorithm and I use the div_s function in the ADSP-BF533 EZ-KIT Lite, but I have a problem: if the numbers are negative, the result of the division is 0.
>
>There is another function to divide fract16? I have thought to use the abs function and then add the negative sign to the numbers, but I think it has to be another easier solution.
>
>Thank you in advance.
Reply by lica...@hotmail.com April 28, 20102010-04-28
Hello everybody,

I need to divide fract16 in my LMS algorithm and I use the div_s function in the ADSP-BF533 EZ-KIT Lite, but I have a problem: if the numbers are negative, the result of the division is 0.

There is another function to divide fract16? I have thought to use the abs function and then add the negative sign to the numbers, but I think it has to be another easier solution.

Thank you in advance.