XC compilers optimization level

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

XC compilers optimization level

Post by viki2000 »

How do I set the XC compilers optimization level in FC7?

Having the license for professional version of XC8 and XC16 compilers, I need to know how to setup the compilers for PRO version in case of XC8 and different other levels of XC16.
XC8 compiler has 3 levels: free, standard and pro. How do I set it PRO in FC7?
XC16 complier has 5 levels: 0, 1, 2, s and 3. How do I choose the one I need in FC7?

When I use MPLABX with XC8 and XC16, then specific for each project I set up the desired level of optimization as seen below:
XC8
XC8
XC8 optimizations - MPLABX.jpg (227.45 KiB) Viewed 8519 times
XC16
XC16
XC16 optimizations - MPLABX.jpg (242.75 KiB) Viewed 8519 times
Here is the help text from MPLABX about XC8 optimization levels:
This option selects the basic operating mode of the compiler. The available types are pro, std and free. A compiler operating in PRO mode uses full optimization and produces the smallest code size. Standard mode uses limited optimizations, and Free mode only uses a minimum optimization level and will produce relatively large code.


Here is the help text from MPLABX about XC16 optimization levels:
- 0 - Do not optimize. The compiler’s goal is to reduce the cost of compilation and to make debugging produce the expected results.
- 1 - Optimize. Optimizing compilation takes somewhat longer, and a lot more host memory for a large function. The compiler tries to reduce code size and execution time.
- 2 - Optimize even more. The compiler performs nearly all supported optimizations that do not involve a space-speed trade-off.
- s - Optimize yet more favoring size (superset of O2).
- 3 - Optimize yet more favoring speed (superset of O2).
I already have read next posts:
viewtopic.php?f=63&t=17843&p=75494&hili ... ion#p75494
viewtopic.php?f=63&t=17978&p=76229&hili ... ion#p76229

Seems clear how to point to XC8 external compiler, but how do I set up the optimizations levels, especially for XC16?

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: XC compilers optimization level

Post by Benj »

Hello,

For the 8-bit PICs the optimisation parameter can be specified in the Compiler Options -> Compiler -> Parameters.

The default settings look like this.
--chip=$(chip) "$(target).c" --MSGDISABLE=359,1273,1388
Simply add the required level of optimisation to the parameters.

For example,
--chip=$(chip) "$(target).c" --MSGDISABLE=359,1273,1388 --OPT=all


For the 16-bit PICs you need to edit the batch file that does the compilation.

This is located in the "Flowcode 7\compilers\pic16\batchfiles" folder.

pic16_C30_comp.bat has this line.
xc16-gcc -c -mcpu=%3 -omf=coff -funsigned-char -fno-short-double -Os -I"%~dp0..\support\h" -I"%~dp0" -std=gnu99 %1.c -o %1.o
Change the -Os for the level of optimisation you require.

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: XC compilers optimization level

Post by viki2000 »

Thank you very much for the explanations.
If I install the latest versions of the XC compilers and I do not install with overwrite in Flowcode 7 folder, but in Microchip folder, then I need your help to show how to point to the compilers.
I think for XC8 was explained in one of the links above, but I do not mind if you explain it here one more time with clear steps.
How about XC16?
There is no “batchfiles” folder in the default folder where the new XC compilers are installed.
Shall I copy the “batchfiles” folder from Flowcode 7 folder to Microchip folder? Or what is the best procedure when the external XC compilers are used?

For example, in my PC here are the default folders for XC compilers in Flowcode 7:
XC16:
C:\Program Files (x86)\Flowcode 7\compilers\pic16\batchfiles
XC8:
C:\Program Files (x86)\Flowcode 7\compilers\pic\bin

And here are the default folders where XC compilers are installed when we download new from Microchip:
XC16:
C:\Program Files (x86)\Microchip\xc16\v1.31
XC8:
C:\Program Files (x86)\Microchip\xc8\v1.42\bin

How to point to them? How to use them? And what do we do for optimization, especially the non-existent “batchfiles” folder?

viki2000
Posts: 190
Joined: Mon Jul 07, 2014 9:38 am
Has thanked: 30 times
Been thanked: 77 times
Contact:

Re: XC compilers optimization level

Post by viki2000 »

The probelm is solved.

For XC8:
FC7 – BUILD – Compiler Options – PIC – Compiler
Location:
C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe
Parameters:
--chip=$(chip) "$(target).c" --MSGDISABLE=359,1273,1388 --OPT=all

It asked me to save with a new name these settings, I named it xc8 and appears under PIC, under Default on left side of the Compiler Options window.


For XC16:
Copy the folder „batchfiles“ from
C:\Program Files (x86)\Flowcode 7\compilers\pic16
to
C:\Program Files (x86)\Microchip\xc16\v1.31

Edit as suggested above „pic16_C30_comp.bat“
in the line:
xc16-gcc -c -mcpu=%3 -omf=coff -funsigned-char -fno-short-double -Os -I"%~dp0..\support\h" -I"%~dp0" -std=gnu99 %1.c -o %1.o

and change -Os with –O3 or -O2 as needed.
In my case I had to save the file „pic16_C30_comp.bat“ somewhere else, on Desktop, edit there, save there and then copy/overwrite from Desktop in the folder :
C:\Program Files (x86)\Microchip\xc16\v1.31\batchfiles
I could not edit/save directly in the folder above.

FC7 – BUILD – Compiler Options – PIC16 – Compiler
Location:
C:\Program Files (x86)\Microchip\xc16\v1.31\batchfiles\pic16_C30_comp.bat
Parameters:
"$(target)" "$(outdir)" "$(chip:u)"

FC7 – BUILD – Compiler Options – PIC16 – Linker/Assembler
Location:
C:\Program Files (x86)\Microchip\xc16\v1.31\batchfiles\pic16_C30_link.bat
Parameters:
"$(outdir)$(target)" $(chip:u) $(family)

It asked me to save with a new name these settings, I named it xc16 and appears under PIC16, under Default on left side of the Compiler Options window.

Post Reply