This chapter contains the following sections:
Description
Invocation
Detailed Description of Assembler Options
Environment Variables
Optimizations
Introduction
Move Symbolic Debug Information
Branch Optimization
Move Parallelization
NOP Removal
Optimize for Speed
Single Instruction DO Loops to REP
Split Parallel Instructions
Retain Instruction Order
Generic Moves
DO Loop Code Duplication
Software Pipelining
List File
Absolute List File Generation
Page Header
Source Listing
Optimizations in Source Listing
The DSP5600x assembler as56 and the DSP563xx/DSP566xx assembler as563 are optimizing assemblers. In this chapter these assemblers are all referred to by as563 unless explicitly stated otherwise. During assembly the assembler builds an internal representation of the program. This representation, the flow graph, is used to optimize the program. Examples of the optimizations are parallelization of moves, exchanging instructions and removal of delay slots. After optimization the object file and, optionally, the list file are generated.
The following phases can be identified during assembly:
1. Preprocess, check the syntax and create the flow graph
2. Resolve references to labels in nested scopes (see note)
3. Type determination of all expressions
4. Legality check of all instructions
5. Optimization
6. Address calculation, jump optimization
7. Generation of object and (when requested) list file
As the section information cannot be represented in the IEEE-695 object format the assembler must resolve all label references
to labels not contained in the referring section.
The assembler generates relocatable object files using the IEEE-695 object format. This file format specifies a code part and a symbol part as well as a symbolic debug information part.
File inclusion and macro facilities are integrated into the assembler. See the chapter Macro Operations for more information.
The compiler control program cc563 may call the assembler automatically. cc563 translates some of its command line options to options of as563. However, the assembler can be invoked as an individual program also.
The PC invocation of as563 is:
When you use a UNIX shell (C-shell, Bourne shell), options containing special characters (such as '( )' ) must be enclosed with "". The invocations for UNIX and PC are the same, except for the -? option in the C-shell:
Invocation with -V only displays a version header. -? shows the invocation syntax.
The source-file must be an assembly source file. This file is the input source of the assembler. This file contains assembly code which is either user written or generated by c563. Any name is allowed for this file. If this name does not have an extension, the extension .asm is assumed or, if the file is still not found, the extension .src is assumed.
In the default situation, an object file with extension .obj is produced. With the -l option a list file with extension .lst is produced also. If additionally a map-file is specified, only an absolute list file is produced.
Options are preceded by a '-' (minus sign). Options can not be combined after a single '-'. If all goes well, the assembler generates a relocatable object module which contains the object code, with the default extension .obj. You can specify another output filename with the -o option. Error messages are written to the terminal, unless they are directed to an error list file with the -err assembler option.
The following list describes the assembler options briefly. The next section gives a more detailed description.
Option | Description | ||||||||||||||||||||||||||||||||||||||
-? | Display invocation syntax | ||||||||||||||||||||||||||||||||||||||
-Dmacro[=def] |
Define preprocessor macro
-Idirectory |
Look in directory for include files |
-J[a|l|r] |
Select branch mode (as563 only) |
-L[flag...] |
Select listing file layout |
-Mmodel |
Select memory model: 16-bit, 16/24-bit or 24-bit or DSP566xx (as563 only) |
-O[flag...]
|
Optimization on/off switches |
-R[flag...]
|
Remove restrictions |
-S[x] |
Generate Motorola compatible assembly file |
-V |
Display version header only |
-c |
Switch to case insensitive mode (default case sensitive) |
-e |
Remove object file on assembly errors |
-err |
Redirect error messages to error file |
-f file |
Read options from file |
-g[flag...] |
Generate assembly level debug information |
-l |
Generate listing file |
-mmask |
Select processor mask (as563 only) |
-o filename |
Specify name of output file |
-t |
Display section summary |
-v |
Verbose mode. Print the filenames and numbers of the passes while they progress |
-w[num] |
Suppress one or all warning messages
| |
Table 2-1: Options summary
With options that can be set from within EDE, you will
find a mouse icon that describes the corresponding action.
-?
Display an explanation of options at stdout.
as563 -?
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous.
Disable the Assembler works case sensitive check box.
-c
Case sensitive
Switch to case insensitive mode. By default, the assembler operates in case sensitive mode.
To switch to case insensitive mode, enter:
as563 -c test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous. Define a macro (syntax: macro[=def])
in the Define user macros field. You can define more macros by separating them with commas.
-Dmacro[=def]
The macro you want to define and optionally its definition.
Define macro as in 'define'. If def is not given ('=' is absent), '1' is assumed. Any number of symbols can be defined.
as563 -DPI=3.1416 test.src
EDE always removes the object file on errors.
-e
Use this option if you do not want an object file when the assembler generates errors. With this option the 'make' utility always does the proper productions.
as563 -e test.src
In EDE this option is not useful.
-err
The assembler redirects error messages to a file with the same basename as the output file and the extension .ers. The assembler uses the basename of the output file instead of the input file.
To write errors to the test.ers instead of stderr, enter:
as563 -err test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous.
Add the option to the Additional options field.
-f file
A filename for command line processing. The filename "-" may be used to denote standard input.
Use file for command line processing. To get around the limits on the size of the command line, it is possible to use command files. These command files contain the options that could not be part of the real command line. Command files can also be generated on the fly, for example by the make utility.
More than one -f option is allowed.
Some simple rules apply to the format of the command file:
1. It is possible to have multiple arguments on the same line in the command file.
2. To include whitespace in the argument, surround the argument with either single or double quotes.
3. If single or double quotes are to be used inside a quoted argument, we have to go by the following rules:
a. If the embedded quotes are only single or double quotes, use the opposite quote around the argument. Thus, if a argument should contain a double quote, surround the argument with single quotes.
b. If both types of quotes are used, we have to split the argument in such a way that each embedded quote is surrounded by the opposite type of quote.
Example:
"This has a single quote ' embedded"
or
'This has a double quote " embedded'
or
'This has a double quote " and \ a single quote '"' embedded"
4. Some operating systems impose limits on the length of lines within a text file. To circumvent this limitation it is possible to use continuation lines. These lines end with a backslash and newline. In a quoted argument, continuation lines will be appended without stripping any whitespace on the next line. For non-quoted arguments, all whitespace on the next line will be stripped.
Example:
"This is a continuation \ line" -> "This is a continuation line" control(file1(mode,type),\ file2(type)) -> control(file1(mode,type),file2(type))
5. It is possible to nest command line files up to 25 levels.
Suppose the file mycmds contains the following line:
-err test.src
The command line can now be:
as563 -f mycmds
Select the Project | Project Options... menu item. Expand the Assembler entry and select Output.
Enable one or more of the following check boxes:
1. Assembler source line information (excludes 2 and 4)
2. Pass HLL debug information (excludes 1, 3 and 4)
3. Local assembly symbols debug information (excludes 2 and 4)
4. Smart debug (excludes 1, 2 and 3)
-g[flag...]
-gAhLS (only HLL debug)
Specify to generate debug information. If you do not use this option or if you specify -g without a flag, the default is -gAhLS, which only passes the high level language debug information.
Flags can be switched on with the lower case letter and switched off with the uppercase letter.
An overview of the flags is given below.
a - assembler source line information
h - pass HLL debug information
l - local symbols debug information
s - always debug; either "AhL"
or "aHl"
With -ga you enable assembler source line information. With -gh the assembler passes the high level language debug information from the compiler to the object file. These two types of debug information cannot be used both. So, -gah is not allowed.
With -gl you enable the generation of local symbols debug information. You can use this option independent of the setting of the -ga and -gh options.
With -gs you instruct the assembler to always generate debug information. If HLL debug information is present in the source file, the assembler passes this information (same as -gAhL). If no HLL debug information is present, the assembler generates assembler source line information and local symbols debug information (same as -gaHl).
To pass high level symbolic debug information to the output files and generate local symbols debug information, enter:
as563 -ghl test.src
To generate assembler source line information, enter:
as563 -ga test.src
To always generate debug information, depending on the debug information in the source file, enter:
as563 -gs test.src
Select the Project | Directories... menu item. Add one or more directory paths to the Include Files Path field.
-Idirectory
The name of the directory to search for include file(s).
Change the algorithm for searching include files whose names do not have an absolute pathname to look in directory. Thus, include files whose names are enclosed in "" are searched for first in the directory of the file containing the include line, then in the current directory, then in directories named in -I options in left-to-right order. If the include file is still not found, the assembler searches in a directory specified with the environment variable AS563INC (for DSP563xx/DSP566xx), AS56INC (for DSP5600x), AS56INC and AS563INC can contain more than one directory. Separate multiple directories with ';' for PC (':' for UNIX). Finally, the directory ../include relative to the directory where the assembler binary is located is searched.
For include files whose names are in <>, the directory of the file containing the include line and the current directory are not searched. However, the directories named in -I options (and the one in AS563INC (AS56INC for DSP5600x), and the relative path) are still searched.
as563 -I/proj/include test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select Branch Mode.
Select a branch mode.
-J[ a |
l | r ]
-J
Select the branch mode. -Ja selects the absolute branch mode and -Jr selects the relative branch mode. -Jl selects the location-independent branch mode (branches within the source file are made relative, all others absolute). Specifying -J or no -J option at all, selects the default branch mode (no changes).
To select the relative branch mode, enter:
as563 -Jr test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select List File. Make sure the Generate list file (.lst) check box is enabled. Enable or disable one or more check boxes in the List file generation options field.
-L[flag...]
Optionally one or more flags specifying which source lines are to be removed from the list file.
-LcDEilMNpQsWXYZ2
Specify which source lines are to be removed from the list file. A list file is generated when the -l option is specified. If you do not specify the -L option the assembler removes source lines containing #line directives or symbolic debug information, empty source lines and puts wrapped source lines on one line. -L without any flags, is equivalent to -Lcdelmnpqswxyz, which removes all specified source lines form the list file.
Flags can be switched on with the lower case letter and switched off with the uppercase letter. The following flags are allowed:
c Default. Remove source lines containing assembler controls (the OPT directive).
C Keep source lines containing assembler controls.
d Remove source lines containing section directives (the ORG directive).
D Default. Keep source lines containing section directives.
e Remove source lines containing one of the symbol definition directives EXTERN, GLOBAL, LOCAL or CALLS.
E Default. Keep source lines containing symbol definition directives.
i Default. Remove source lines included from other files (INCLUDE).
I Keep source lines included from other files (INCLUDE).
l Default. Remove source lines containing C preprocessor line information (lines with #line).
L Keep source lines containing C preprocessor line information.
m Remove source lines containing macro/dup directives (lines with MACRO or DUP).
M Default. Keep source lines containing macro/dup directives.
n Remove empty source lines (newlines).
N Default. Keep empty source lines.
p Default. Remove source lines with false conditional assembly conditions (IF, ELSE, ENDIF).
P Keep source lines with false conditional assembly conditions (IF, ELSE, ENDIF).
q Remove source lines containing assembler equates (lines with EQU or '=').
Q Default. Keep source lines containing assembler equates.
s Default. Remove source lines containing high level language symbolic debug information (lines with SYMB).
S Keep source lines containing HLL symbolic debug information.
w Remove wrapped part of source lines.
W Default. Keep wrapped source lines.
x Remove source lines containing MACRO/DUP expansions.
X Default. Keep source lines containing MACRO/DUP expansions.
y Hide cycle counts.
Y Default. Show cycle counts.
z Show instruction lines from input file.
Z Default. Show actual coded instructions.
0 Hide opcode columns.
1 Show one column of opcodes.
2 Default. Show two columns of opcodes.
To remove source lines with assembler controls from the resulting list file and to remove wrapped source lines, enter:
as563 -l -Lcw test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select List File.
Enable the Generate list file (.lst) check box.
-l
Generate listing file. The listing file has the same basename as the output file. The extension is .lst.
To generate a list file with the name test.lst, enter:
as563 -l test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous.
Select an Assembly Mode.
-Mmodel
A memory model:
Model Description
16 16-bit assembly model (constant expressions)
1624 16/24-bit assembly model
24 24-bit assembly model (default)
6 DSP566xx assembly model
The DSP566xx assembly model is used to generate DSP566xx compatible assembly. This automatically selects the 16-bit model for constant expressions. It also conforms to the specific pipeline requirements of this processor. This model is only available on the DSP563xx.
The 16-bit model is used to generate constants in 16-bit format for use in the 16-bit arithmetic mode of the processor. It matches the 'opt sbm' assembler directive. This model is only available on the DSP563xx .
The assembler accepts all memory model options (-M) from the C compiler (see C manual). The memory model passed on the command line is ignored except for the DSP566xx memory model. The other model options are used to set the predefined functions @MODEL(), @DEFMEM() and @STKMEM() that can be used to make assembly code work in any memory model.
Assemble a list of fract constants in 16-bit mode:
as563 -M16 test.src
M:ADDRSS CODE LINE SOURCELINE 2 X:000000 3 org x: X:000000 000CCD 4 dc 0.1,0.2,0.3 00199A 002666
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous. Select a chip mask in the Select chip mask for problem fixes field.
-mmask
A number indicating the mask for a DSP563xx/DSP566xx processor:
Number Mask
0 0F92R and 1F92R
1 3F48S
When the assembler knows different masks for a given processor then you can select a mask using this option. Currently the assembler only supports masks for the DSP563xx processor.
Because of pipeline problems some instructions may not be used after (external) memory accesses, the assembler inserts NOP instructions when necessary.
To select masks 0F92R and 1F92R, enter:
as563 -m0 test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select Optimization. Enable or disable one or more Optimization check boxes.
-O[flag...]
Optionally one or more optimization flags.
-OGJMNpRS (no optimization)
Description:
Control optimization. -O without any flags is the same as specifying -OgjmnprS, which performs all optimizations.
Flags can be switched on with the lower case letter and switched off with the uppercase letter. The following flags are allowed:
g Move symbolic debug locations. This option only has effect when used with the -Om option. The assembler moves lines containing symbolic debug information to another location in order to perform a better move parallelization.
G Default. Retain symbolic debug locations.
j Enable branch optimization. The assembler tries to replace branches with shorter or faster functionally equivalent branches.
J Default. Disable branch optimization.
m Enable move parallelization. The assembler tries to change any programmed MOVE instruction into a parallel move, added to a previous or next instruction.
M Default. Disable move parallelization.
n Remove existing NOP instructions.
N Default. Do not perform NOP removal.
p Default. Optimize for speed rather than code size.
P Do not perform speed optimization.
r Replace a single instruction DO loop with a REP instruction.
R Default. Do not perform single instruction DO REP optimization.
s Split parallel move instructions in separate instructions before performing optimizations.
S Default. Do not split parallel move instructions.
To enable move parallelization, enter:
as563 -Om test.src
Example of backward move parallelization:
AND X0,A1 MOVE (R5)-N5
can be changed into:
AND X0,A1 (R5)-N5
Example of forward move parallelization:
MOVE (R5)-N5 AND X0,A1
can be changed into:
AND X0,A1 (R5)-N5
If symbolic debug information was found between instructions that could otherwise be optimized, you also have to specify -Og. For example, when you specify -Ogm or (-O):
as563 -Ogm test.src
the following code:
MOVE (R5)-N5 SYMB ALAB, Fi, #16 AND X0,A1
can be changed into:
SYMB ALAB, Fi, #16 AND X0,A1 (R5)-N5
To remove existing NOP instructions, enter:
as563 -On test.src
With this option the following code:
AND X0,A1 NOP AND Y0,B1
can be changed into:
AND X0,A1 AND Y0,B1
To replace a single instruction DO loop with a REP instruction, enter:
as563 -Or test.src
With this option the following code:
DO #$100,label MAC x0,x0,a x:(r1)+,x0 label:
becomes:
REP #$100 MAC x0,x0,a x:(r1)+,x0
To split parallel move instructions before performing optimizations, enter:
as563 -Os test.src
With this option the following code:
MAC x0,x0,a x:(r1)+,x0
becomes:
MAC x0,x0,a MOVE x:(r1)+,x0
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous.
Add the option to the Additional options field.
-o filename
An output filename. The filename may not start immediately after the option. There must be a tab or space in between.
Basename of assembly file with .obj suffix.
Use filename as output filename of the assembler, instead of the basename of the assembly file with the .obj extension.
To create the object file myfile.obj instead of test.obj, enter:
as563 test.src -o myfile.obj
Select the Project | Project Options... menu item. Expand the Assembler entry and select Optimization.
Enable or disable one or more Restrictions check boxes.
-R[flag...]
Optionally one or more remove restriction flags.
-RDRS (no restrictions are removed)
Remove pipeline restrictions. Some instruction sequences may cause pipeline effects, as described in section 7.2.2 Summary of Pipeline-Related Restrictions in Motorola's DSP56000 Digital Signal Processor Family Manual [Motorola, inc]. as563 can remove these restrictions by inserting NOP instructions. as563 also issues warning W139: "inserted NOP instruction(s) to remove restriction". If a pipeline effect was found and you did not supply any of the -R options, as563 issues warning W140: "previous instruction sequence has a pipeline effect".
-R without any flags is the same as specifying -Rdrs, which removes all pipeline restrictions.
Flags can be switched on with the lower case letter and switched off with the uppercase letter. The following flags are allowed:
d Remove DO/ENDDO restrictions. With this option the assembler can check if certain DO/ENDDO instructions may cause problems. For example, a number of operations may not precede a DO loop target label.
D Default. Retain DO/ENDDO restrictions.
r Remove Rn, Nn, Mn pipeline restrictions.
R Default. Retain Rn, Nn, Mn pipeline restrictions.
s Remove stack restrictions. This option removes restrictions that apply to the usage of SSH, SSL, SP, MR and CCR before a RTI or RTS instruction and removes restrictions of SP and SSH/SSL register manipulation.
S Default. Retain stack restrictions.
To remove DO/ENDDO restrictions and Rn, Nn, Mn pipeline restrictions, enter:
as563 -Rdr test.src
Example of removing a DO/ENDDO restriction:
do #10,L1 movec ssh,x:(R0)+ L1:
is changed into:
do #10,L1 movec ssh,x:(R0)+ nop nop nop L1:
Example of removing a Rn, Nn, Mn restriction:
move #$100,R7 move x:(R7)+,x0
is changed into:
move #$100,R7 nop move x:(R7)+,x0
Example of removing stack restriction:
move ssh,r0 RTS
is changed into:
move ssh,r0 nop RTS
Section 7.2.2 Summary of
Pipeline-Related Restrictions in Motorola's DSP56000 Digital Signal Processor Family Manual
[Motorola, inc]
Select the Project | Project Options... menu item. Expand the Assembler entry and select Output.
Enable the Generate assembly file instead of object file check box.
-S[x|X]
Generate a Motorola compatible assembly file. This option is intended to be used in combination with optimization options of the TASKING assembler to produce an optimized assembly file, which can be used by the Motorola assembler. -S is the same as -SX. With -Sx the assembler does not expand macro/dup definitions in the assembly file.
The following command produces an optimized Motorola compatible assembly file, called test.asm, with expanded macro/dup definitions.
as563 -S -Om test.src
Select the Project | Project Options... menu item. Expand the Assembler entry and select Output.
Enable the Display module section size summary check box.
-t
Produce totals (section size summary). For each section its memory space, size, total cycle counts and name is listed on stdout.
The cycle count consists of two parts. The total accumulated count for the section and the total accumulated count for all repeated (REP/DO) instructions. In the case of nested loops it is possible that the total supersedes the section total.
as56 -t test.src
Section summary: Nr M:Loc Size Cycle/loop Name 1 P: 000a 24/0 .ptext 2 X: 0001 .xovl@main 3 X: 000d .xstring
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous.
Add the option to the Additional options field.
-V
With this option you can display the version header of the assembler. This option must be the only argument of as56. Other options are ignored. The assembler exits after displaying the version header.
as56 -V
TASKING DSP5600x assembler vx.yrz Build nnn Copyright 1995-year Altium BV Serial# 00000000
as563 -V
TASKING DSP563xx/6xx assembler vx.yrz Build nnn Copyright 1996-year Altium BV Serial# 00000000
Select the Project | Project Options... menu item. Expand the Assembler entry and select Miscellaneous.
Add the option to the Additional options field.
-v
Verbose mode. With this option specified, the assembler prints the filenames and the assembly passes while they progress. So you can see the current status of the assembler.
as563 -v test.src
Parsing "test.src" 48 lines (total now 43) Optimizing Evaluating absolute ORG addresses Parsing symbolic debug information Creating object file "test.obj" Closing object file
Select the Project | Project Options... menu item. Expand the Assembler entry and select Diagnostics. Select Display all warnings, Suppress all warnings or Suppress only certain warnings.
If you select Suppress only certain warnings, type the numbers of the warnings you want to suppress in the corresponding field.
-w[num]
Optionally the warning number to suppress.
-w suppress all warning messages. -wnum suppresses warning messages with number num. More than one -wnum option is allowed.
The following example suppresses warnings 113 and 114:
as563 -w113 -w114 file.src
AS56INC With this environment variable you can specify directories where the as56 assembler will search for include files. You can overrule this search path with the -I command line option. Multiple pathnames can be separated with semicolons.
AS563INC Same as AS56INC, but now for as563.
TMPDIR With the TMPDIR environment symbol you can specify the directory where the assembler can generate temporary files. If the assembler terminates normally, the temporary file will be removed automatically. If you do not set TMPDIR, the temporary file will be created in the current working directory.
The DSP56xxx assemblers perform various optimizations to speed up assembled applications.
This section discusses the assembler optimizations and their possible implications. All optimizations can be switched on and off from the command line and by using appropriate OPT directive arguments. Some optimizations can only be switched on module basis (last OPT is valid), while others can be changed at any point in the source (e.g. flow).
The following optimizations are available, they are discussed hereafter. See also the -O option.
Description | Option | OPT | Module |
Move symbolic debug information | -Og | OPHLL | Module |
Branch optimization | -Oj | OPJMP | Module |
Move parallellization | -Om | OPPM | Module |
NOP removal | -On | OPNOP | Flow |
Optimize for speed | -Op | OPSPEED | Flow |
Single instruction DO to REP | -Or | OPREP | Flow |
Split parallel instructions | -Os | OPSP | Module |
Retain instruction order | ORDER | Flow | |
Generic Move instructions | - | - | |
DO loop code duplication | OPPM and OPHLL | Module | |
Software pipelining | - | - |
Table 2-2: Optimizations
All parallellizations are done on instruction blocks surrounded by labels, symbolic debug information, retained NOP instructions or instructions that change the control flow.
In the C compiler generated sources extra debugging information is inserted using SYMB directives. To maintain debugging ease it is possible to instruct the assembler not to move instructions past the debugging information. When debugging ease is not important but code size and speed is, it is possible to instruct the assembler to collect all debugging information at the start of an instruction block. In that case the assembler has more possibilities to move and combine instructions. High level source stepping in a debugger can behave strangely after using this option.
As mentioned above the assembler will try to combine instructions within an instruction block. This is done by reordering the instructions to find combinations of instructions that can be combined. The assembler does not try to retain any ordering as written in the assembly source file. The result of the instruction reordering and combination can be seen in the listing file.
The assembler tries to replace branches with shorter or faster functionally equivalent branches. This is only done with branches whose targets are not annotated with the short ('<') or long ('>') operators. Annotated branches remain as specified in the source.
When the -Oj option is given the assembler makes extra passes over the flow graph to check whether some branches can be made shorter or faster.
All NOP instructions (except those immediately following REP instructions) are removed from the program. The assembler tries to reorder the instructions so a minimum of NOP instructions is needed to accommodate for pipeline delays. Sometimes it is necessary to retain NOP instructions. In that case it is possible to enclose those instructions between two OPT directives:
OPT NOOPNOP MOVE #$13,X:$FFFC NOP ; wait four cycles NOP ; these NOPs will not be removed MOVE X:$FFFD,X0 OPT OPNOP
The assembler tries to reduce stall cycles and tries to unroll small loops, at the expense of code size.
When a DO loop with a body of only one instruction is found then the DO instruction is changed into a REP instruction. In this case the REP instruction is faster and shorter. The drawback is that interrupts are not serviced during a REP loop.
It is possible to split instructions in single moves and arithmetic instructions before the optimizer tries to reorder and combine the instructions. In some cases this yields shorter code because the optimizer has more combination possibilities.
Sometimes you do not want the assembler to reorder instructions, especially when doing input or output. In this case you can surround the instructions that must be executed in a predetermined order with the OPT ORDER and OPT NOORDER directives. In that case the instructions will retain their ordering, however it is still possible that other instructions can be inserted between or combined with instructions of the sequence. When this is not what you want, you can place a label at the start of and after the instruction sequence, as the assembler does not move instructions past labels.
Apart from the affected condition flags some MOVE type instructions and arithmetic instructions have almost the same effect. To give the assembler more combination possibilities generic move, GMOVE, instructions may be used. Every move can be written as a GMOVE, but only some of them map into, almost, equivalent TFR or CLR instructions.
Possible mappings are:
GMOVE #$0,reg |
CLR reg
MOVE #$0,reg (DSP5600x/3xx)
MOVEC #$0,reg
GMOVE reg,reg |
TFR reg,reg
MOVE reg,reg
MOVEC reg,reg
| |
Table 2-3: Generic moves
Other GMOVE instructions are replaced by their corresponding MOVE, MOVEC, MOVEP, MOVES or MOVEI counterparts.
Sometimes it is possible to combine an instruction in the head of a DO loop body with an instruction in the tail of the DO loop body. When this is possible and when at the target label or directly after the target label a VOID directive is used that lists all registers changed by the instruction, then the instruction is combined with the instruction in the tail of the DO loop and duplicated in front of the DO instruction.
For example:
DO R0,L1 MOVE X:(R2)+,X0 MAC X0,X0,A L1: VOID R2,X0
Is changed into:
MOVE X:(R2)+,X0 ;duplicate move DO R0,L1 MAC X0,X0,A X:(R2)+,X0 ;combined instr. L1: VOID R2,X0
Using DO loop to REP optimization, this can be changed into:
MOVE X:(R2)+,X0 REP R0 MAC X0,X0,A X:(R2)+,X0
In tight loops the execution speed can often be improved by reshuffling the loop contents and adding code before and after the loop. This allows more code parallelism and decreases pipeline delays. For example, to create an array containing the squares of values in the input array you can code:
Farray square: do #20,L1 move x:(r0)+,x0 mpyr x0,x0,b move b,y(r4)+ L1: void r0,r4,x0,b
Is changed into:
Farray square: move x:(r4)+,x0 mpyr x0,x0,b x:(r4)+,x0 do #19,L1 mpyr x0,x0,b x:(r4)+,x0 b,y(r0)+ L1: move b,y(r0)+
Using DO loop to REP optimization, this can be changed into:
Farray square: move x:(r4)+,x0 mpyr x0,x0,b x:(r4)+,x0 rep #19 mpyr x0,x0,b x:(r4)+,x0 b,y(r0)+ move b,y(r0)+
In fact, one of the loop iterations is taken out of the loop. The assembler then looks for the optimal placement of the loop start and finish and places them back in the resulting code. The loop goes down from three instructions with a pipeline restriction to only one, a gain of a factor four. However, the code size increases slightly despite the improved parallelism.
Restrictions that apply to this optimization are:
- The loop count must be a constant.
- The loop body must contain no more than ten instructions.
- The VOID directive must have been used for registers that can be destroyed due to the optimization.
- In many cases, optimize for speed (OPT OPSPEED) must be selected to allow for a larger code size.
The list file is the output file of the assembler which contains information about the generated code. The amount and form of information depends on the use of the -L option. The name is the basename of the output file with the extension .lst. The list file is only generated when the -l option is supplied. When -l is supplied, a list file is also generated when assembly errors/warnings occur. In this case the error/warning is given just below the source line containing the error/warning.
From EDE you can enable the list file generation by enabling the Generate list file check box in the Output tab of the Project | Assembler Options | Project Options... menu item.
After locating the whole application, an absolute list file can be generated for all assembly source input files with the assembler. To generate an absolute list file from an assembly source file the source code needs to be assembled again with use of the locator map file of the application the assembly source belongs to. See section 11.7, Locator Output, how to produce a locator map file.
An absolute list file contains absolute addresses whereas a standard list file contains relocatable addresses.
When a map file is specified as input for the assembler, only the absolute list file is generated when list file generation is enabled with the list file option -l. The previously generated object file is not overwritten when absolute list file generation is enabled. Absolute list file generation is only enabled when a map file is specified on the input which contains the filename extension .map.
When you want to generate an absolute list file, you
have to specify the same options as you did when generating the object file.
If the options are not the same you might get an incorrect absolute list
file.
Suppose your first invocation was:
as563 -Oj test.src
then when you want to generate an absolute list file you have to specify the same option (-Oj), the -l option and the map file:
as563 -Oj -l test.src test.map
With this command the absolute list file "test.lst" is created.
The page header consists of four lines.
The first line contains the following information:
- information about assembler name
- version and serial number
- copyright notice
The second line contains a title specified by the TITLE (first page) or STITLE (succeeding pages) directive and a page number.
The third line contains the name of the file (first page) or is empty (succeeding pages).
The fourth line contains the header of the source listing as described in the next section.
DSP563xx/6xx assembler va.b rc SNzzzzzzzz-zzz (C)year TASKING, Inc. Title for demo use only page 1 /tmp/hello.asm M:ADDR CODE CYCLES LINE SOURCELINE
The following line appears in the page header:
M:ADDR CODE CYCLES LINE SOURCELINE
The different columns are discussed below.
M:ADDR This is the memory space and location counter. The memory space can be one of P, X, Y or L. The location counter is a (4 digit for DSP5600x, 6 digit for DSP563xx/DSP566xx) hexadecimal number that represents the offset from the beginning of a relocatable section or the absolute address for an absolute section.
M:ADDR CODE CYCLES LINE SOURCELINE . . X:0000 44 org x,".xovl@malloc",overlay: 45 local ss0000 X:0000 46 ss0000: ds 49 | RESERVED X:0030 P:0000 48 org p,".ptext": 49 global Fmalloc 54 Fmalloc: P:0000 05703C rrrrrr 4 4 55 movec ssh,x:ss0000 P:0002 200003 2 6 56 tst a P:0003 0AF0A2 rrrrrr 6 12 57 jne L3
CODE This is the object code generated by the assembler for this source line, displayed in hexadecimal format. By default two columns are present, but you change this with the -L1 or -L0 assembler option to display one code column or even no code column.
M:ADDR CODE CYCLES LINE SOURCELINE . . P:000000 4 org p: | RESERVED P:00007E 5 P:00007F 000000 1 1 6 nop 7 align cache
CYCLES The first number is the number of instruction cycles needed to execute the instruction as generated in the CODE field. The second number is the accumulated cycle count of this section. A number within parentheses is the number of cycles of the previous DO loop.
M:LOC CODE CYCLES LINE SOURCELINE . . P:0000 60F400 rrrrrr 4 4 28 Fmain: move #L3,r0 P:0002 0AF080 rrrrrr 6 10 29 jmp Fputs
M:ADDR CODE CYCLES LINE SOURCELINE P:000000 60F400 000300 2 2 3 move #$300,r0 3 5 4 ; (stall 3 cycles) P:000002 56D800 1 6 4 move x:(r0)+,a
LINE This column contains the line number. This is a decimal number indicating each input line, starting from 1 and incrementing with each source line. If listing of the line is suppressed (i.e. by NOLIST), the number increases by one anyway.
The following source part,
;Line 12 NOLIST ;Line 14 LIST ;Line 16
results in the following list file part (assemled with -LC):
M:ADDR CODE CYCLES LINE SOURCELINE . . 12 ;Line 12 15 LIST 16 ;Line 16
SOURCELINE
This column contains the source text. This is a copy of the source line from the source module. For ease of reading the list file, tabs are expanded with sufficient numbers of blank spaces.
M:ADDR CODE CYCLES LINE SOURCELINE . . 17 MOVE X0,ABYTE as563 E217: /tmp/tst.src line 17 : invalid parallel move as563 W118: /tmp/tst.src line 17 : inserted "extern ABYTE"
When optimizing the source file, the assembler moves and combines instructions. The listing file tries to resemble as much as possible the generated object code. For this the source lines are reordered and changed. The line number associated with a source line in the listing resembles the line number of the line in the source file. As the lines are reordered the line numbers are not strictly increasing. The following examples make things clearer:
M:ADDR CODE CYCLES LINE SOURCELINE P:0095 21C52A 688 asr b ; ( 692) move a,x1 P:0096 21AF00 689 move b1,b P:0097 21E67C 691 sub y1,b ; ( 690) move b,y0
Instructions that are combined with other instructions are shown below the latter instruction. These parallelized instructions are preceded by their line number between parentheses.
M:ADDR CODE CYCLES LINE SOURCELINE P:011D 60F000 rrrrrr 877 move x:ss_psearch+862,r0 P:011F 000000 877 ; nop (inserted) P:0120 205800 879 move (r0)+
When optimizing the assembler removes all NOP instructions and re-inserts them when it cannot reorder the source so that the NOP would be obsolete. Assembler generated NOP instructions have the line number of the instruction causing the restriction and are marked with the text "nop (inserted)".
M:ADDR CODE CYCLES LINE SOURCELINE P:0115 576600 871 move b,x:(r6) 872 L79: P:0116 61F000 rrrrrr 873 move x:ss_psearch+863,r1 P:0118 56F400 000001 872 move #>1,a
When an instruction that was placed after a label is moved to another place the assembler tries to avoid confusion by removing the label before the instruction and removing the instruction after the actual label position. In the example above the line 872 is split in two different lines. Sometimes the assembler cannot construct the source belonging to the actual object, in such cases a label or instruction is mentioned two or more times in the listing file. It is guaranteed that the first occurrence of a label in the listing file is the actual label position. All other occurrences are ghost-occurrences and are not actually generated in the object file.