老师让我简单解释一下下面这个程序里的test1子程序的用途,我看了半天,感觉好诡异,而且好多不明白的语句。
哪位大侠能帮我看一下啊?
#define xtensa 1
/* Compiler extensions */
#ifdef XTENSA_DEBUG
/* debug version */
#include
#include
#include
#include "iostream.h"
#include "stdafx.h"
#define xtensaError(str)
{
printf((str));
printf("\n");
exit(-1);
}
#define xtensaWarn(str)
{
printf((str));
printf("\n");
}
#define xtensaIgnore(a) ((void)a)
#define xtensaAssert(a) assert(a)
#else
/* release version */
#define xtensaError(str) ((void) (str))
#define xtensaWarn(str) ((void) (str))
#define xtensaIgnore(a) ((void) (a))
#define xtensaAssert(a) ((void) (a))
#endif /* XTENSA_DEBUG */
/** OMX_U32 is a 32 bit unsigned quantity that is 32 bit word aligned */
typedef unsigned long OMX_U32;
/** OMX_U8 is an 8 bit unsigned quantity that is byte aligned */
typedef char OMX_U8;
typedef int OMX_INT;
/** signed integer corresponding to machine word length, has maximum signed value INT_MAX*/
OMX_U32 test1(const OMX_U8 **ppBitStream, OMX_INT *pOffset, OMX_INT N)
{
const OMX_U8 *pBitStream = *ppBitStream;
OMX_INT Offset = *pOffset;
OMX_U32 Value;
xtensaAssert(Offset>=0 && Offset<=7); /* 这两句我不明白,看样子好像是如果Offset和N不符合条件程序终止,但是我单独调试这两句的时候根本不管用。*/
xtensaAssert(N>=1 && N<=32);
/* Read next 32 bits from stream */
Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16) | (pBitStream[2] << 8 ) | (pBitStream[3]) ; /* 还有这儿,为什么要把一个字符向左移位?pBitStream[]这个时候应该是数字,对应ASCII码表的字母,这样移位有什么意义吗?*/
Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));
/* Return N bits */
return Value >> (32-N);
}
/***************************************
* Simulation Parameters
***************************************/
#ifdef x86
#define LOOPS 100000000;
#elif xtensa
#define LOOPS 1000;
#else
#define LOOPS = 1000;
#endif
int main(){
const OMX_U8 *d = "This is a test bitstream";
OMX_INT pOffset = 12;
OMX_INT num_bits = 11;
OMX_U32 value = 0;
int loops = LOOPS;
int i = 0;
for (i =0;i {
value = test1(&d,&pOffset,num_bits);
}
cout<<"Loopcount: "< printf("value:0x%x\n", value);
return 0;
}
--------------------next---------------------
阅读(1099) | 评论(0) | 转发(0) |