# MSVC and SSE

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

## Recommended Posts

When going through the old stuff I had on my HD I found a couple of short articles on SSE and SSE2, and decided to toy around a bit with it. Seeing as vectors should gain quite a lot from SIMD instructions, I decided to optimize an old vector class of mine. Here's where I run into problems. For some reason, class member variables aren't allowed as operands for SSE instructions, so the following piece of code won't compile:
class CVector
{
public:
inline CVector &operator+=(CVector &rhs)
{
__asm
{
movups xmm0, m_v
...
}
return *this;
}
private:
float m_v[4];
};

If, however, we declare m_v as a float vector at the start of CVector::operator+= or as a global, then all is fine. Oh well, let's do some ugly hacking and use the this-pointer as a temporary solution, since it should be the same as m_v.
class CVector
{
public:
inline CVector &operator+=(CVector &rhs)
{
__asm
{
movups xmm0, this
movups xmm1, rhs
movups this, xmm0
}
return *this;
}
private:
float m_v[4];
};

This one compiles just fine, but reads the addresses of the pointers instead of the addresser stored in the pointers. Strangely, adding brackets around the pointers does nothing. This is quite weird, since the articles I've been looking at are doing the exact same thing with the pointers. Could it be a problem with the compiler, or is it my sub-par assembly skills that are showing? I'm using MSVC++ 7.1. Any suggestions about how to fix this, or perhaps some info about why it's perfectly acceptable to use class members as operands to normal instructions but not SSE/SSE2?

##### Share on other sites
btw are there sse intrinsics in vc 7.1? I've always used the intel compiler with vc71 so i don't really know. if so, I'd recommend using them.

as for your problem you have to align your data to a 16 b boundary and put everything inside __m128 types like

union sse4
{
float v[4];
__m128 m;
};

__declspec(align(16)) sse4 m_v;

then simply do something like

and you're done.

##### Share on other sites
Thanks, I'll try that. I think those intrinsics exist in VC7.1 too, now that you mention them.