Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualimoogiBG

Posted 24 October 2013 - 04:21 PM

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.


#2imoogiBG

Posted 24 October 2013 - 04:13 PM

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?


#1imoogiBG

Posted 24 October 2013 - 04:11 PM

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

PARTNERS