How to profile SIMD

Started by
12 comments, last by satanir 10 years, 6 months ago


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

Maybe I willsmile.png

Advertisement

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  
a = _mm_add_ps(c, b);
 addps       xmm1,xmm0  

/////////////////////////////////////////////////////
//__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  
v.m_M128 = _mm_add_ps(d.m_M128, v2.m_M128);
 addps       xmm1,xmm0  

?/////////////////////////////////////////////////////
//_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  
vec3_add2(d, v2, v);
 addps       xmm1,xmm0 

////////////////////////////////////////////
//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
v = vec3_add(d.m_M128, v2.m_M128);
addps xmm1,xmm0

SGE_FORCE_INLINE void vec3_add2(const SGVector& a, const SGVector& b, SGVector& c)
{
#if defined(SGE_MATH_USE_SSE)
c.m_M128 = _mm_add_ps(a.m_M128, b.m_M128);
#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.

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.


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.

This topic is closed to new replies.

Advertisement