Vdsp(bf561)中的浮点运算(14):fract16除法2010-02-01 csdn博客 快乐虾原来指望能够有div_fr1x16之类的函数来实现fract16的除法,但是很遗憾vdsp居然不直接提供这样的函数,让人颇为尴尬,估计是因为其CPU不直接提供fract除法的缘故。不过vdsp文档里面提供了一个做除法的例子:fract16 saturating_fract_divide(fract16 nom, fract16 denom) { int partialres = (int)nom; int divisor = (int)denom; fract16 rtn; int i; int aq; /* initial value irrelevant */
if (partialres == 0) { /* 0/anything gives 0 */ rtn = 0; } else if (partialres >= divisor) { /* fract16 values have the range -1.0 <= x < +1.0, */ /* so our result cannot be as high as 1.0. */ /* Therefore, for x/y, if x is larger than y, */ /* saturate the result to positive maximum. */ rtn = 0x7fff; } else { /* nom is a 16-bit fractional value, so move */ /* the 16 bits to the top of partialres. */ /* (promote fract16 to fract32) */ partialres <<= 16;
/* initialize sign bit and AQ, via divs(). */ partialres = divs(partialres, divisor, &aq);
/* Update each of the value bits of the partial result */ /* and reset AQ via divq(). */ for (i=0; i<15; i++) { partialres = divq(partialres, divisor, &aq); }