Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1696 Discussions

Moving an XMM register to a less than 128 bit memory location

soth
Beginner
241 Views
Code:
class Vec3_SSE
{

	
public:

	union
	{
		 ALIGN16( float V[3] );
		struct
		{
		 float x,y,z;
		};
	};

	Vec3_SSE()
	{
		x=0.0f;
		y=0.0f;
		z=0.0f;		
	}

	Vec3_SSE(float _x,float _y,float _z)
	{
		x=_x;
		y=_y;
		z=_z;
	};

	
	inline float Normalize(void);//normalizes vector 3d
	};

/////////////////////////////////////////////////////////////////////////////////
float Vec3_SSE::Normalize(void)
{
	float d;
	

	__asm
	{
		mov	edi, this
		movaps	xmm0, [edi]
		movaps	xmm1, xmm0
		mulps	xmm1, xmm1
		haddps	xmm1, xmm1
		haddps	xmm1, xmm1
		sqrtps  xmm1, xmm1
		movss	d, xmm1
		rcpps	xmm1, xmm1
		mulps	xmm0, xmm1

		movaps	[edi], xmm0		//can this lead to memory overrun?

		
	}
	
	return d;
}


The question is :
Can Iget memory corruption by movinga 128 bit register contents to a 96 bit memory location?
At a first glance everything works fine.
0 Kudos
2 Replies
Intel_C_Intel
Employee
241 Views

Dear Soth,
What you are doing is not safe, even if it works most of the time. You should really use a structure with four float members.
Aart Bik
http://www.aartbik.com/

0 Kudos
soth
Beginner
241 Views
Thanks
0 Kudos
Reply