I am getting Segmentation fault when running the compilation of following short C code:
#include <pmmintrin.h>
#include <stdio.h>
#include <stdlib.h>
#define VALUE 4242
typedef short int Type;
void threshold(Type *dst, const Type *src, int len)
{
short int i, N=16;
short int checkval[] = { VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE };
const short int* __attribute__ ((aligned (16))) line1;
__m128i v1, v2, v3:
v2 = _mm_loadu_si128((__m128i*) checkval );
for(i = 0; i < len; i+=N)
{
line1 = src + N*i;
//Thisline
v1 = _mm_loadu_si128((__m128i*) line1 );
v3 = _mm_cmpgt_epi16( v1, v2 );
_mm_storeu_si128((__m128i*) (dst + N*i), v3 );
}
return;
}
int main()
{
int N = 1024;
Type dst[N], src[N];
int i;
for(i = 0; i < N; i++)
src[i] = rand()%VALUE;
threshold(dst, src, N);
return 0;
}
I am quite assured the line after the "This line" is giving me problems, but I can't tell if the problem is caused by line1 not fitting inside __m128i or some other error.
As a subquestion - I tried to align the elements in line1, would function _mm_load_si128 be more appropriate (I tried both, but I cannot avoid the fault).