class with SSE members crashed

Hello,

i have a strange Problem which maybe MS specific.
Im am using VC++ 2005 Express Edition

I have defined a class like this:

1
2
3
4
5
6
7
8
9
10
11
12
class vec4
{
  union
  {
	struct
	{
		float w,z,y,x;
	};
	__m128 reg;	
	float coord[4];
  };
}


I am using intrinsic Methods like _mm_add_ps to define some operations.
In Project i have the settings:

C/C++ > Code Generation:
Enable enhanced construction set: Streaming SIMD Extensions (/arch:SSE)
Struct Member Alignment : 16 Bytes (/Zp16)
C/C++ > Optimization:
Enable intrinsic functions: yes (/Oi)

I think all the other Options are not interessting in this case.
Now I have another class -- lets say Foo

1
2
3
4
5
6
7
class Foo
{
  public:
    Foo( const vec4 & v = vec4(1,2,3) ) { myfoo = v; }
  private
  vec4 myfoo;
}


which is called in the Main Programm like this

Foo * afoo = new Foo();

at this call the programm crashed before the Constructor of Foo is entered.
Question - why?

Because i enabled the alignment settings in the project, i see now reason for this. May be the "new" is the Problem, because Foo is not aligned? But this is a guess :-)

Like to discuss about this Problem.


If that's all the code you have for your vec4 class's construction, and presuming __ml128 is not an object type, then saying vec4(1,2,3) is undefined (and ambiguous).

You must either provide explicit constructors:
1
2
3
4
5
6
7
8
9
10
11
12
class vec4
  {
  ...
  public:
    vec4( float x=0.0, float y=0.0, float z=0.0, float w=1.0 ):
      w(w), z(z), y(y), x(x)
      { }
    vec4( float coord[ 4 ] ):
      w(coord[0]), z(coord[1]), y(coord[2]), x(coord[3])
      { }
    ...
  };

or a function that constructs them:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class vec4
  {
  public:  // don't forget this
  ...
  };
vec4 make_vec4( float x=0.0, float y=0.0, float z=0.0, float w=1.0 )
  {
  vec4 result;
  result.x = x;
  result.y = y;
  result.z = z;
  result.w = w;
  return result;
  };

etc.

Hope this helps.
Last edited on
Hey,

no. I posted only the data members of that class. As i said - there are a lot of operations.
And my default constructor looks more like this

1
2
3
4
5
6
7
8
vec4::vec4(void)
{
   reg = _mm_setzero_ps();
}
vec4::vec3(float x, float y = 0.0f, float z = 0.0f, float w=0.0f)
{
   reg = _mm_set_ps(x,y,z,w);
}


_m128 is a 128 bit register you can use with a lot of Operations. Thouse operations are comupted in one clock step. As I said in the topic - i have a problem with SSE intrinsic code.

My structures are compiling very well and if i implement all operations without SSE everything works fine. There is no implementation mistake in my point of view, but there maybe a misconfiguration in the Project settings or additional limitations how sse structures can be uses.

By the way - if my vec4 _example_ was the only code the class declaration would be redundant. I tried to reduce my problem to a very small example.

Greetings and Thanks for your try!
Topic archived. No new replies allowed.