对“_addcarry_u64”的未定义引用

undefined reference to `_addcarry_u64'

我有这样的代码:

uint8_t carry;

carry = 0;
for (i = 0; i < 8; i++)
    carry = _addcarry_u64 (carry, *(buf1 + i),
            *(buf2 + i), buf1 + i);

并出现以下错误:

undefined reference to `_addcarry_u64'

我用标志编译:

CCFLAGS = -Wall -g -msse -msse2 -msse3 -msse4 -mavx -mavx2 -fopenmp

我还包括:

#include <immintrin.h>
#include <emmintrin.h>
#include <pmmintrin.h>
#include <smmintrin.h>
#include <omp.h>

我在尝试使用内在函数中的 bittest 函数时遇到了同样的问题。

我使用 x86_64 ubuntu 14.04 和 gcc 编译器。

_addcarry_u64 是在 GCC 5.1 中添加的。您还需要内在函数包括:

 #include <x86intrin.h>

然后您的示例将编译,如您所见on the Godbolt compiler explorer


对于相关的 _addcarryx_u64 intrinsic to actually compile to ADCX/ADOX,您还需要 -madx 使用 ADX 指令集扩展启用代码生成。 -march=native 将在支持它的主机上包含它(参见 /proc/cpuinfo),以及启用 -mtune=native.

您还需要更新版本的 gcc(尚不存在)。 .