Jump to content
  • Advertisement
Sign in to follow this  
Valderman

MSVC and SSE

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

If you intended to correct an error in the post then please contact us.

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
            addps xmm0, xmm1
            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 this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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
m_v.m = __mm_add_ps(m_v.m, right.m_v.m);



and you're done.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!