Tel: (519) 746-7178
Email: info@lumousoft.com
The trace analyzer can help compiler to optimize memory and performance by recycling memory and reducing codes reluctance and avoiding memory override.
The size of data memory is one of important factors that decides microprocessor s price. The bigger size of memory, the more cost of microprocessor chip. To recycle memory is one of pursuits of compiler optimization. Lumousoft graphic language can maximally recycle memory and reduce the size of memory. As a result, user can generate more productivity product and reduce cost.
Lumousoft graphic compiler s trace analyzer is able to identify the variable life span in all possible program layouts like parallel, selection branches, loop, call function modules etc, therefore can fully recycle memory.
Fig.1 Memory alloction example codes
A variable usually is assigned a memory or register to store a special value. When the content of a memory is written and the previous value of the memory is lost, we can say that the previous value is dead and the variable associated with this dead value die too. While, when the memory is written a new value, the variable associated with this memory is born. The variable has life span from the variable is assigned a new value to the last time usage before the memory was override. The variable might alive and die for many times in a program. And the variable with the same name might be assigned different memory address in a different life cycle. In order to show the difference of a variable address in the different life span, the variable in assembly files generated by compilation, append an address that assigned to this variable. Fig.1 demonstrates graphic codes and assembly codes for pic16f677. For instance, x_0x20 in the assembly files means that the data memory address 0x20 is allocated to variable x . We can find that variable x has two lives and the address is 0x20; the variable y also has two lives but the address is different in the different life span. At the beginning, the variable y is allocated by 0x21, and for the second time it is allocated by 0x20, same as x , but at this time the variable a is dead and memory associated with the variable a is released and can be used by variable y .
PIC microprocessors usually have different memory banks, some memories can be accessed in the all memory banks, while others can be accessed in part of memory banks. Lumousoft graphic compiler uses the trace analyser to remember which bank current program is in, and can automatically setup memory bank when it comes across a variable that has different memory bank from current memory bank. When the program comes across a memory, it will identify the memory bank of this variable and decide whether to insert bank setting up code. For example if the current bank is bank 0 and the variable that program come across belongs to bank 0, the compiler will not insert bank setup code, but the variable belongs to the other bank, the compiler will automatically insert bank setup code. As for a variable that can be accessed in more than two banks, the compiler can also automatically setup bank.
We still take pic16f677 for code example. Fig.2 illustrates how memory bank setup. At the beginning the memory bank is set as bank 0. At the block s0, Z is the bit of the register status and this status can be accessed in all banks including bank0, so there isnt need to set bank. When Z is set the program will go to block s2 and come across bit variable WPUB5, the variable WPUB is only accessed by bank2, the bit RP0 of the register status should be reset and RP1 set, because RP0 already reset, the compiler does not insert reset instruction for RP0, and only add RP1 set instruction, so the bank is in bank2. While in block S1 variable a is in bank0, because the current bank is bank0 (from block s0), there is no bank setting instruction. Block s3 comes from either S1 or S2, and the bank is either bank0 or bank2, because PORTA can be accessed either in bank0 or bank2, there isnt need to add bank setting instruction, when come to variable a which is in bank0, considering if S3 comes from s2, the bank is bank2, the compiler will add reset RP0 instruction to guarantee the bank is bank0. Through this example we can see that the analyzer can help compiler to set up correct memory bank without any reductant codes.
Fig.2 Memory bank setup example codes
As for indirect address bank setup, current version does not consider optimization of indirect address bank setup. In the future version this optimization will be considered.
PIC microprocessor allows indirect address by File Select Register (FSR) and INDF register, FSR hold the address pointer, the INDF register can map to the address that FSR point to. Lumousoft trace analyzer can statically remember the address that FSR hold. When the program encounter a indirect address, it will compare with the current indirect address that the trace analyzer remember , if it is same there is not action to load FSR with indirect address, on the opposite side, if it is different , it will load new address to FSR. By this method the reductant codes can be eliminated .
Fig.3 shows the example. We can find that FSR is not always loaded when come across a pointer. Because reference c is referenced to x , the x has known address, the variable c can directly map to x, it is not necessary to use indirect address, the compiler directly allocated the x address to c. While a and b reference address contain uncertain variable i , it cannot statically analyze the exact address that can directly point to. Therefore pointer a and b need to use indirect method to address. In assembly file Line 19 and 20 the FSR is loaded a pointer, the trace analyzer remember the Fsr address point to a , the FSR will not change until come to pointer variable b , line 27 and 28 indicates that the pointer b address is loaded to FSR. And in line 31 and 32, the FSR is loaded pointer a again.
Fig.3 Indirect address example codes
In the same way as memory bank setup, the analyzer can identify and remember which program memory page that the current program stay and when perform call or goto function, it will analyze which page that the routine that will be jumped to and automatically insert the page setup codes without reductance.
With trace analyzer the constant can be assigned a different value along the program path as long as there is not conflict. The confliction problem comes up when more than on branches join and if there no redefinition of this constant value at the join point, and a value from a branch is different from another branch.
Fig.4 show example code for constant change. The variable a can be set to constant data type by variable dialog. The constant a has a value of 3 at the first, later it change to 2 .
Fig.4 Constant example codes
Lumousoft trace analyzer can help compiler to indentify the program status of variable life span, data memory bank and program memory page, and therefore the compiler can optimize memory size and reduce reductant codes to increase performance and reduce cost due to lower memory requirements.
©Lumousoft Inc. 2013 - 2018.
Links
Elektronik Forum EEWeb : EEWEb Germany is an online community for electronics and electrical engineers and hobbyist. It offers electrical engineering and electronics forum. It also has electrical and electronic design articles, and resources in the area of RF design, analog design, embedded design, PCB design, test and measure.
Power Electronics News: Power Electronics News offers electrical engineering news focused on Power and Power solutions. Up to date solutions and products featuring the latest innovations in power solutions.
PCBWeb : A free CAD application for designing and manufacturing electronics hardware.