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

Why does march=native not work on Apple M1?(为什么 March=native 在 Apple M1 上不起作用?)

本文介绍了为什么 March=native 在 Apple M1 上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试在带有 M1 芯片的 Macbook 上使用 march=native 编译任何 C++ 程序时,我在使用 clang 时都会收到以下错误:

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'

但是,它曾经可以在配备 Intel CPU 的旧款 Macbook 上运行.clang 不支持这种架构(还)吗?

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

clang --version 给出:

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.2.0

推荐答案

据我所知,这不是 Apple M1 特定的,它也发生在用于各种其他架构的 clang(主要是各种其他 arm处理器).例如在此处查看此错误报告 https://github.com/DMOJ/judge-server/issues/303

As far as I know this is not Apple M1 specific, it occurs also with clang for various other architectures (mostly various other arm processors). e.g. See this bug report here https://github.com/DMOJ/judge-server/issues/303

基本上每个新架构的 clang 构建都必须选择为march=native"提供默认值;对于编译器构建与否的目标;如果没有,那么您将看到此错误消息.即使对于那些确实有优化目标的 arm 处理器,您通常也必须专门使用-mcpu=xxx";而不是-march".

Basically every build of clang for a new architecture must choose to provide defaults for "march=native" for the target for which the compiler is built or not; and if not then you will see this error message. Even for those arm processors who do have optimisation targets you often have to use specifically "-mcpu=xxx" instead of "-march".

例如对于 iphone,您将使用 -mcpu=apple-a11 -mcpu=apple-a12 等.

e.g. For the iphone you would use -mcpu=apple-a11 -mcpu=apple-a12 etc.

然而,Apple M1

这篇关于为什么 March=native 在 Apple M1 上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:为什么 March=native 在 Apple M1 上不起作用?

基础教程推荐