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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/01/05 17:43
Read: times


 
#96398 - Overlaying and Scope
Responding to: ???'s previous message

I'd previously thought that keeping locals in the innermost scope possible would get a further benefit from overlaying - but someone on the Keil forum recently suggested that this is not so.

Can you comment?


Overlaying works on function scope only. That's because local variable segments are created at the function level but no lower.

In most cases, the compiler re-uses variables in sequential blocks. For example:


line level    source

   1          void main (void)
   2          {
   3   1      // Block 1
   4   1        {
   5   2        unsigned int a, b, c, d, e, f;
   6   2      
   7   2        a = b+c+d+e+f;
   8   2        }
   9   1      
  10   1      // Block 2
  11   1        {
  12   2        unsigned long a, b, c;
  13   2      
  14   2        a = b+c;
  15   2        }
  16   1      
  17   1      // Block 3
  18   1        {
  19   2        unsigned char a, b, c;
  20   2      
  21   2        a = b+c;
  22   2        }
  23   1      }
  24          

ASSEMBLY LISTING OF GENERATED OBJECT CODE


             ; FUNCTION main (BEGIN)
                                           ; SOURCE LINE # 1
                                           ; SOURCE LINE # 2
                                           ; SOURCE LINE # 4
                                           ; SOURCE LINE # 7
0000 E500        R     MOV     A,b+01H
0002 2500        R     ADD     A,c+01H
0004 CF                XCH     A,R7
0005 E500        R     MOV     A,b
0007 3500        R     ADDC    A,c
0009 CF                XCH     A,R7
000A 2500        R     ADD     A,d+01H
000C CF                XCH     A,R7
000D 3500        R     ADDC    A,d
000F CF                XCH     A,R7
0010 2500        R     ADD     A,e+01H
0012 CF                XCH     A,R7
0013 3500        R     ADDC    A,e
0015 CF                XCH     A,R7
0016 2500        R     ADD     A,f+01H
0018 F500        R     MOV     a+01H,A
001A EF                MOV     A,R7
001B 3500        R     ADDC    A,f
001D F500        R     MOV     a,A
                                           ; SOURCE LINE # 8
                                           ; SOURCE LINE # 11
                                           ; SOURCE LINE # 14
001F E500        R     MOV     A,b+03H
0021 2500        R     ADD     A,c+03H
0023 F500        R     MOV     a+03H,A
0025 E500        R     MOV     A,b+02H
0027 3500        R     ADDC    A,c+02H
0029 F500        R     MOV     a+02H,A
002B E500        R     MOV     A,b+01H
002D 3500        R     ADDC    A,c+01H
002F F500        R     MOV     a+01H,A
0031 E500        R     MOV     A,b
0033 3500        R     ADDC    A,c
0035 F500        R     MOV     a,A
                                           ; SOURCE LINE # 15
                                           ; SOURCE LINE # 18
                                           ; SOURCE LINE # 21
0037 E500        R     MOV     A,b
0039 2500        R     ADD     A,c
003B F500        R     MOV     a,A
                                           ; SOURCE LINE # 22
                                           ; SOURCE LINE # 23
003D 22                RET     
             ; FUNCTION main (END)



MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =     62    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      12
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)


Jon

List of 54 messages in thread
TopicAuthorDate
code optimization            01/01/70 00:00      
   erm...            01/01/70 00:00      
   guidelines            01/01/70 00:00      
   Duh !!!!            01/01/70 00:00      
      yes its a link to learn optimization            01/01/70 00:00      
         the links provided            01/01/70 00:00      
            Really Wicked Optimisations!            01/01/70 00:00      
            counters in loops?            01/01/70 00:00      
               DJNZ            01/01/70 00:00      
                  ahh            01/01/70 00:00      
                  DOES it ?            01/01/70 00:00      
                     on Keil forum            01/01/70 00:00      
                     Yes!            01/01/70 00:00      
                     Of course it does...            01/01/70 00:00      
                        But...            01/01/70 00:00      
                           asking too much            01/01/70 00:00      
                              Not at all            01/01/70 00:00      
                           Maybe it does...            01/01/70 00:00      
                              Not when I tried it.            01/01/70 00:00      
                                 Lopp Rtation            01/01/70 00:00      
                        While you're there, Jon...            01/01/70 00:00      
                           how like a salt block?            01/01/70 00:00      
                              oh -- got it            01/01/70 00:00      
                           Overlaying and Scope            01/01/70 00:00      
                              Does it matter?            01/01/70 00:00      
                                 debugging            01/01/70 00:00      
   Previously on 8052.com            01/01/70 00:00      
      yes its in the board            01/01/70 00:00      
      IAR Article - Getting the Least            01/01/70 00:00      
   To be taken with a pinch of salt            01/01/70 00:00      
      more like a salt block            01/01/70 00:00      
      Re            01/01/70 00:00      
         switch            01/01/70 00:00      
            Switch/Case Optimization            01/01/70 00:00      
               Re: Switch/Case Optimization            01/01/70 00:00      
                  Look Why            01/01/70 00:00      
               Jon, I may have made a mistake            01/01/70 00:00      
         Big switches            01/01/70 00:00      
         Was?            01/01/70 00:00      
            Link to newer version            01/01/70 00:00      
               Hitex; Chris Hills            01/01/70 00:00      
                  Draft!            01/01/70 00:00      
   intermediate values in lookup tables            01/01/70 00:00      
      Generating lookup tables            01/01/70 00:00      
   a general statement on code optimization            01/01/70 00:00      
      Craft            01/01/70 00:00      
      Corrections            01/01/70 00:00      
         urban legends            01/01/70 00:00      
            Been there.            01/01/70 00:00      
               I think this is closer to the truth            01/01/70 00:00      
                  I just realize that the above            01/01/70 00:00      
               EE/CS            01/01/70 00:00      
            Micro-Optimisations - real-life example            01/01/70 00:00      
               manual optimization            01/01/70 00:00      

Back to Subject List