Search notes:

gcc -march

-march is an option that selects the used Instruction Set Architecture (ISA).
gcc -march=native produces code that is optimized for the CPU that is used to compile the program.
Code produced with -march=native is not backwards compatible, for example, an executable procuded on an Intel Core CPU won't be able to run on an (old) Intel Atom CPU.)
Other possible values for the x86 family are:

prog.c

#include <stdio.h>
int main() {

  int fac_10 =1*2*3*4*5*6*7*8*9*10;

  printf("10! = %d\n", fac_10);

  return 0;
}
Github repository about-gcc, path: /options/m_/arch/prog.c

Makefile

a.out: prog_native.s
	gcc $<

prog_native.s: prog.c Makefile
	gcc -march=native -S $< -o $@
Github repository about-gcc, path: /options/m_/arch/Makefile

TODO

Show enabled and disabled options

gcc -c -Q -march=native --help=target

-march=x86-64-v3

For example, to select the second level, x86-64-v3, a programmer would build a shared object with the -march=x86-64-v3 GCC flag. The resulting shared object needs to be installed into the directory /usr/lib64/glibc-hwcaps/x86-64-v3 or /usr/lib/x86_64-linux-gnu/glibc-hwcaps/x86-64-v3 (in case of dis- tributions with a multi-arch file system layout). In order to support systems that only implement the K8 baseline, a fallback implementation must be installed into the default locations, /usr/lib64 or /usr/lib/x86_64-linux-gnu. It has to be built with -march=x86-64 (the upstream GCC default). If this guideline is not followed, loading the library will fail on systems that do not support the level for which the optimized shared object was built.

-mwindows

Apparently, there is also the possibility to set arch to windows: -mwindows.

Print known architectures

$ gcc --help=target | awk '/Known valid arguments for -march= option/{getline; print}' | xargs -n1 | sort
amdfam10
athlon
athlon-4
athlon64
athlon64-sse3
…
generic
…
i386
i486
i586
i686
…
lakemont
…
native
…
skylake
…
x86-64
x86-64-v2
x86-64-v3
x86-64-v4
…

TODO

Showing default value for -march

$ gcc -Q --help=target | grep -- '-march=  '
  -march=                               x86-64

What is enabled by -march=native

$ gcc               -Q --help=target > /tmp/march-default
$ gcc -march=native -Q --help=target > /tmp/march-native
$ diff -y /tmp/march-default /tmp/march-native

attribute target

Compile a function as though -march=… were used:
__attribute__((target("arch=…"))) int func (…) {
  …
}

See also

-march=cpu-type implies -mtune=cpu-type
-mcpu
-mcpu (which is deprecated for/on x86 or x86-64 systems)
Other -m options
GCC options

Links

resolve-march-native is a command line tool to resolve -march=native into explicit GCC flags.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759398272, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/C-C-plus-plus/GCC/options/m_lowercase/arch(165): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78