为什么__ARM_FEATURE_CRC32不是由编译器定义的? [英] Why is __ARM_FEATURE_CRC32 not being defined by the compiler?

查看:2206
本文介绍了为什么__ARM_FEATURE_CRC32不是由编译器定义的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直对这个问题有一段时间了,我希望有人能指出我的错误。我想我再也看不到森林穿过树林。

我有一个 LeMaker HiKey 开发板我用于测试。其AArch64,所以其具有NEON和其他CPU的功能,如AES,SHA和CRC32:

  $执行cat / proc内/ cpuinfo
处理器:AArch64处理器转3(aarch64)
...
特点:FP asimd evtstrm AES pmull SHA1 SHA2 CRC32
...

当我尝试编译的程序:

  $猫test.cxx
#如果(定义(__ ARM_NEON__)||定义(__ ARM_NEON))
#定义NEON_INTRINSICS_AVAILABLE 1
#其他
#定义NEON_INTRINSICS_AVAILABLE 0
#万一#如果BOOL_NEON_INTRINSICS_AVAILABLE
#包括LT&;&arm_neon.h GT;
#如果定义(__ ARM_FEATURE_CRC32)|| (__ARM_ACLE> = 200)
#包括LT&;&arm_acle.h GT;
# 万一
#万一#包括LT&;&stdint.h GT;INT主(INT ARGC,CHAR *的argv [])
{
  uint32_t的CRC = 0;  CRC = __crc32b(CRC(uint8_t有)0);
  返回0
}

这导致了以下内容:

  $ G ++ test.cxx -o TEST.EXE
test.cxx:在函数'主INT(INT,CHAR **):
test.cxx:20:33:错误:'__crc32b没有在这个范围内声明
   CRC = __crc32b(CRC(uint8_t有)0);
                                 ^
test.cxx:22:1:错误:预期';'之前'}'令牌
 }
 ^$铛++ test.cxx -o TEST.EXE
test.cxx:20:9:错误:使用未声明的标识符__crc32b的
  CRC = __crc32b(CRC(uint8_t有)0);
        ^
test.cxx:21:11:错误:预期';'之后return语句
  返回0
          ^
          ;
产生2个错误。

文件系统的grep的揭示 arm_acle.h 其实头:

  $ grep的-IR__crc32/ usr / lib目录
/usr/lib/gcc/.../include/arm_acle.h:__crc32b(uint32_t的__A,uint8_t有__B)
...

和根据ARM®C语言扩展,第9.7节的 CRC32内部函数的,缺少的符号是__ ARM_FEATURE_CRC32 >假设BE present。检查 arm_acle.h 证实了这一点。

有关完整性,我试着用 -march =本地编译,但是编译器拒绝了。

为什么 __ ARM_FEATURE_CRC32 不是由编译器定义的?

我能做些什么来让程序编译在黑板上?

可用本机功能

  $ GCC --version
海湾合作委员会(于Debian / Linaro的4.9.2-10)4.9.2
版权所有(C)2014年自由软件基金会
这是自由软件;参见复印条件的来源。有否
保证;甚至不是针对特定目的的适销。$铛--version
(基于LLVM 3.5.0)的Debian版本铿锵3.5.0-10(标签/ RELEASE_350 /决赛)
目标:aarch64未知-Linux的GNU
线程模型:POSIX


  $ G ++ -dM -E  - <的/ dev / null的| egrep的-i(手臂|霓虹灯| ACLE)
#定义__ARM_NEON 1$铛++ -dM -E - <的/ dev / null的| egrep的-i(手臂|霓虹灯| ACLE)
#定义__ARM_64BIT_STATE 1
#定义__ARM_ACLE 200
#定义__ARM_ALIGN_MAX_STACK_PWR 4
#定义__ARM_ARCH 8
#定义__ARM_ARCH_ISA_A64 1
的#define __ARM_ARCH_PROFILE'A'
#定义__ARM_FEATURE_CLZ 1
#定义__ARM_FEATURE_DIV 1
#定义__ARM_FEATURE_FMA 1
#定义__ARM_FEATURE_UNALIGNED 1
#定义__ARM_FP 0xe
#定义__ARM_FP16_FORMAT_IEEE 1
#定义__ARM_FP_FENV_ROUNDING 1
#定义__ARM_NEON 1
#定义__ARM_NEON_FP 0xe
#定义__ARM_PCS_AAPCS64 1
#定义__ARM_SIZEOF_MINIMAL_ENUM 4
#定义__ARM_SIZEOF_WCHAR_T 4


解决方案

至于为什么该功能默认不启用;这是一个可选功能,在基准ABI present你的编译器的目标,也就是你的编译器产生的,预计能够在缺乏CRC功能的设备上运行的二进制文件。

至少对于GCC,您可以启用的 -march 修改 CRC ,这样此功能:

  $ GCC -dM -E  -  -march = armv8-A + CRC<的/ dev / null的| egrep的-i(手臂|霓虹灯| ACLE | CRC)
