Re: lpc2138 taking commands merely as a suggestion?




"kosta" <kostak@xxxxxxxxx> wrote in message
news:1185690759.615158.229930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I compile the code with -O0 optimizations usually, but oddly enough
sometimes
when I try other types of optimization, some work better in making the
leds work
correctly.

It sounds like you are expecting your code to do what you write, in the
order you write it.

Consider the following code:

int i=10;
i++;
i=30;
return i;

assuming that i is kept in normal memory the compiler can see that the
intermediate results are not used, so this code will turn into:

set r0 to30;
branch exchange lr;

The compiler will do this wherever it can see that the results should not
change between source lines, but obviously this is not what you want when
manipulating system control registers that are not just memory.

There is a keyword in C: "volatile" which effectivly means "assume nothing
about memory thru this pointer" any writes will cause a write to the
location and any reads will cause a read from the location, the same code
with volatile would probebly turn into:

write 10 to location i;
read location i;
add one to read value;
store to location i;
store 30 to location i;
read location i into r0;
branch exchange lr;

you can see why the compiler does the optimizations!

I will be glad to provide any other information which might help
resolve this, I
just don't really know what might be needed - please tell me if theres
anything
else you need to know, and I will promptly provide the info.

the source code of your simpilest example might help


.



Relevant Pages

  • Re: Implement memcmp function with help from gccs inline asm
    ... I would expect an optimising compiler to generate ... memcmp needs to compare memory as unsigned. ... > optimization, both snippets of code should be identical on P4. ... > 2 when comparing cached data. ...
    (comp.lang.asm.x86)
  • Re: WaitForSingleObject() will not deadlock
    ... It seems that "memory visibility" has something to do with making sure that results are in ... shared variables should be declared 'volatile' to ensure the compiler ... optimization fence into the intermediate instruction stream inside the compiler). ...
    (microsoft.public.vc.mfc)
  • Re: Runtime memory effect on compile and link
    ... I suspect that the problem is that the LTCG optimization, does a different job if it has more memory use at link time. ... and some different code is generated by the compiler. ...
    (microsoft.public.vc.language)
  • Re: C#, Threads, Events, and DataGrids/DataSets
    ... JIT compiler just compiles IL to x86 (or whatever platform it is developed ... optimization theory if you are interesting). ... then volatile could be important to guarantee that all memory writes ...
    (microsoft.public.dotnet.general)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... what experienced programmers do, ... optimization, ... Thugs" ad nauseum fits that a lot more closely than discussing compiler ... be modified outside a loop, and guessing ...
    (comp.programming)