# How to profile SIMD

This topic is 2180 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If you'd ever care to go into depth about optimization work, consider writing an article for the site wink.png

Maybe I will

##### Share on other sites

Guys i was looking at the ASM and this i what i've got

//pure _128
__m128 a, b , c;
c = _mm_set_ps1(f);
movss       xmm1,dword ptr [esp+0Ch]
b = _mm_set_ps1(ff);
movss       xmm0,dword ptr [esp+10h]
shufps      xmm0,xmm0,0
shufps      xmm1,xmm1,0

/////////////////////////////////////////////////////
//__m128 as a member of a struct
SGVector v, v2, d;
d.m_M128 = _mm_set_ps1(f);
movss       xmm1,dword ptr [esp+0Ch]
v2.m_M128 = _mm_set_ps1(ff);
movss       xmm0,dword ptr [esp+10h]
shufps      xmm0,xmm0,0
shufps      xmm1,xmm1,0

?/////////////////////////////////////////////////////
//_m128 as a member of a struct. Calling a custom function
SGVector v, v2, d;
d.m_M128 = _mm_set_ps1(f);
movss       xmm1,dword ptr [esp+0Ch]
v2.m_M128 = _mm_set_ps1(ff);
movss       xmm0,dword ptr [esp+10h]
shufps      xmm0,xmm0,0
shufps      xmm1,xmm1,0

////////////////////////////////////////////
//retval is SGVector

SGVector v, v2, d;
d.m_M128 = _mm_set_ps1(f);
movss       xmm1,dword ptr [esp+0Ch]
v2.m_M128 = _mm_set_ps1(ff);
movss       xmm0,dword ptr [esp+10h]
shufps      xmm0,xmm0,0
shufps      xmm1,xmm1,0
SGE_FORCE_INLINE void vec3_add2(const SGVector& a, const SGVector& b, SGVector& c)
{
#if defined(SGE_MATH_USE_SSE)
#endif
}
Refs, retvals do not change anything. For add ofc. Tomorrow i will try the cross product.

CL x86 O2

PS:
shufps      xmm0,xmm0,0

shufps      xmm1,xmm1,0

Why shufps is needed?

PS 2:

SuperVGA, on 24 Oct 2013 - 2:11 PM, said:

Pass vectors by value, not reference

Hi Rob,

Why do you recommend passing vectors by value rather than reference?

I've made it a habit to use const ref parameters wherever possible, and wherever ref makes sense
compared to the size of the type (I wouldn't pass a char by reference)

if the function is inlined then the refs do not change anything.

Edited by imoogiBG

##### Share on other sites

Pass vectors by value, not reference

Hi Rob,

Why do you recommend passing vectors by value rather than reference?
I've made it a habit to use const ref parameters wherever possible, and wherever ref makes sense
compared to the size of the type (I wouldn't pass a char by reference)

As of C++11, the new rule of thumb is to pass vectors and other objects like it by value when the operation performed on them requires a copy, otherwise pass by const ref. The rule for passing by reference is still the same. The reason is that this can enable move semantics when the arguments passed are rvalues. With virtual functions, the rule becomes when the operation logically needs a copy (even though every overload may not).

EDIT: that's std::vector. SIMD vectors that your architecture natively supports are basically primitive types since they can fit into a single register by definition. Edited by King Mir

##### Share on other sites

shufps xmm0,xmm0,0

shufps xmm1,xmm1,0

Why shufps is needed?

That's what _mm_set_ps1() - broadcast a single float value into all of the __m128 components. Has to be movss and shufps.

Refs, retvals do not change anything

This because of the inlining. You usually don't need to use reference for __m128. I use references for __m128 only when passing more than 3 vectors to a function - no calling convention support that, and due to stack alignemnt you can't pass a vector on stack.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 30
• 9
• 16
• 12