TI C64x可以有两种(我现在知道的,不排除有第三种)方法来得到程序的运行cycle,一个是Enable clock后调用用clock()(这个在VC下是得到以ms为单位的时间,这里得到的是cycle),另一个就是CSL(Chip Support Library)提供的timer。
下面给出两种方法的程序段
/**************************************************************/
/* */
/* Auth:wb0330 */
/* Dest: used to measure cycle counts for TI C64x DSP */
/* Support by: http://hi.baidu.com/videocodec */
/* or QQ group: 24960630,10714050, 11216191 */
/* */
/**************************************************************/
#include <stdio.h>
#include <time.h>/* need time.h in order to call clock()*/
int main()
{
unsigned int start,stop, overhead,cycles;
/*––––––––––––––––––––––––––*/
/* The following example demonstrates how to include */
/* the clock() function in your C code. */
/*––––––––––––––––––––––– – –*/
start = clock(); /* Calculate overhead of calling clock*/
stop = clock(); /* and subtract this value from The results*/
overhead = stop - start;
start = clock();
/* ––––––––––––––––––––––––––*/
/* Call a function here. */
/* ––––––––––––––––––––––––––*/
stop = clock();
cycles = stop - start - overhead;
printf( “cycles: %d /n ” , cycles);
printf("times: %.2f s with cpu 600MHz, /n",((float) cycles /(float)600000000));
// clock() end
return 0;
}
/**************************************************************/
/* */
/* Auth:wb0330 */
/* Dest: used to measure cycle counts for TI C64x DSP */
/* Support by: http://hi.baidu.com/videocodec */
/* or QQ group:24960630, 10714050, 11216191 */
/* */
/**************************************************************/
#include <stdio.h>
#include "csl.h"
#include "csl_timer.h"
int main()
{
TIMER_Handle hTimer;
unsigned int start,stop, overhead,diff,cycles;
/*––––––––––––––––––––––––––––––––––*/
/* The following sample code shows how to set up the timer */
/* and measure cycle counts with Chip Support Library (CSL) */
/*––––––––––––––––––––––––––––––––––*/
hTimer = TIMER_open(TIMER_DEVANY,0); /* open a timer */
/*––––––––––––––––––––––––––––––––––*/
/* Configure the timer. count corresponds to 8 CPU cycles in C64 */
/*––––––––––––––––––––––––––––––––––*/
/* control period initial value */
TIMER_configArgs(hTimer, 0x000002C0, 0xFFFFFFFF, 0x00000000);
/* ––––––––––––––––––––––––––––––––––*/
/* Compute the overhead of calling the timer. */
/* ––––––––––––––––––––––––––––––––––*/
start = TIMER_getCount(hTimer); /* to remove L1P miss overhead */
start = TIMER_getCount(hTimer);
stop = TIMER_getCount(hTimer);
overhead = stop - start;
start = TIMER_getCount(hTimer);
/* ––––––––––––––––––––––––––––––––––*/
/* Call a function here. */
/* ––––––––––––––––––––––––––––––––––*/
diff = (TIMER_getCount(hTimer) - start) - overhead;
TIMER_close(hTimer);
cycles =diff*8;
printf( “cycles %d /n”,cycles);
printf("times: %.2f s with cpu 600MHz, /n",((float) cycles /(float)600000000));
// The maximum resolution of the timer is 8 CPU cycles, since the input clock to
// the timer is fixed to the CPU clock divided by eight
// CSL_timer end
return 0;
}
转载标明出处:http://blog.csdn.net/yd808/archive/2008/03/30/2230391.aspx