c++ - segmentation fault in programm with SIMD commands -
what wrong here? when run program, says, segmentation fault (core dumped)
. have used simd commands.
float function ( point p1, point p2, int dim ) { int k; float result=0.0; float *p3; p3 = (float*) malloc (16); k=dim%4; __m128 *v_p1 = (__m128*)p1.coord; __m128 *v_p2 = (__m128*)p2.coord; __m128 *v_p3 = (__m128*)p3; (int i=0; i<dim/4; i++){ *v_p3= _mm_sub_ps(*v_p1,*v_p2); } for(int i=0; i<dim; i++){ result+=p3[i]; } return(result); }
any of simd _ps
instructions going require 16
byte aligned data. can tell @ least p3
not aligned , seg fault
if not use aligned data. can not run code myself if assign __m128
variables value should okay since should aligned:
__m128 v_p1 = _mm_set_ps( ... ); // not sure of argument __m128 v_p2 = _mm_set_ps( ... ); // not sure of argument __m128 v_p3 = _mm_set_ps1(p3) ;