??? 07/28/05 07:03 Read: times |
#98320 - Counting cycles... possible in C? |
I think this topic deserves a separate thread.
Just to summarize: Adam Klaum said: That being said...how 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 |
Topic | Author | Date |
Counting cycles... possible in C? | 01/01/70 00:00 | |
You need a Profiler | 01/01/70 00:00 | |
The compiler knows | 01/01/70 00:00 | |
Source code useless | 01/01/70 00:00 | |
That's why you need Assembler! | 01/01/70 00:00 | |
nohohoho | 01/01/70 00:00 | |
Speed is not everything! | 01/01/70 00:00 | |
Cycles vary? | 01/01/70 00:00 | |
I know | 01/01/70 00:00 | |
absolutely, but what good does it do | 01/01/70 00:00 | |
other way round | 01/01/70 00:00 | |
Yes, the things posted apply in this cas | 01/01/70 00:00 | |
exactly for this reason | 01/01/70 00:00 | |
how can you automate that it is small en | 01/01/70 00:00 | |
Use Microsoft Excel | 01/01/70 00:00 | |
excel and conditional branches ? | 01/01/70 00:00 | |
That's why | 01/01/70 00:00 | |
That makes absolutotally no difference,![]() | 01/01/70 00:00 |