We are trying to do validation for the C2000 compiler and we use optimization level 4.
Can you give us an example code snippet that would be optimized by level 4?
We need a way to prove the setting is active.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
We are trying to do validation for the C2000 compiler and we use optimization level 4.
Can you give us an example code snippet that would be optimized by level 4?
We need a way to prove the setting is active.
Please consider this example.
C:\examples>type f1.c
int gets_inlined();
int main()
{
return gets_inlined();
}
C:\examples>type f2.c
int gets_inlined()
{
return 0x1234;
}
C:\examples>cl2000 f1.c f2.c -z -o no_opt.out
[f1.c]
[f2.c]
<Linking>
C:\examples>dis2000 no_opt.out > no_opt_dis.txt
The first two commands show the source files. The third command builds those files into a program. (Because it uses the linker default memory ranges, it is nearly certain to not run on your system.) The fourth command disassembles the program into the file no_opt_dis.txt. Inspect that file and search for the function main ...
00000118 _main: 00000118 7640 LCR 0x00011b 00000119 011b 0000011a 0006 LRETR 0000011b _gets_inlined: 0000011b 28a9 MOV AL, #0x1234 0000011c 1234 0000011d 0006 LRETR
The LCR instruction performs a call. The operand is the address of the called function. In this case, it calls the function gets_inlined at address 0x11b. The function gets_inlined returns the value 0x1234 in the low half of the accumulator.
Build again, but with optimization level 4. Then disassemble into the file opt4_dis.txt.
C:\examples>cl2000 --opt_level=4 f1.c f2.c -z -o opt4.out [f1.c] [f2.c] <Linking> C:\examples>dis2000 opt4.out > opt4_dis.txt
Inspect opt4_dis.txt and search for the function main ...
0000010e _main: 0000010e 28a9 MOV AL, #0x1234 0000010f 1234 00000110 0006 LRETR
Now main doesn't call any functions, and it returns the value 0x1234.
Thanks and regards,
-George
Thanks George! We had to add the path for the RTS libs to get it to compile but it otherwise worked!
Do you have examples for the other optimization levels also? Our validation group wants to test the other optimization levels too.
Do you have examples for the other optimization levels also?
Unfortunately, no.
However, now that you have a general idea of how to see optimizations occur, you can probably create your own. For some guidance on what other optimizations are performed, please search the C28x compiler manual for the sub-chapter titled What Kind of Optimization Is Being Performed. To see what optimizations are performed at what level, search the same manual for the sub-chapter titled Invoking Optimization.
Thanks and regards,
-George