副标题#e#
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;
}
#p#副标题#e#
它实际利用__builtin_multr_fr1x16完成计较,展开后的汇编代码就是:
// line 29
R0.L = R0.L * R1.L ;
R0 = R0.L (X);
W[FP + 16] = R0;
它不利用尾缀举办乘法计较,关于这种计较方法,文档这样描写:
Signed fraction. Multiply 1.15 * 1.15 to produce 1.31 results after left-shift correction. Round 1.31 format value at bit 16. (RND_MOD bit in the ASTAT register controls the 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).
也就是说它将对功效举办舍入操纵,虽然和截断对比,它们之间的差值最大也就是2-15。
1.3 multu_fr1x16
这个函数在文档内里没有记实,其界说为:
/* 16-bit unsigned fractional multiplication using the FU option
*/
#pragma inline
#pragma always_inline
static fract16 multu_fr1x16(fract16 __a, fract16 __b) {
fract16 __rval = __builtin_multu_fr1x16(__a, __b);
return __rval;
}
展开__builtin_multu_fr1x16的汇编代码为:
// line 29
R0.L = R0.L * R1.L (FU);
R0 = R0.L (X);
W[FP + 16] = R0;
它利用了FU尾缀举办乘法运算,文档这样描写:
Unsigned fraction. Multiply 0.16 * 0.16 to produce 0.32 results. No shift correction. Round 0.32 format value at bit 16. (RND_MOD bit in the ASTAT register controls the rounding.) Saturate the result to 0.16 precision in destination register half. Result is between minimum 0 and maximum 1-2-16 (or, expressed in hex, between minimum 0x0000 and maximum 0xFFFF).
它回收的是0.16的名目,而不是fract16的1.15名目,难怪在文档内里没有记实,嘿嘿。