SSE With Swig

David Abrahams david.abrahams at rcn.com
Sat Jun 29 18:52:29 EDT 2002


"Andrew Wilkinson" <ajw126NO at SPAMyork.ac.uk> wrote in message
news:uhs5g8hos5og51 at corp.supernews.com...

> I'm trying to develop a Vector class that uses Intel's SSE extension. It
> works very well when called using c or c++, but when I wrap the class with
> Swig I get a privileged instruction exception error (this is under Windows
> 2000 using MSVC++ 6sp5 with the processor pack installed).
>
> I've included the code below, any suggestions would be greatly appreciated
> Andrew Wilkinson

1. Get rid of the virtual destructor
2. Get a copy of Scott Meyers' Effective C++ CD and read about operator
overloads. Then write operator+ as a free function:
    vector operator+(vector const&, vector const&);
3. None of these are the reason for your crash, though. I don't know
anything about SSE, but don't you have to tell it how many doubles it's
going to operate on?


> swig.i
> %module Vector
> %{
> #include "Vector.h"
> %}
> class Vector
> {
> public:
>  Vector();
>  virtual ~Vector();
>  Vector* operator+(const Vector *other);
>  float x;
>  float y;
>  float z;
>  float w;
> };
> __
> vector.h
> class Vector
> {
> public:
>  Vector();
>  virtual ~Vector();
>
>  Vector* operator+(const Vector *other);
>
>  __declspec(align(16)) union {
>   __m128 v;
>   struct {
>    float x;
>    float y;
>    float z;
>    float w;
>   };
>  };
> };
> ---
> vector.cpp
> #include "Vector.h"
> #include <xmmintrin.h>
>
> Vector::Vector()
> {
>  x = 0.0f; y = 0.0f; z = 0.0f; w = 0.0f;
> }
>
> Vector::~Vector()
> {
>
> }
>
> Vector* Vector::operator +(const Vector *other)
> {
>  Vector* r = new Vector;
>
>  r->v = _mm_add_ps(v, (other->v)); // The exception occurs here.
>
>  return r;
> }
>
> --
> ---
> Ditch The Decimal System!
> Lets Use Hex - http://www.intuitor.com/hex/switch.html
>
>





More information about the Python-list mailing list