当前位置:天才代写 > tutorial > C语言/C++ 教程 > Vdsp(bf561)中的浮点运算(16):fract2x16范例

Vdsp(bf561)中的浮点运算(16):fract2x16范例

2017-11-05 08:00 星期日 所属: C语言/C++ 教程 浏览:703

副标题#e#

由于BF561内部带有两个16位的MAC,因此它将可以在一个周期内举办两个fract16范例的运算。

Vdsp(bf561)中的浮点运算(16):fract2x16典型

为适应这种特性,vdsp引入了一个称之为fract2x16的范例。它其实是界说为一个int范例的整数,可是其实际意义却是要用坎坷16位别离来暗示两个fract16范例。

typedef int   _raw32;
typedef _raw32     raw2x16;
typedef raw2x16   fract2x16;

要查察fract2x16范例的值照旧只能通过data register窗口,手动将范例改为fract16,这样在寄存器的高16位和低16位就能别离瞥见这两个值了。

利用compose_fr2x16函数可以结构一个fr2x16数据:

The notation used to represent two fract16 values packed into a fract2x16 is {a,b}, where “a” is the fract16 packed into the high half, and “b” is the fract16 packed into the low half.

fract2x16 compose_fr2x16(fract16 f1, fract16 f2)

Takes two fract16 values, and returns a fract2x16 value.

直接看看它在头文件的界说:

/* Takes two fract16 values, and returns a fract2x16 value.
* Input: two fract16 values
* Returns: {_x,_y} */
#pragma inline
#pragma always_inline
static fract2x16 compose_fr2x16(fract16 _x, fract16 _y) {
return compose_2x16(_x,_y);
}
/* Composes a packed integer from two short inputs.
*/

#pragma inline
#pragma always_inline
static int  compose_2x16(short  __a, short  __b) {
int  __rval = __builtin_compose_2x16(__a, __b);
return __rval;
}


#p#副标题#e#

所以咱直接利用__builtin_compose_2x16得了。

result = __builtin_compose_2x16(0x7fff, 0x8000);

这行语句生成汇编就成了:

R0 = -32768 /* 2147450880 */;
R0.H = 32767 /* 2147450880 */;
[FP + 16] = R0;

从中可以很清楚看出组合的进程。

要从fr2x16获得高半部门可以用这个挪用:

/* Takes a fract2x16 and returns the 'high half' fract16.
* Input: _x{a,b}
* Returns: a.
*/

#pragma inline
#pragma always_inline
static fract16 high_of_fr2x16(fract2x16 _x) {
return high_of_2x16(_x);
}
#pragma inline
#pragma always_inline
static  _raw16 high_of_2x16(raw2x16 _x) {
return __builtin_extract_hi(_x);
}

取低半部门可以用下面的函数:

/* Takes a fract2x16 and returns the 'low half' fract16
* Input: _x{a,b}
* Returns: b
*/

#pragma inline
#pragma always_inline
static fract16 low_of_fr2x16(fract2x16 _x) {
return low_of_2x16(_x);
}
#pragma inline
#pragma always_inline
static  _raw16 low_of_2x16(raw2x16 _x) {
return __builtin_extract_lo(_x);
}

 

    关键字:

天才代写-代写联系方式