为什么March=native在AppleM1上不起作用?

每当我尝试march=native在带有 M1 芯片的 Macbook 上编译任何 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

  • The closest option to use at the time of writing is `-mcpu=lightning`, which optimizes for an A13, which gives the compiler access to ARMv8.4-A instructions.

以上是为什么March=native在AppleM1上不起作用?的全部内容。
THE END
分享
二维码
< <上一篇

)">
下一篇>>