Vanfanel
Posts: 433
Joined: Sat Aug 18, 2012 5:58 pm

What C/CXX FLAGS does -march=native activate on a Rpi3?

Mon Apr 02, 2018 12:05 am

That's about it.

I am building some software on the Pi3 with the latest Raspbian/GCC combination, and I need to know what GCC flags does -march=native produce on the Pi3. I take it should be something like "-O3 -mcpu=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard", but I am starting to suspect it's likely using Pi1 flags instead...
Am I right?

jahboater
Posts: 4468
Joined: Wed Feb 04, 2015 6:38 pm

Re: What C/CXX FLAGS does -march=native activate on a Rpi3?

Mon Apr 02, 2018 1:02 am

Compile with -S and look at the header at the start of the .s file.
You should see ".arch" and ".fpu" directives.

Mine says

.arch armv8-a
.fpu neon-fp-armv8

but it is gcc 7.3 that I installed myself.

User avatar
Paeryn
Posts: 2570
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: What C/CXX FLAGS does -march=native activate on a Rpi3?

Mon Apr 02, 2018 1:36 am

Using -march= wouldn't set the optimisation level, that would be wrong. -march= is equivalent to doing both a -mcpu= and a -mtune= with their corresponding values for the architecture.

The version of the compiler (6.3.0) in Raspbian Stretch is the updated version that fixed the bug in the native detection but the code hasn't had the ARMv8 cpus added to its list of known variants so it will default back to using what the compiler was set up to target by default when it sees that the cpu is a Cortex-A53 (or any other that the native detection code doesn't know about). The compiler can happily be set to target the Cortex-A53, it's just the routine that re-writes the option from native to whatever value it should be that is lacking knowledge of ARMv8 cpus.

You will need to specify the architecture (and/or cpu / tune) yourself when compiling on the RPi3 (and the RPi2 v1.2 which uses the same SoC).
She who travels light — forgot something.

Vanfanel
Posts: 433
Joined: Sat Aug 18, 2012 5:58 pm

Re: What C/CXX FLAGS does -march=native activate on a Rpi3?

Mon Apr 02, 2018 9:54 am

Thanks, solved. It seems default 6.3.0 it's still using Pi1 flags...

jahboater
Posts: 4468
Joined: Wed Feb 04, 2015 6:38 pm

Re: What C/CXX FLAGS does -march=native activate on a Rpi3?

Mon Apr 02, 2018 10:56 am

Vanfanel wrote:
Mon Apr 02, 2018 9:54 am
It seems default 6.3.0 it's still using Pi1 flags...
Yes exactly.

I build gcc with:

Code: Select all

../configure -v --enable-languages=c,c++ --with-cpu=cortex-a53 \
  --with-fpu=neon-fp-armv8 --with-float=hard --build=arm-linux-gnueabihf \
  --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
to get a modern compiler (7.3) targeting the Pi3(+) by default.

User avatar
scruss
Posts: 2272
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: What C/CXX FLAGS does -march=native activate on a Rpi3?

Mon Apr 02, 2018 3:38 pm

… for good reasons, though. In an educational setup with mixed Raspberry Pi boards, a small performance hit is worth keeping binary compatibility.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “C/C++”