# SIMD Intrinsics and STL algorithms

## Recommended Posts

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[i] = _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

##### Share on other sites
Quote:
 Original post by BakuraThe problem is that I have a link error :unresolved external symbol __mm_setzero_psThe 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.

##### Share on other sites
Hum... That's possible... Is there an easy way to overcome this problem ? I'm gonna try to find those files !

##### Share on other sites
extern __m128 _mm_setr_ps(float _A, float _B, float _C, float _D);
extern __m128 _mm_setzero_ps(void);

##### Share on other sites
Quote:
 Original post by BakuraHum... 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);

##### Share on other sites
Thanks. I'll try that solution !

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978730

• 21
• 14
• 12
• 22
• 35