ppc instruction count

Hi,

Can anyone tell me how I can count the number of instructions or cycles needed for a particular piece of code? Other than stepping over in the debugger :)

Thanks, e.

Reply to
eascheiber
Loading thread data ...

You can get an assembly listing with something like objdump -d , and count by hand (or automatically). This will tell you how many instructions are needed to implement a particular function, but not how many instructions will actually be executed when running that function (because you need to know how all the branches behave).

Thinking fast - if your debugger has a "run for N instructions" facility, you can use that to manually perform a binary search - go to the start of the function, set a breakpoint at the end, run for 100,000 instructions, then 50,000, then 25,000, then 37,500... braketting until you've got an accurate-enough answer.

With a following wind, that might even be scriptable.

-Ben-

Reply to
Ben Jones

To count the number of cycles, use the time stamp counter present in the PPC. If you are using Xilinx EDK, you can use XTime_GetTime() routines to access the TSC..or you can always write assembly code.

/Siva

Reply to
Siva Velusamy

Thanks for the great solution,

just one question, in xtime_l.c XTime_GetTime function shouldn't use mftb instead of mfspr. It does not seem to work ok /w mfspr.

Bye.

Siva Velusamy wrote:

Reply to
eascheiber

That's odd. It does look like XTime_GetTime *should* be using mftb. But the mfspr code works fine for me (EDK6.1, EDK7.1, EDK8.1).

Alan Nishioka

Reply to
Alan Nishioka

Time Base Register is just another special purpose register. From the documentation it looks like mftb provides read access to non privileged code.

mfspr should work as long as you are running privileged code..which is the case with most simple apps. I haven't verified this though.

-Siva

Reply to
Siva Velusamy

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.