Page 1 of 1

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

Posted: Mon Apr 02, 2018 12:05 am
by Vanfanel
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?

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

Posted: Mon Apr 02, 2018 1:02 am
by jahboater
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.

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

Posted: Mon Apr 02, 2018 1:36 am
by Paeryn
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).

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

Posted: Mon Apr 02, 2018 9:54 am
by Vanfanel
Thanks, solved. It seems default 6.3.0 it's still using Pi1 flags...

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

Posted: Mon Apr 02, 2018 10:56 am
by jahboater
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.

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

Posted: Mon Apr 02, 2018 3:38 pm
by scruss
… for good reasons, though. In an educational setup with mixed Raspberry Pi boards, a small performance hit is worth keeping binary compatibility.