为什么 march=native 在 Apple M1 上不起作用?
Why does march=native not work on Apple M1?
每当我尝试在带有 M1 芯片的 Macbook 上用 march=native
编译任何 C++ 程序时,我在使用 clang 时收到以下错误:
clang: error: the clang compiler does not support '-march=native'
但是,它曾经在配备 Intel CPU 的旧款 Macbook 上运行。 clang 是否不支持这种架构(还)?
clang --version
给出:
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.2.0
据我所知,这不是 Apple M1
特有的,对于各种其他架构(主要是各种其他 arm 处理器),它也会出现在 clang 中。
例如在此处查看此错误报告 https://github.com/DMOJ/judge-server/issues/303
基本上,每次为新架构构建 clang 时,都必须选择为编译器构建或不构建的目标提供默认的“march=native”;如果没有,那么您将看到此错误消息。即使对于那些确实具有优化目标的 arm 处理器,您通常也必须专门使用“-mcpu=xxx”而不是“-march”。
例如对于 iphone,您将使用 -mcpu=apple-a11
-mcpu=apple-a12
等
但是 Apple M1
尚未实现此类目标
$ 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
可能是 M1 的最佳选择。
在 Apple clang 版本 13.0.0 中,-mcpu=apple-m1
现已可用。
每当我尝试在带有 M1 芯片的 Macbook 上用 march=native
编译任何 C++ 程序时,我在使用 clang 时收到以下错误:
clang: error: the clang compiler does not support '-march=native'
但是,它曾经在配备 Intel CPU 的旧款 Macbook 上运行。 clang 是否不支持这种架构(还)?
clang --version
给出:
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.2.0
据我所知,这不是 Apple M1
特有的,对于各种其他架构(主要是各种其他 arm 处理器),它也会出现在 clang 中。
例如在此处查看此错误报告 https://github.com/DMOJ/judge-server/issues/303
基本上,每次为新架构构建 clang 时,都必须选择为编译器构建或不构建的目标提供默认的“march=native”;如果没有,那么您将看到此错误消息。即使对于那些确实具有优化目标的 arm 处理器,您通常也必须专门使用“-mcpu=xxx”而不是“-march”。
例如对于 iphone,您将使用 -mcpu=apple-a11
-mcpu=apple-a12
等
但是 Apple M1
$ 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
可能是 M1 的最佳选择。
在 Apple clang 版本 13.0.0 中,-mcpu=apple-m1
现已可用。