Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Jan Waclawek
07/28/05 01:03
Read: 971 times

#98320 - Counting cycles... possible in C?
I think this topic deserves a separate thread.
Just to summarize:
Adam Klaum said:
That being would one go about calculating exactly how many machine cycles a particular chunk of ISR code would take to execute?
Russell Bull said:
Counting machine cycles gets a little difficult with 'c' as the compiler makes the decisions. You can read the assembler output from the compiler and manually lookup how many cycles each instruction takes and count them for each execution path.

Well, I think that automated worst-case cycle counting is at least partially possible, especially in structured high level language (C).

It should be possible to decompose the (structured) program into smaller blocks (in a tree form) and determine the worst-case execution time of it. For example, for "if" branches, it is straighforward to take the worst-case path. For cycles, it is not so straghforward but estimates can be made e.g. for for cycles based on the width of the cycle variable (e.g. for byte, max. 256 loops or so). In ambiguous places, a warning can be issued and human "intervention" can be asked (often one can determine the maximum loop count easily).

I visualise a series of pragmas, e.g. for begin/end counting, skip counting of some part, manually set count for same part, set max. mumber of cycles, set the type of processor etc.

While I don't think the commercial compilers' producers will start now implementing it; it is not unthinkable on open source compilers (SDCC).

Will this be useful?

Jan Waclawek

List of 18 messages in thread
Counting cycles... possible in C?      Jan Waclawek      07/28/05 01:03      
   You need a Profiler      Andy Neil      08/01/05 00:00      
      The compiler knows      Jan Waclawek      08/01/05 03:21      
         Source code useless      Andy Neil      08/01/05 04:50      
         That's why you need Assembler!      Andy Neil      08/01/05 04:56      
            nohohoho      Jan Waclawek      08/01/05 05:12      
               Speed is not everything!      Andy Neil      08/01/05 05:54      
   Cycles vary?      James Krushlucki      08/01/05 01:37      
      I know      Jan Waclawek      08/01/05 03:23      
   absolutely, but what good does it do      Erik Malund      08/01/05 06:27      
      other way round      Jan Waclawek      08/01/05 07:10      
         Yes, the things posted apply in this cas      Erik Malund      08/01/05 07:23      
            exactly for this reason      Jan Waclawek      08/01/05 08:29      
               how can you automate that it is small en      Erik Malund      08/01/05 08:35      
   Use Microsoft Excel      Aubrey Kagan      08/01/05 18:04      
      excel and conditional branches ?      Erik Malund      08/02/05 05:53      
         That's why      Aubrey Kagan      08/02/05 07:13      
            That makes absolutotally no difference,      Erik Malund      08/02/05 07:23      

Back to Subject List