• Keine Ergebnisse gefunden

EPSONBasic instructions after expansion

10.7 Optimize Function

10.7.1 Optimizing Relative Branch Instruction

The E0C33000's basic relative branch instruction allows branch to any location within a signed 9-bit (LSB = 0) relative address range by using a single instruction. Branching to an address beyond this range requires extension by the ext instruction.

The ext33 allows you to write an extended branch instruction without worrying about the ext instruction as described in Section 10.6.9. Thus instruction is then expanded so that control is transferred a relative distance to the branch destination label by using the fewest possible instructions.

The following extended branch instructions can be optimized:

xcall xjp xjreq xjrne xjrgt xjrge xjrlt xjrle xjrugt xjruge xjrult xjrule

xcall.d xjp.d xjreq.d xjrne.d xjrgt.d xjrge.d xjrlt.d xjrle.d xjrugt.d xjruge.d xjrult.d xjrule.d The basic branch instructions written by adding the ext instruction are not optimized.

The number of instructions (1 to 3 instructions) that derive from expansion are determined according to the following conditions:

· Relative distance between the extended branch instruction and branch destination label

· Whether the extended branch instruction and branch destination label exist in the same file

· Whether the -near option is specified

· Whether there is symbol file/link map file specification by the -lk option

· Relative distance determination threshold 0x180000 (default) or value specified by the -j option

The number of instructions derived by expansion are determined in the following manner by resolving the above conditions:

Table 10.7.1.1 Number of instructions derived by expansion

Number of expanded In the same file In different files

To threshold value *3

To 0x7ffffff *4

Unknown relative distance

*1: The value indicates the number of instructions from the extended branch instruction to the branch destination label.

*2: Up to 125 when branching toward to a higher address.

*3: Up to the threshold value - 1 when branching toward to a higher address in the same file.

*4: Up to 0x7fffffe when branching toward to a higher address in the same file.

CHAPTER 10: INSTRUCTION EXTENDER

EPSON

When the -lk option is specified, branching to a different file based on the postlink symbol information can be optimized. However, since execution by cashing into the internal RAM is possible, branching to a label in a different file – although in the object file it may be branching within the 1-instruction range – is expanded as consisting of at least two instructions.

10.7.2 Optimization by the Global Pointer

Memory access by an extended instruction using a symbol is accomplished by using the R9 register as a scratch register, and is expanded in the following manner:

Example: xld.w [i],%r10 (Example of expansion before linkage)

ext i+0x0@h

ext i+0x0@m

ld.w %r9,i+0x0@l

ld.w [%r9],%r10

When accessing a memory-resident global variable, for example, the number of instructions derived from expansion can be reduced by setting the start address of the global variable area as a global pointer in advance.

Since the ext33 uses the R8 register as a global pointer, the address of the global pointer must be set to the R8 register in the initialize routine in advance. Note that the memory accessible range is limited to within +26-bit space from the global pointer address.

Specification for the ext33 is made by using the -gp <address> option ([global pointer optimize] in the wb33).

When this option is specified, the ext33 assumes that the R8 register is set as a global pointer to the specified

<address> as it processes the program.

If a global pointer is specified, the above example will be expanded as follows:

Example: xld.w [i],%r10 (Example of expansion before linkage)

ext i+0x0@ah

ext i+0x0@al

ld.w [%r8],%r10

In this case, since no scratch register is used, the number of instructions for each access can be reduced by one.

10.7.3 Optimization by Symbol Information

When creating one program by linking multiple relocatable modules, it should be noted that the absolute address of each instruction in the assembly source is not determined until after the modules are linked. Optimization at this phase is limited to those instructions that can be solved within the same file.

For this reason, the ext33 is designed in such a way that symbol information can be obtained from the symbol and link map files output by the linker by specifying the -lk option. Since each of these files contains information about the absolute addresses of the symbols that are determined after linkage, the symbols defined in other files can be referenced.

Therefore, make sure all source files including the ext33 are processed temporarily way up to the linking phase, then re-execute the ext33 after specifying the -lk option. The ext33 optimizes the extended instructions that are used to access memory locations using indeterminate symbols as it generates an assembly source file. Then, after this is done, assemble and link the source files one more time.

To generate the symbol and link map files, you need to specify the -m and -s options when starting up the linker.

If the variable i, which was used as an example in the preceding section, is assumed to be located in the 4th byte from the address indicated by the global pointer, then the first ext instruction will be deleted as follows:

Example: xld.w [i],%r10 (Example of expansion using postlink symbol information)

ext i+0x0@al

ld.w [%r8],%r10

Furthermore, if there is a memory access that is out of the accessible range by the global pointer, this function disables the global pointer optimization.

The ext33 checks to see if the symbol and map files bearing the file name specified by the -lk option are created in the same directory. If one or both of the two files cannot be found, the ext33 outputs a warning and stops performing -lk option-based optimization. Therefore, these files must always be stored under the same name in the same directory.

10.8 Other Functions

10.8.1 Comment Adding Function

When expanding extended instructions to create an assembly source file, the ext33 replaces these extended instructions with comments that begin with a semicolon (;) in order to show information about the contents of the extended instructions before they are expanded. The comments are added after the first line of instruction derived by expansion. If there is any comment accompanying the original statement, that comment is included among the added comments.

Example: Before expansion

xcall main ; goto main

After expansion

ext main@rm ; xcall main ; goto main

call main@rl

10.8.2 Classification of Local Symbols

The ext33 classifies the local labels that are valid in only the files generated by the Preprocessor and Compiler, then changes the labels "_ _ L????" used in extended relative branch instructions to "_ _ LX????." The changed labels have already been referenced in their file.

As a result, the Assembler as33 interprets the information on labels beginning with "_ _ LX" as being local;

therefore, this information is not output to the object file.

Local symbols used in any other instructions are not changed even if they are labeled "_ _ L????".

10.8.3 Syntactic Check

The ext33 only checks the syntax of extended instructions and the assembler pseudo-instructions listed below.

Assembler pseudo-instructions checked by ext33 .org, .space, .align, .comm, .lcomm, .set pseudo-instructions

These instructions are checked to see if the address-specifying operand is within the effective range of values represented by 32 bits.

.ascii pseudo-instruction

This instruction is checked to see if character strings are enclosed with double quotations (").

An error results if any extended instruction or one of the above assembler pseudo-instructions is written in a syntactically incorrect manner. If the operand value is invalid, a warning is output, and processing continues.

The syntax of the basic instructions is not checked. Nor is the validity of the instructions derived by expansion checked.

CHAPTER 10: INSTRUCTION EXTENDER

EPSON