在Solaris 11上使用Sun提供的GCC的_blsr_u64的标头

Header for _blsr_u64 with Sun supplied GCC on Solaris 11?

本文关键字:GCC blsr u64 Solaris Sun      更新时间:2023-10-16

我们有一些在多个平台上运行的代码。该代码在可用时使用BMI/BMI2内部函数,如Core i7第5代。Sun在Solaris 11.3上提供的GCC定义了__BMI____BMI2__,但在查找BMI/BMI1内部函数时遇到问题:

$ 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并没有什么区别。

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


以下是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.

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

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

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

$ /bin/g++ -march=native -m64 test.cxx -o test.exe