http://hi.baidu.com/myyb/blog/item/e1071dce1878d032b700c8c7.html
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;
}
这里给出CSL_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
"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;
}