Ti DSP Cycle Count

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值