C++ error: ‘_mm_sin_ps’ was not declared in this scope

_mm_sin_ps is part of the SVML library, shipped with intel compilers only. GCC developers focused on wrapping machine instructions and simple tasks, so there's no SVML in immintrin.h so far.

You have to use a library or write it by yourself. Sinus implementation:

  • Taylor series
  • CORDIC
  • Quadratic curve

As has already been pointed out, you're trying to use Intel's SVML library.

There are however several SIMD transcendental functions in the free open source sse_mathfun library. The original version, which uses only SSE2 is here: http://gruntthepeon.free.fr/ssemath/ but there's a more up-to-date version here which has been updated for SSE3/SSE4 here: https://github.com/RJVB/sse_mathfun

The function you want is called sin_ps:

v4sf sin_ps(v4sf x);

where v4sf is just a typedef for __m128.

The original sse_mathfun also has cos_ps, log_ps and exp_ps, and the newer (RJVB) version has some additional functions for both single and double precision.

I've successfully used both versions of this library with gcc, clang and Intel's ICC (with some minor mods for the latter).


__mm_sin_ps is an intrinsic for calling SVML library(already mentioned).

In GCC SVML is available as a part of libmvec in glibc.

Functions are named according to Vector ABI, described in the link above. Sin, cos, exp, sincos, log, pow functions are available. Here is an example for __m128:

#include <x86intrin.h>
#include <stdio.h>

typedef union
{
  __m128  x;
  float a[4];
} union128;

__m128 _ZGVbN4v_sinf_sse4(__m128);

void main()
{
  union128 s1, res;
  s1.x = _mm_set_ps (0, 0.523599, 1.0472 , 1.5708);
  res.x =_ZGVbN4v_sinf_sse4(s1.x);
  fprintf(stderr, "%f %f %f %f\n", res.a[0], res.a[1], res.a[2], res.a[3]);
}

Is there any reason, why intrinsic is better than using the SVML function directly?