-1

I have a segmentation fault problem that is driving me crazy.

this is the code :

            for (k = 0; k < range; k=k+4)
        {
            int k1,k2,kfactor,k1factor,k2factor;
            __m128 bfly0_rv, bfly1_rv, bfly2_rv, bfly3_rv;
            __m128 bfly0_iv, bfly1_iv, bfly2_iv, bfly3_iv;
            __m128 x_n2_vec, x_N2_vec, x_N2_2_vec, x_N2_3_vec;
            __m128 y_n2_vec, y_N2_vec, y_N2_2_vec, y_N2_3_vec;
            ///////////
            //factors//
            ///////////
            k1=2*k;
            k2=3*k;
            kfactor = k * factor;
            k1factor = k1 * factor;
            k2factor = k2 * factor;
            //printf("%d \t %d \t %d \n",kfactor,k1factor,k2factor);

            //////////////
            //Load input//
            //////////////
            //real parts//
            __M128_MM_LOAD_PS(x_n2_vec,&x[n2]);
            __M128_MM_LOAD_PS(x_N2_vec,&x[N2]);
            __M128_MM_LOAD_PS(x_N2_2_vec,&x[N2_2]);
            __M128_MM_LOAD_PS(x_N2_3_vec,&x[N2_3]);
            //imaginary parts//
            __M128_MM_LOAD_PS(y_n2_vec,&y[n2]);
            __M128_MM_LOAD_PS(y_N2_vec,&y[N2]);
            __M128_MM_LOAD_PS(y_N2_2_vec,&y[N2_2]);
            __M128_MM_LOAD_PS(y_N2_3_vec,&y[N2_3]);

            ///////////////
            //butterflies//
            ///////////////
            //additions//
            //Butterfly 0//
            __M128_MM_ADD_PS(bfly0_rv,x_n2_vec,x_N2_vec)
            __M128_MM_ADD_PS(bfly0_rv,bfly0_rv,x_N2_2_vec)
            __M128_MM_ADD_PS(bfly0_rv,bfly0_rv,x_N2_3_vec)

            __M128_MM_ADD_PS(bfly0_iv,y_n2_vec,y_N2_vec)
            __M128_MM_ADD_PS(bfly0_iv,bfly0_iv,y_N2_2_vec)
            __M128_MM_ADD_PS(bfly0_iv,bfly0_iv,y_N2_3_vec)
            //Butterfly 1//
            __M128_MM_ADD_PS(bfly1_rv,x_n2_vec,y_N2_vec)
            __M128_MM_SUB_PS(bfly1_rv,bfly1_rv,x_N2_2_vec)
            __M128_MM_SUB_PS(bfly1_rv,bfly1_rv,y_N2_3_vec)

            __M128_MM_SUB_PS(bfly1_iv,y_n2_vec,x_N2_vec)
            __M128_MM_SUB_PS(bfly1_iv,bfly1_iv,y_N2_2_vec)
            __M128_MM_ADD_PS(bfly1_iv,bfly1_iv,x_N2_3_vec)
            //Butterfly 2//
            __M128_MM_SUB_PS(bfly2_rv,x_n2_vec,x_N2_vec)
            __M128_MM_ADD_PS(bfly2_rv,bfly2_rv,x_N2_2_vec)
            __M128_MM_SUB_PS(bfly2_rv,bfly2_rv,x_N2_3_vec)

            __M128_MM_SUB_PS(bfly2_iv,y_n2_vec,y_N2_vec)
            __M128_MM_ADD_PS(bfly2_iv,bfly2_iv,y_N2_2_vec)
            __M128_MM_SUB_PS(bfly2_iv,bfly2_iv,y_N2_3_vec)
            //Butterfly 3//
            __M128_MM_SUB_PS(bfly3_rv,x_n2_vec,y_N2_vec)
            __M128_MM_SUB_PS(bfly3_rv,bfly3_rv,x_N2_2_vec)
            __M128_MM_ADD_PS(bfly3_rv,bfly3_rv,y_N2_3_vec)

            __M128_MM_ADD_PS(bfly3_iv,y_n2_vec,x_N2_vec)
            __M128_MM_SUB_PS(bfly3_iv,bfly3_iv,y_N2_2_vec)
            __M128_MM_SUB_PS(bfly3_iv,bfly3_iv,x_N2_3_vec)
            printf("%f \t %f \t %f \t %f \t %f \t %f \t %f \t %f \n",bfly0_rv[0],bfly0_iv[0],bfly1_rv[0],bfly1_iv[0],bfly2_rv[0],bfly2_iv[0],bfly3_rv[0],bfly3_iv[0]);
            printf("%f \t %f \t %f \t %f \t %f \t %f \t %f \t %f \n",bfly0_rv[1],bfly0_iv[1],bfly1_rv[1],bfly1_iv[1],bfly2_rv[1],bfly2_iv[1],bfly3_rv[1],bfly3_iv[1]);
            printf("%f \t %f \t %f \t %f \t %f \t %f \t %f \t %f \n",bfly0_rv[2],bfly0_iv[2],bfly1_rv[2],bfly1_iv[2],bfly2_rv[2],bfly2_iv[2],bfly3_rv[2],bfly3_iv[2]);
            printf("%f \t %f \t %f \t %f \t %f \t %f \t %f \t %f \n",bfly0_rv[3],bfly0_iv[3],bfly1_rv[3],bfly1_iv[3],bfly2_rv[3],bfly2_iv[3],bfly3_rv[3],bfly3_iv[3]);

            n2    = n2 + 4;
            N2    = N2 + 4;
            N2_2  = N2_2 + 4;
            N2_3  = N2_3 + 4;
        }

the segmentation fault comes when i use the printf for the butterflies. I'm printing the values of the butterflies because i want to be sure that all the calculations are done properly.

what have i done wrong?

NOTICE :

range is taking the following values (1024,256,64,16,4,1)

x array of floats for reals

y array of floats for imaginaries

the arrays size is 4096

I'm using Intel intrinsics so I'm loading 4 values at a time.

A.nechi
  • 521
  • 1
  • 5
  • 15
  • 1
    Try reducing this to a [mcve] that still segfaults. It doesn't have to still implement an FFT, just use a couple intrinsics and try to print them. – Peter Cordes Aug 05 '16 at 16:49

1 Answers1

1

According to MSDN (https://msdn.microsoft.com/en-us/library/ayeb3ayc.aspx):

You should not access the __m128 fields directly. You can, however, see these types in the debugger. A variable of type __m128 maps to the XMM[0-7] registers.

So possibly you run into a situation which the warning above tried to make you avoid.

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167
  • thank you for your clear answer Sir ... the problem that the execution is so long if i debug it and i need to see almost all the values. – A.nechi Aug 05 '16 at 10:50
  • 4
    Welcome to the real life of a programmer: Write code for 5 minutes, then look at the debug screen for 5 hours :) – Ferenc Deak Aug 05 '16 at 10:57