Vdsp(bf561)中的浮点运算(13):fract16乘法运算

快乐虾

http://blog.csdn.net/lights_joy/

[email protected]

本文适用于

ADSP-BF561

Visual DSP++ 5.0 (update 6)

Vdsp dual processor simulate

欢迎转载,但请保留作者信息

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;

}

它实际使用__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的格式,而不是fract161.15格式,难怪在文档里面没有记载,嘿嘿。

2 参考资料

Vdsp(bf561)中的浮点运算(12):fract16加减运算(2009-8-17)

Vdsp(bf561)中的浮点运算(11):fract16float的转换(2009-8-17)

Vdsp(bf561)中的浮点运算(10):fract16类型表示(2009-8-17)

Vdsp(bf561)中的浮点运算(9):long doublefloat的比较(2009-8-14)

Vdsp(bf561)中的浮点运算(8):float除法运算(2009-8-14)

Vdsp(bf561)中的浮点运算(7):float乘法运算(2009-8-13)

Vdsp(bf561)中的浮点运算(6):float加减运算(2009-8-13)

Vdsp(bf561)中的浮点运算(5):float类型表示总结(2009-8-12)

Vdsp(bf561)中的浮点运算(4):FLT_MAX(2009-8-12)

Vdsp(bf561)中的浮点运算(3):FLT_MIN(2008-12-19)

Vdsp(bf561)中的浮点运算(2):float的疑问(2008-12-18)

Vdsp(bf561)中的浮点运算(1):文档的说法(2008-12-16)

你可能感兴趣的:(.net,Blog,FP)