Greetings,
Does this actually work on propgcc:
error: 'asm' undeclared (first use in this function)
so I cannot actually tell if it did anything. In my experience with timings, the compiler is so sensitive to changes in code that there is no logic to looking at the actual number you get back and you really have to examine the assembly to figure out why a time did what it did.
I am trying to prevent movement of timing measurements when compiling with -Os optimizations in a COGC. For example:
All the best,
Tom
Does this actually work on propgcc:
#define COMPILER_BARRIER() asm volatile("" ::: "memory")? I get very strange behavior in that it will compile under SimpleIDE, but when I try to look at the generated asm, I get:
error: 'asm' undeclared (first use in this function)
so I cannot actually tell if it did anything. In my experience with timings, the compiler is so sensitive to changes in code that there is no logic to looking at the actual number you get back and you really have to examine the assembly to figure out why a time did what it did.
I am trying to prevent movement of timing measurements when compiling with -Os optimizations in a COGC. For example:
cnt=CNT; //do a bunch of stuff externalStruct->time=CNT-cnt;The compiler feels free to move both timing lines pretty much anywhere it wants since there are no dependencies between them and anything that happens in the "do a bunch of stuff" code. Indeed, strictly speaking I believe the following is an allowable reordering under the rules of C:
cnt=CNT; externalStruct->time=CNT-cnt; //do a bunch of stuffObviously it typically does not move them nearly that far, but enough to be annoying when tuning things. So I want to do something like:
cnt=CNT; COMPILER_BARRIER() ; //do a bunch of stuff COMPILER_BARRIER() ; externalStruct->time=CNT-cnt;to lock those lines down.
All the best,
Tom