#定义__ARM_FEATURE_CRC32 1
#定义__ARM_NEON 1

请参阅 https://gcc.gnu.org /onlinedocs/gcc-6.1.0/gcc/AArch64-Options.html (或同一页的旧版本的GCC)关于如何设置更多的文档。

我想人们可以期待 -march =本地做同样的,但该选项目前只似乎是x86体系结构来实现。

I've been working on this issue for some time now, and I hope someone can point out my mistake. I guess I can no longer see the forest through the trees.

I have a LeMaker HiKey dev board I use for testing. Its AArch64, so its has NEON and the other cpu features like AES, SHA and CRC32:

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

When I attempt to compile a program:

$ cat test.cxx
#if (defined(__ARM_NEON__) || defined(__ARM_NEON))
# define NEON_INTRINSICS_AVAILABLE 1
#else
# define NEON_INTRINSICS_AVAILABLE 0
#endif

#if BOOL_NEON_INTRINSICS_AVAILABLE
# include <arm_neon.h>
# if defined(__ARM_FEATURE_CRC32) || (__ARM_ACLE >= 200)
#  include <arm_acle.h>
# endif
#endif

#include <stdint.h>

int main(int argc, char* argv[])
{
  uint32_t crc = 0;

  crc = __crc32b(crc, (uint8_t)0);
  return 0
}

It results in the following:

$ g++ test.cxx -o test.exe
test.cxx: In function ‘int main(int, char**)’:
test.cxx:20:33: error: ‘__crc32b’ was not declared in this scope
   crc = __crc32b(crc, (uint8_t)0);
                                 ^
test.cxx:22:1: error: expected ‘;’ before ‘}’ token
 }
 ^

$ clang++ test.cxx -o test.exe
test.cxx:20:9: error: use of undeclared identifier '__crc32b'
  crc = __crc32b(crc, (uint8_t)0);
        ^
test.cxx:21:11: error: expected ';' after return statement
  return 0
          ^
          ;
2 errors generated.

A grep of the file system reveals arm_acle.h is in fact the header:

$ grep -IR '__crc32' /usr/lib
/usr/lib/gcc/.../include/arm_acle.h:__crc32b (uint32_t __a, uint8_t __b)
...

And according to ARM® C Language Extensions, Section 9.7 CRC32 Intrinsics, the missing symbols are suppose be present when __ARM_FEATURE_CRC32 is defined. Inspecting arm_acle.h confirms it.

For completeness, I tried compiling with -march=native, but the compiler rejected it.

Why is __ARM_FEATURE_CRC32 not being defined by the compiler?

What can I do to get the program to compile with the native features available on the board?


$ gcc --version
gcc (Debian/Linaro 4.9.2-10) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang --version
Debian clang version 3.5.0-10 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: aarch64-unknown-linux-gnu
Thread model: posix


$ g++ -dM -E - </dev/null | egrep -i '(arm|neon|acle)'
#define __ARM_NEON 1

$ clang++ -dM -E - </dev/null | egrep -i '(arm|neon|acle)'
#define __ARM_64BIT_STATE 1
#define __ARM_ACLE 200
#define __ARM_ALIGN_MAX_STACK_PWR 4
#define __ARM_ARCH 8
#define __ARM_ARCH_ISA_A64 1
#define __ARM_ARCH_PROFILE 'A'
#define __ARM_FEATURE_CLZ 1
#define __ARM_FEATURE_DIV 1
#define __ARM_FEATURE_FMA 1
#define __ARM_FEATURE_UNALIGNED 1
#define __ARM_FP 0xe
#define __ARM_FP16_FORMAT_IEEE 1
#define __ARM_FP_FENV_ROUNDING 1
#define __ARM_NEON 1
#define __ARM_NEON_FP 0xe
#define __ARM_PCS_AAPCS64 1
#define __ARM_SIZEOF_MINIMAL_ENUM 4
#define __ARM_SIZEOF_WCHAR_T 4

解决方案

As for why this feature isn't enabled by default; this is an optional feature not present in the baseline ABI that your compiler targets, i.e. the binaries that your compiler produces are expected to be able to run on devices lacking the CRC feature.

At least for gcc, you can enable this feature with the -march modifier crc, like this:

$ gcc -dM -E - -march=armv8-a+crc < /dev/null | egrep -i '(arm|neon|acle|crc)'
#define __ARM_FEATURE_CRC32 1
#define __ARM_NEON 1

See https://gcc.gnu.org/onlinedocs/gcc-6.1.0/gcc/AArch64-Options.html (or the same page for older gcc versions) for more docs on how to set this.

I guess one could expect -march=native to do the same, but that option currently only seems to be implemented for x86 architectures.

这篇关于为什么__ARM_FEATURE_CRC32不是由编译器定义的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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