Yes, I suggested it, but it is not best practice. Better practice is to override symbols originally defined in the Makefile itself with command line over-rides; in this regime, do not edit the Makefile.
In particular, override the symbol for cc optimization flags: OPT_CFLAGS
, so your make
command discards the previous definition (in the Makefile) and replaces it with that found on the command line. In accordance with this example:
make cli OPENMP_CFLAGS="" OPENMP_LIBS="" OPT_CFLAGS="-03 -mtune=cortex-a55"
Perhaps smarter than my first example in 3.4.0 filters issue… Post #9 would be:
$ gcc -c -Q -march=native -mtune=native --help=target | sed 's/[[:space:]]*//g' | grep -E 'march=|mtune='
-march=znver4
-mtune=znver4
Knownvalidargumentsfor-march=option:
Knownvalidargumentsfor-mtune=option:
(znver4
is peculiar to AMD processors, here an AMD Ryzen 9 7950X3D.)
That is, first pipe to the stream editor (sed
) to remove all white space (as defined by your language locale); this minimizes the possibility of line wrapping on narrow Android phone displays. Then the output of the white-space-stripped stream is piped to the pattern matcher, which finds only those lines with either march=
or mtune=
patterns. This should dramatically cut down on the volume of text one has to search through.
Commonly, -march
and -mtune
appear together but sometimes -mtune
is omitted. -march
chooses an Instruction Set Architecture (ISA). Choosing an ISA does not induce the compiler to actually optimize the resulting assembly language in an ISA-specific way. that is what -mtune
asks for. It is a bit unusual to specify -mtune
without also explicitly choosing -march.
To illustrate:
gosgood@bertha ~ $ gcc -c -Q -mtune=native --help=target | sed 's/[[:space:]]*//g' | grep -E 'march=|mtune='
-march=x86-64
-mtune=znver4
Knownvalidargumentsfor-march=option:
Knownvalidargumentsfor-mtune=option:
If I were to use only a -mtune=znver4
compiler option, then the ISA in play, x86-64
, would only include the most common assembly language instructions of Intel / AMD processors, for which I am asking for optimizations for a Ryzen 9 7950X3D processor — but I have excluded the assembly language instructions specific to the 7950X3D processor, so my optimizations are probably not going to be very optimal. In light of that, you probably would want to amend your tutorial to include both -march
and -mtune
switches.
There will be those out there who couldn’t be arsed for searching through anything. For those folk, there could be this command line:
make cli OPENMP_CFLAGS="" OPENMP_LIBS="" OPT_CFLAGS="-03 -march=native -mtune=native"
which means ‘pick my ISA for me, (I don’t really want to know what it is) and optimize the assembly language instructions for it, (whatever that may be).’ They wouldn’t make use of $ gcc -c -Q -mtune=native --help=target…
at all and avoid trying to make sense of its output.
That could be quicker, but if errors like this crops up:
x86_64-pc-linux-gnu-g++: error: 03: linker input file not found: No such file or directory
then a more deliberative and careful setting of -march
and -mtune
is called for, and the fellow looking for a fast get-a-way will have to look these up through gcc -c -Q -march=native -mtune=native --help=target
output.