macos - gcc 11.3.0 on macOS/Apple Silicon 和 SHA-3 指令

标签 macos gcc arm64

我在配备 Apple Silicon M1 CPU 的 MacBook Air 上使用 Homebrew 安装了 gcc 11.3.0。二进制文件是 aarch64 native 版本,不是 Rosetta 模拟的。安装的操作系统是 macOS Monterey 12.3。

我在编译使用 M1 CPU 支持的 ARMv8.2-A SHA-3 扩展指令的程序时遇到问题。这是一个最小的可重现示例:

#include <arm_neon.h>

int main() {
    uint64x2_t a = {0}, b = {0}, c = {0};
    veor3q_u64(a, b, c);
    return 0;
}

这段代码使用 Apple 提供的 clang 编译器编译得很好。

我使用以下 gcc 11 命令行编译它:

gcc-11 -o test test.c -march=armv8-a+sha3

这会导致以下错误:

In file included from test.c:1:
test.c: In function 'main':
/opt/homebrew/Cellar/gcc/11.3.0/lib/gcc/11/gcc/aarch64-apple-darwin21/11/include/arm_neon.h:32320:1: error: inlining failed in call to 'always_inline' 'veor3q_u64': target specific option mismatch
32320 | veor3q_u64 (uint64x2_t __a, uint64x2_t __b, uint64x2_t __c)
      | ^~~~~~~~~~
test.c:5:5: note: called from here
    5 |     veor3q_u64(a, b, c);
      |     ^~~~~~~~~~~~~~~~~~~

这是这个特定硬件/软件组合中的错误,还是有一些命令行选项我可以传递给 gcc 来编译这个特定程序?

最佳答案

问题解决了。事实证明,gcc 需要 -march=armv8.2-a+sha3 而不仅仅是 -march=armv8-a+sha3 来编译这个内在函数。实际上,在 gcc 版本的 arm_neon.h 中,可以在包含 veor3q_u64 的内部函数 block 之前找到它:

#pragma GCC target ("arch=armv8.2-a+sha3")

关于macos - gcc 11.3.0 on macOS/Apple Silicon 和 SHA-3 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72100202/

相关文章:

cocoa - FSEvents 神秘地无法传递某些文件夹中的事件

python - 扭曲关闭事件未触发

c++ - 宏调用中的 #ifdef 适用于 gcc 但不适用于 msvc

创建静态 Mac OS X C 构建

linux - ARMv8 - 在 64 位操作系统上运行传统的 32 位应用程序

macos - 强制自己掌握 Emacs

XCode库搜索路径

c - GCC 将所有字符串存储在 .rodata 中

assembly - 有什么方法可以缩短 AArch64 汇编中的机器代码 Hello World 吗?

ios - iPhone应用程序是否可以使用iPhone 5或更高版本?