I was experimenting with some sse2 to get ready for making a vector and matrix lib. I have run into a weird issue that I do not understand.
Vec4f is a class with 4 floats and is defined with __declspec(align(16))
int main()
{
Vec4f v1, v2, v3;
v1.Set(1,1,1,1);
v2.Set(2,2,2,2);
Vec4fAdd(&v3, &v1, &v2);
__asm
{
movaps xmm0, v1
movaps xmm1, v2
addps xmm0, xmm1
movaps v3, xmm0
}
return 0;
}
void Vec4fAdd(void* _o, const void* _a, const void* _b)
{
//_o.x = _a.x + _b.x;
//_o.y = _a.y + _b.y;
//_o.z = _a.z + _b.z;
//_o.w = _a.w + _b.w;
__asm
{
movaps xmm0, _a
movaps xmm1, _b
addps xmm0, xmm1
movaps _o, xmm0
}
}
The asm inlined in main() works but the Vec4fAdd() call does not. It gets an exception reading 0xffffffff. If I also inline some assembly to put the parameters into general registers it works. What I do not understand is why it doesnt work even though the values thatI am seeing in the debugger are the same memory locations that are used in the inlined part in main(). It seems that no matter whatfunction I sendthe Vec4f in it crashes even though it looks 16 byte aligned.
Message Edited by Rheikon on 09-30-2005 02:45 PM


