Welcome

首页 / 软件开发 / C++ / Vdsp(bf561)中的浮点运算(13):fract16乘法运算

Vdsp(bf561)中的浮点运算(13):fract16乘法运算2010-02-01 csdn博客 快乐虾vdsp提供了三种不同的方式进行fract16的乘法运算。

1.1 mult_fr1x16函数

这个函数定义为:

#pragma inline
#pragma always_inline
static fract16 mult_fr1x16(fract16 __a, fract16 __b) {
fract16 __rval = __builtin_mult_fr1x16(__a, __b);
return __rval;
}

从这里可以看出我们实际可以使用__builtin_mult_fr1x16这一函数调用。

写一个很简单的程序:

typedef fract16 ft;

ft calc(ft x, ft y)
{
ft r;
r = __builtin_mult_fr1x16(x, y);
return r;
}

__builtin_mult_fr1x16展开后的汇编代码为:

// line 29
R0.L = R0.L * R1.L (T);
R0 = R0.L (X);
W[FP + 16] = R0;

因而完成这样一个运算将只需要一个cycle的时间。

这里的乘法运算使用了(T)尾缀,文档里这样解释:

Signed fraction with truncation. Truncate Accumulator 9.31 format value at bit 16. (Perform no rounding.) Saturate the result to 1.15 precision in destination register half. Result is between minimum -1 and maximum 1-2-15 (or, expressed in hex, between minimum 0x8000 and maximum 0x7FFF).

这种计算方式直接将累加器里的数进行截断而不进行任何舍入的处理。

1.2 multr_fr1x16

这个函数定义为:

/* Performs a 16-bit fractional multiplication of the two input
** parameters. The result is rounded to 16 bits. Whether the
** rounding is biased or unbiased depends what the RND_MOD bit
** in the ASTAT register is set to.
*/

#pragma inline
#pragma always_inline
static fract16 multr_fr1x16(fract16 __a, fract16 __b) {
fract16 __rval = __builtin_multr_fr1x16(__a, __b);
return __rval;
}