>-----Original Message----- >From: [email protected] [mailto:avr- >[email protected]] On Behalf Of Pertti >Kellomäki >Sent: Wednesday, March 02, 2011 1:08 PM >To: [email protected] >Subject: Re: [avr-chat] Missed Optimisation ? > >Like Colin said, the C standard defines the semantics of the language >in terms of an abstract machine. Normally the compiler is allowed to >use an "as if" approximation of the semantics and leave out things >that would not change the state of the abstract machine. > >One way to look at volatile is that it is a way to tell the compiler >that you know things that the compiler does not know, and therefore >the compiler needs to do things "by the book", i.e. do all the things >that the abstract machine semantics requires it to do. > >I don't have an AVR compiler handy, but it would be instructive to see >what the compiler generates for "result = result*0" where result is >volatile.
result =result * 0; 00000058 LDD R24,Y+1 Load indirect with displacement 00000059 LDD R25,Y+2 Load indirect with displacement 0000005A LDD R26,Y+3 Load indirect with displacement 0000005B LDD R27,Y+4 Load indirect with displacement 0000005C STD Y+1,R1 Store indirect with displacement 0000005D STD Y+2,R1 Store indirect with displacement 0000005E STD Y+3,R1 Store indirect with displacement 0000005F STD Y+4,R1 Store indirect with displacement Code generated with -O2 turned on. R1 is zero register. The compiler expects the value of 'result' to be 0 which I think is ok no matter what 'result' is during the assignment execution. Likewise: result =result * 1; 00000058 LDD R24,Y+1 Load indirect with displacement 00000059 LDD R25,Y+2 Load indirect with displacement 0000005A LDD R26,Y+3 Load indirect with displacement 0000005B LDD R27,Y+4 Load indirect with displacement 0000005C STD Y+1,R24 Store indirect with displacement 0000005D STD Y+2,R25 Store indirect with displacement 0000005E STD Y+3,R26 Store indirect with displacement 0000005F STD Y+4,R27 Store indirect with displacement Anitha _______________________________________________ AVR-chat mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/avr-chat
