在预处理器中检测 ARM NEON 的可用性? [英] Detect ARM NEON availability in the preprocessor?

查看:37
本文介绍了在预处理器中检测 ARM NEON 的可用性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据ARM ARM, __ARM_NEON__ 在 Neon SIMD 指令可用时定义.我无法让 GCC 提供它.

According to the ARM ARM, __ARM_NEON__ is defined when Neon SIMD instructions are available. I'm having trouble getting GCC to provide it.

Neon 在这个运行 Debian 8.2 的 BananaPi Pro 开发板上可用:

Neon available on this BananaPi Pro dev board running Debian 8.2:

$ cat /proc/cpuinfo | grep neon
Features    : swp half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt 

我使用的是 GCC 4.9:

I'm using GCC 4.9:

$ gcc --version
gcc (Debian 4.9.2-10) 4.9.2

尝试 GCC 和 -march=native:

$ g++ -march=native -dM -E - </dev/null | grep -i neon
#define __ARM_NEON_FP 4

好的,试试 Google 在为 Neon 构建时为 Android 使用的东西:

OK, try what Google uses for Android when building for Neon:

$ g++ -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -dM -E - </dev/null | grep -i neon
#define __ARM_NEON_FP 4

也许是带有硬浮点数的 ARMv7-a:

Maybe a ARMv7-a with a hard float:

$ g++ -march=armv7-a -mfloat-abi=hard -dM -E - </dev/null | grep -i neon
#define __ARM_NEON_FP 4

我的问题是:

  • 为什么我没有看到 __ARM_NEON__?
  • 如何检测预处理器中的 Neon 可用性?

也许:

  • 应该使用哪些 GCC 开关来启用 Neon SIMD 指令?

相关,在 LeMaker HiKey 上,这是运行 Linaro 和 GCC 的 AARCH64/ARM644.9.2,这是预处理器的输出:

Related, on a LeMaker HiKey, which is AARCH64/ARM64 running Linaro with GCC 4.9.2, here's the output from the preprocessor:

$ cpp -dM </dev/null | grep -i neon
#define __ARM_NEON 1

根据 ARM 的说法,这块板确实有高级 SIMD 指令:

According to ARM, this board does have Advanced SIMD instructions even though:

$ cat /proc/cpuinfo 
Processor   : AArch64 Processor rev 3 (aarch64)
...
Features    : fp asimd evtstrm aes pmull sha1 sha2 crc32

推荐答案

这里隐藏了很多问题,我会试着依次提取出来...

There are a number of questions hidden in here, I'll try to extract them in turn...

根据ARM ARM,__ARM_NEON__ 是在Neon SIMD 指令可用时定义的.我无法让 GCC 提供它.

According to the ARM ARM, __ARM_NEON__ is defined when Neon SIMD instructions are available. I'm having trouble getting GCC to provide it.

那是 ARM 编译器 [旧版本] 的编译器文档,而不是 ARM 架构参考手册.用于检查高级 SIMD 指令是否存在的更好的宏是 __ARM_NEON,它在 ARM C 语言扩展.

That is compiler documentation for [an old version of] the ARM Compiler rather than the ARM Architceture Reference Manual. A better macro to check for the presence of the Advanced SIMD instructions would be __ARM_NEON, which is defined in the ARM C Language Extensions.

尝试 GCC 和 -march=native:

正如您可能已经发现.ARM 目标的 GCC 将 -march(对于 GCC 应为其生成代码的体系结构修订版)、-mfpu(对于可用的浮点/高级 SIMD 单元)和-mfloat-abi(关于应该如何传递浮点参数,以及是否存在浮点单元).最后是 -mtune(它要求 GCC 尝试针对特定处理器进行优化)和 -mcpu(作为 -mtune 的组合> 和 -march).

As you may have found. GCC for the ARM target separates out -march (For the architecture revision for which GCC should generate code), -mfpu (For the floating point/Advanced SIMD unit available) and -mfloat-abi (For how floating point arguments should be passed, and for the presence or absence of a floating point unit). Finally there is -mtune (Which asks GCC to try to optimise for a particular processor) and -mcpu (which acts as a combination of -mtune and -march).

通过要求 -march=native 您要求 GCC 生成适合检测到的您正在运行的处理器架构的代码.这对 -mfpu 设置没有影响,因此不一定启用高级 SIMD 指令生成.

By asking for -march=native You're asking GCC to generate code appropriate for the detected architecture of the processor on which you are running. This has no impact on the -mfpu setting, and so does not necessarily enable Advanced SIMD instruction generation.

请注意,以上仅适用于面向 AArch32 的编译器.AArch64 GCC 不支持 -mfpu,将通过 -march=native 检测是否存在高级 SIMD 支持.

Note that the above only applies to a compiler targeting AArch32. The AArch64 GCC does not support -mfpu and will detect presence of Advanced SIMD support through -march=native.

好的,试试 Google 在为 Neon 构建时为 Android 使用的东西:

OK, try what Google uses for Android when building for Neon:

$ g++ -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -dM -E

这些构建标志不足以支持高级 SIMD 指令,您的注释可能不完整.-mfpu 支持的标志 通过 GCC 4.9.2 我期望:

These build flags are not sufficient to enable support for Advanced SIMD instructions, your notes may be incomplete. Of the -mfpu flags supported by GCC 4.9.2 I'd expect any of:

neonneon-fp16neon-vfpv4neon-fp-armv8crypto-neon-fp-armv8

给你你想要的.

根据 ARM 的说法,这块板确实有高级 SIMD 指令:

According to ARM, this board does have Advanced SIMD instructions even though:

看起来您在 AArch64 内核上运行,该内核通过 asimd 功能公开了对高级 SIMD 的支持 - 如您的示例输出所示.

Looks like you're running on an AArch64 kernel, which exposes support for Advanced SIMD through the asimd feature - as in your example output.

这篇关于在预处理器中检测 ARM NEON 的可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