Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does march=native not work on Apple M1?

Whenever I try to compile any C++ program with march=native on a Macbook with a M1 chip, I get the following error when using clang:

clang: error: the clang compiler does not support '-march=native'

However, it used to work on an older Macbook with an Intel CPU. Does clang not support this architecture (yet)?

clang --version gives:

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.2.0
like image 458
Momo Avatar asked Jan 30 '21 10:01

Momo


2 Answers

In Apple clang version 13.0.0, -mcpu=apple-m1 is now available.

like image 142
champagniac Avatar answered Oct 13 '22 04:10

champagniac


$ clang --print-supported-cpus
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Available CPUs for this target:

    a64fx
    apple-a10
    apple-a11
    apple-a12
    apple-a13
    apple-a14
    apple-a7
    apple-a8
    apple-a9
    apple-latest
    apple-s4
    apple-s5
    carmel
    cortex-a34
    cortex-a35
    cortex-a53
    cortex-a55
    cortex-a57
    cortex-a65
    cortex-a65ae
    cortex-a72
    cortex-a73
    cortex-a75
    cortex-a76
    cortex-a76ae
    cortex-a77
    cortex-a78
    cortex-x1
    cyclone
    exynos-m3
    exynos-m4
    exynos-m5
    falkor
    generic
    kryo
    lightning
    neoverse-e1
    neoverse-n1
    saphira
    thunderx
    thunderx2t99
    thunderx3t110
    thunderxt81
    thunderxt83
    thunderxt88
    tsv110
    vortex

-mcpu=apple-a14 might be the best one for M1.

like image 13
Guanyang Xue Avatar answered Oct 13 '22 04:10

Guanyang Xue