2

我们有一些可以在多个平台上运行的代码。该代码在可用时使用BMI/BMI2内在函数,例如 Core i7 5th gen。Sun 在 Solaris 11.3 上提供的 GCC 定义了__BMI__and __BMI2__,但它在定位 BMI/BMI2 内部函数时遇到了问题:

$ cat test.cxx
#include <x86intrin.h>
int main(int argc, char* argv[])
{
  unsigned long long t = argc;
#if defined(__BMI__) || defined(__BMI2__)
  t = _blsr_u64(t);
#endif
  return int(t);
}

$ /bin/g++ -march=native test.cxx -o test.exe
test.cxx: In function ‘int main(int, char**)’:
test.cxx:6:18: error: ‘_blsr_u64’ was not declared in this scope
   t = _blsr_u64(t);
                  ^

包括immintrin.h并没有什么不同。

_blsr_u64在 Solaris 11.3 上使用 GCC 时,我们包含哪个标头?


以下是 GCC 的相关定义:

$ /bin/g++ -march=native -dM -E - < /dev/null | sort | \
  /usr/gnu/bin/egrep -i '(sse|aes|rdrnd|rdseed|avx|bmi)'
#define __AES__ 1
#define __AVX__ 1
#define __AVX2__ 1
#define __BMI__ 1
#define __BMI2__ 1
#define __core_avx2 1
#define __core_avx2__ 1
#define __RDRND__ 1
#define __RDSEED__ 1
#define __SSE__ 1
#define __SSE2__ 1
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#define __SSSE3__ 1
#define __tune_core_avx2__ 1

和CPU特点:

$ isainfo -v
64-bit amd64 applications
        avx xsave pclmulqdq aes movbe sse4.2 sse4.1 ssse3 amd_lzcnt popcnt tscp 
        ahf cx16 sse3 sse2 sse fxsr mmx cmov amd_sysc cx8 tsc fpu prfchw adx 
        rdseed efs rtm hle bmi2 avx2 bmi1 f16c fma rdrand 

和 GCC 版本:

$ /bin/g++ --version
g++ (GCC) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
4

1 回答 1

3

在 Solaris 11.3 上使用 GCC 时,我们为 _blsr_u64 包含哪个标头?

看起来#include <x86intrin.h>是正确的。

问题是编译器调用需要,-march=native -m64即使 64 位是本机的机器并且内核是 64 位的:

$ /bin/g++ -march=native -m64 test.cxx -o test.exe
于 2016-07-20T05:33:14.240 回答