SSE With Swig
Andrew Wilkinson
ajw126NO at SPAMyork.ac.uk
Wed Jul 3 13:19:29 EDT 2002
Just in case anyone else comes up against this problem, here's the solution.
You need to override the new and delete operators so they use the
_aligned_alloc and _aligned_free functions to align the _m128 variables on a
16 byte boundy.
Andrew
--
"Andrew Wilkinson" <ajw126NO at SPAMyork.ac.uk> wrote in message
news:uhs5g8hos5og51 at corp.supernews.com...
> Hi,
>
> 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
>
> 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