SIMD Intrinsics and STL algorithms

Started by
4 comments, last by Bakura 15 years, 5 months ago
Hi everyone, in order to have a more compact code and because I have a lot of small functions, I would like to use STL algorithms (and also because I love how they look on the screen ^^), and replace that :
[source code="cpp"]for (std::size_t i = 0 ; i != 4 ; ++i)
   data = _mm_setzero_ps();
by the more compact :
[source code="cpp"]std::generate (data, data + 4, _mm_setzero_ps);
The problem is that I have a link error : unresolved external symbol __mm_setzero_ps The strange thing about that is that if I replace the _mm_setzero_ps by this generator function :
[source code="cpp"]__m128 Func ()
{
   return _mm_setzero_ps();
}

... In my function :

std::generate (data, data + 4, Func);
It works ! So, is there an error in MSVC intrinsics definition ? Thanks for your answer
Advertisement
Quote:Original post by Bakura
The problem is that I have a link error :
unresolved external symbol __mm_setzero_ps
The strange thing about that is that if I replace the _mm_setzero_ps by this generator function :
It works ! So, is there an error in MSVC intrinsics definition ?
I don't have a copy of MSVC in front of me, but I would guess that those intrinsics are macros, not functions.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Hum... That's possible... Is there an easy way to overcome this problem ? I'm gonna try to find those files !
extern __m128 _mm_setr_ps(float _A, float _B, float _C, float _D);
extern __m128 _mm_setzero_ps(void);
Quote:Original post by Bakura
Hum... That's possible... Is there an easy way to overcome this problem ? I'm gonna try to find those files !


The easiest way to overcome this problem, regardless of what's causing it, is to make a small wrapper like you did in your original post.

Or like this, for maximum performance:

struct SetZeroHelper{   __m128 operator()()   {      return _mm_setzero_ps();   }};In your function:std::generate (data, data + 4, SetZeroHelper);
Thanks. I'll try that solution !

This topic is closed to new replies.

Advertisement