2

I have code like this:

uint8_t carry;

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

And the following error:

undefined reference to `_addcarry_u64'

I compile with flags:

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

I also include:

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

The same kind of problem I have while trying to use bittest function from intrinsics.

I use x86_64 ubuntu 14.04 and gcc compiler.

Artyom
  • 284
  • 2
  • 14

1 Answers1

4

_addcarry_u64 was added in GCC 5.1. You also need the intrinsics include:

 #include <x86intrin.h>

Then your example will compile, like you can see on the Godbolt compiler explorer.


For the related _addcarryx_u64 intrinsic to actually compile to ADCX/ADOX, you also need -madx to enable code-gen using the ADX instruction-set extension. -march=native will include this on hosts that support it (see /proc/cpuinfo), as well as enabling -mtune=native.

You also need a newer version of gcc (which doesn't exist yet). gcc curently (2016) just compiles it to correct code using the normal adc.

Community
  • 1
  • 1
isedev
  • 18,848
  • 3
  • 60
  • 59
  • @jww: fixed your edit: _addcarryx_u64 and _addcarry_u64 aren't the same thing. (Although my guess is that they will both compile to ADCX/ADOX with `-madx` in some future gcc and clang version. If you tell the compiler the target supports it, why would it *not* use it if it can make more efficient code?) – Peter Cordes Sep 05 '16 at 08:03