5

I'm trying to apply the log2 onto a __m128 variable. Like this:

#include <immintrin.h>
int main (void) {
    __m128 two_v = {2.0, 2.0, 2.0, 2.0};
    __m128 log2_v = _mm_log2_ps(two_v); // log_2 := log(2)

    return 0;
}

Trying to compile this returns this error:

error: initializing '__m128' with an expression of
      incompatible type 'int'
                __m128 log2_v = _mm_log2_ps(two_v); // log_2 := log(2)
                       ^        ~~~~~~~~~~~~~~~~~~

How can I fix it?

tmuecksch
  • 6,222
  • 6
  • 40
  • 61
  • 4
    It is an SVML intrinsic. Quacks like the declaration in the .h file is wrong, show us what it looks like. – Hans Passant Nov 21 '13 at 14:59
  • @HansPassant Sorry, i don't understand. Do you want to see my immintrin.h file? – tmuecksch Nov 21 '13 at 15:02
  • I did not specify any header file. You can already see all my code. – tmuecksch Nov 21 '13 at 15:08
  • 1
    @tmuecksch For example by using the given SSE-instrinsics, like `_mm_set_ps` and the like. But it seems your compiler understands that syntax anyway (even if this is not platform-independent), since the error seems indeed to be in the log2-line. What *Hans* meant was that you should look up the declaration of the `_mm_log2_ps` intrinsic inside its header file, to check if it really takes and returns `__m128` instead of being declared somehow incorrectly. – Christian Rau Nov 21 '13 at 15:22
  • What compiler/library is it anyway? – Christian Rau Nov 21 '13 at 15:28
  • I'm using the gcc version which is delivered with the Apple Command Line Tools. "gcc -v" returns: Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) – tmuecksch Nov 21 '13 at 15:31
  • I checked my \w+mmintrin on ubuntu 13.04 with gcc 4.8. That intrinsic just doesn't exist. The path I checked was /usr/lib/gcc/x86_64-linux-gnu/4.8/include, but its probably slightly different for you. perhaps find /usr/ -iname 'xmmintrin.h' will work for you – RichardBruce Dec 27 '13 at 08:29

1 Answers1

2

The immintrin.h you look into and immintrin.h used for compilation are different. Likely, you're looking into Intel-specific header (somewhere like /opt/intel/include/immintrin.h), while your compiler uses default immintrin.h

As it was correctly said, extern __m128 _mm_log2_ps(__m128 v1) is SVML routine, so the very first solution I see is to use Intel Compiler. For non-commercial development its free for Linux.

Although you can specify the include path to your custom immintrin.h file as a very first argument during compilation using different compiler, but I think you'll get just way too many errors - just because this header is Intel-specific.

kikobyte
  • 334
  • 1
  • 10