avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by Artcfox »

I downloaded a whole bunch of Atmel's official AVR 8-bit GNU Toolchain versions, and compiled Bugz using each version, and gathered statistics on how small the resulting binary is, how much memory it uses, and how many clocks it take to generate each frame of a deterministic level.

Spoiler: gcc version 4.8.1 (AVR_8_bit_GNU_Toolchain_3.4.3_1072) beat every other version I tested both in terms of smallest binary size, and fastest code execution.

Here are the results:

Code: Select all

gcc version 4.9.2 (AVR_8_bit_GNU_Toolchain_3.5.0_1662)

AVR Memory Usage

Program:   57888 bytes (88.3% Full)
Data:       3567 bytes (87.1% Full)

Cycles Per Frame

Min:       8234
Max:       8797
Average:   8628.83

Code: Select all

gcc version 4.8.1 (AVR_8_bit_GNU_Toolchain_3.4.3_1072)

AVR Memory Usage

Program:   57030 bytes (87.0% Full)
Data:       3561 bytes (86.9% Full)

Cycles Per Frame

Min:       7910   
Max:       8439   
Average:   8007.99

Code: Select all

gcc version 4.7.2 (AVR_8_bit_GNU_Toolchain_3.4.2_939)

AVR Memory Usage

Program:   57344 bytes (87.5% Full)
Data:       3563 bytes (87.0% Full)

Cycles Per Frame

Min:       8083   
Max:       8632   
Average:   8318.91

Code: Select all

gcc version 4.6.2 (AVR_8_bit_GNU_Toolchain_3.4.1_798)
UNSUPPORTED: -mstrict-X -maccumulate-args

AVR Memory Usage

Program:   59060 bytes (90.1% Full)
Data:       3563 bytes (87.0% Full)

Cycles Per Frame

Min:       9621  
Max:       9951  
Average:   9753.9

Code: Select all

gcc version 4.5.1 (AVR_8_bit_GNU_Toolchain_3.2.3_314)
UNSUPPORTED: -mstrict-X -maccumulate-args

AVR Memory Usage

Program:   59486 bytes (90.8% Full)
Data:       3565 bytes (87.0% Full)

Cycles Per Frame

Min:       9095   
Max:       9396   
Average:   9215.11
I use function pointers quite a bit in my code, and so far I haven't seen a problem with them, but I'll continue to test this version. Atmel released more than one version of their official toolchain based on gcc 4.8.1, and I tried them starting from newest to oldest until I found one that worked (AVR_8_bit_GNU_Toolchain_3.4.3_1072).

The resulting binary that avr-gcc 4.8.1 produces is small enough that I was able to switch my Makefile optimizations from using a mixture of -Os and -O2, to a mixture of -O2 and -O3 to shave off even more cycles per frame, resulting in:

Code: Select all

Cycles Per Frame (with -O2 and -O3 optimizations)

Min:       7871	 
Max:       8151	 
Average:   7965.3
while still being small enough to fit with the bootloader.
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by D3thAdd3r »

These are very interesting results thank you for this detailed analysis. I guess I am sticking with 4.8.1.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by Artcfox »

D3thAdd3r wrote:These are very interesting results thank you for this detailed analysis. I guess I am sticking with 4.8.1.
You might get different results depending on what you compile. Since 4.6.2 and 4.5.1 don't support the:

Code: Select all

-mstrict-X -maccumulate-args
compile flags, I would say it isn't worth having those versions installed, but I'm thinking that it might be good to keep 4.9.2, 4.8.1, and 4.7.2 installed to see which gives the best results.

For compiling Tornado2000, 4.9.2 gives the best (and more importamtly, correct!) results. So I guess the lesson is YMMV.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by uze6666 »

I'd be curious to see how newer versions fares compared to the one you tested years ago.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by Artcfox »

I tried this for danboid in another thread, and found that the really ancient toolchains will not run on newer Debian versions, but you can always boot up an old version of Debian inside a VM to run them. For the newest, GCC 7.3.0, it tends to make noticablely smaller binaries when you use -Os versus GCC 5.4.0 with the same flags. I haven't really been able to compare the generated ASM with -O3 because so much is inlined it was hard to parse the output.
CunningFellow
Posts: 1445
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by CunningFellow »

I just installed 7.3.0 (latest from microchip) and ran a comparison on T2K which I was using 4.9.2 on.

Free space went from 2110 to 2860. A saving of 750 bytes. Or given how much is C code and how much is ASM/DATA it makes a saving in space of over 5%
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by Artcfox »

CunningFellow wrote: Sun Mar 05, 2023 3:52 am I just installed 7.3.0 (latest from microchip) and ran a comparison on T2K which I was using 4.9.2 on.

Free space went from 2110 to 2860. A saving of 750 bytes. Or given how much is C code and how much is ASM/DATA it makes a saving in space of over 5%
That is a huge space savings!


Continued from other thread:
ry755 wrote: Sun Mar 05, 2023 3:31 am
Artcfox wrote: Sun Mar 05, 2023 2:14 am I wonder if that has all of the Atmel (now Microchip) patches applied, since the latest official version on Microchip's website is 7.3.0. One example that used to be different is the avr-objdump command has extra parameters specific to AVR chips. I'm not on a computer now but IIRC one of the specific parameters is -A.
Interesting, `avr-objdump -A` returns this: ("<help output>" added by me)

Code: Select all

$ avr-objdump -A
avr-objdump: invalid option -- 'A'
<help output>
At the end of the listed help output, it says this:

Code: Select all

avr-objdump: supported targets: elf32-avr elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex plugin
avr-objdump: supported architectures: avr avr:1 avr:2 avr:25 avr:3 avr:31 avr:35 avr:4 avr:5 avr:51 avr:6 avr:100 avr:101 avr:102 avr:103 avr:104 avr:105 avr:106 avr:107
Anyways this is getting off-topic so we should probably move to the avr-gcc thread.
Sorry, I just looked at my Makefile, and it is the avr-size command that is patched to have the -A argument. If avr-size complains about missing that argument it would make me wonder if any of the AVR-specific patches that Atmel/Microchip uses have been applied to the toolchain in question. I would hope by now that they upstreamed all of their changes, but in the past it wasn't, and building a toolchain manually (or for a distro) involved applying all of their patches, but a lot of them wouldn't apply cleanly to newer versions.
User avatar
danboid
Posts: 1935
Joined: Sun Jun 14, 2020 12:14 am

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by danboid »

I have emailed the Debian gcc-avr maintainer to ask if there is a reason for Debian packaging such an old version, 5.4.0. I pointed out Fedora (and Arch) provide gcc-avr 12.2.0.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by Artcfox »

danboid wrote: Sun Mar 05, 2023 5:21 pm I have emailed the Debian gcc-avr maintainer to ask if there is a reason for Debian packaging such an old version, 5.4.0. I pointed out Fedora (and Arch) provide gcc-avr 12.2.0.
In the past I have gone through the process of compiling the entire AVR toolchain from source code in order to try out the newest versions of GCC, but without the Atmel-specific patches (that did not apply cleanly to the latest version) the code it generated was not as good, so I quickly abandoned that idea.
CunningFellow
Posts: 1445
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: avr-gcc versions compared: 4.9.2, 4.8.1, 4.7.2, 4.6.2, 4.5.1

Post by CunningFellow »

I recall "Sprinter" from the AVRFreaks forum saying that at one point a few years ago that GCC had changed something fundamental in how it worked.
It made optimisation better for giant super scalar CPU but made it worse for AVR.

That might be the reason the official version stopped at 7.3.0
Post Reply