stack around variable x, sse2 intrinsic codes

stack around variable x, sse2 intrinsic codes

though the codes compiles well, the programe gives the message "run time check failure, stack around variable x", where i am doing it wrong? the output y[j] is equally wrong. data type is short 2-D array.

//.h file

#define
_SSEEXAMPLE1_H

#include

__declspec(align(16))class
sseexample1

{

public:

void charles(__m128i *x, __m128i
*y);

};

#endif

//.cpp file

#include "stdafx.h"

#include

#include

#include "sseexample1.h"

void
sseexample1::charles(__m128i* x,__m128i* y)

{

int j;

__m128i p,q,s;

for (j =
0;j<4;j++)

{

p
=_mm_loadu_si128(&x[j]);//load row one of x

q
=_mm_loadu_si128(&x[j+1]);// load row 2 of x

s = _mm_add_epi16(p,q);// add row one and two

_mm_storeu_si128(&y[j],s);

}

}

//main.cpp file

#include "stdafx.h"

#include

#include

#include "sseexample1.h"

#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

short x[4][4]={1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4};

short y[4][4];

//int s[4];

sseexample1 z;

z.charles((__m128i*)x,(__m128i*)y);

for (int j = 0; j < 4; j++)

cout << y[j] << " ";

cout << endl;

return 0;

}

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

in c, 2D array is kept in memory as 1D array of pointers to 1D arrays

so when reading your x value, you are actually reading a vector of pointers. try to pass to the function &x[0][0] as argument

Leave a Comment

Please sign in to add a comment. Not a member? Join today