This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/17759] New: Failure to emit code when using inline asm and optimizing


Using the following code:

void matrix_mult(float* dst, const float* mat, const float* vec, int count) {
    asm (
            //put matrix into xmm4-7
            "movaps (%0), %%xmm4\n\t"
            "movaps 16(%0), %%xmm5\n\t"
            "movaps 32(%0), %%xmm6\n\t"
            "movaps 48(%0), %%xmm7\n\t"
            :
            : "r"(mat)
        );
    do {
        asm (
            "movaps (%0), %%xmm0\n\t"
            "addl $16, %1\n\t"
            "movaps %%xmm0, %%xmm1\n\t"
            "addl $16, %0\n\t"
            "movaps %%xmm0, %%xmm2\n\t"
            "movaps %%xmm0, %%xmm3\n\t"
            "shufps $0x00, %%xmm0, %%xmm0\n\t"
            "shufps $0x55, %%xmm1, %%xmm1\n\t"
            "shufps $0xAA, %%xmm2, %%xmm2\n\t"
            "shufps $0xFF, %%xmm3, %%xmm3\n\t"
            "mulps %%xmm4, %%xmm0\n\t"
            "mulps %%xmm5, %%xmm1\n\t"
            "mulps %%xmm6, %%xmm2\n\t"
            "mulps %%xmm7, %%xmm3\n\t"
            "addps %%xmm0, %%xmm1\n\t"
            "addps %%xmm3, %%xmm2\n\t"
            "addps %%xmm2, %%xmm1\n\t"
            "movaps %%xmm1, -16(%1)\n\t"
#if 1
            : "+q"(vec), "+q"(dst)
#else
            :: "r"(vec), "r"(dst)
#endif
        );
        count--;
    } while(count);
}

With the #if statement the way that I have it currently, the compiler omits the entire second asm block 
when compiling -O1 or higher.  If the #if statement is set the other way, the code works in the higher 
optimization levels, but with O0 it doesn't function properly, probably because the compiler is using 
registers that are being wiped by the assembly part.  I'm sure my constraints are wrong, but having the 
compiler fail to emit code entirely seems like a bug to me.

-- 
           Summary: Failure to emit code when using inline asm and
                    optimizing
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tsuraan-gcc at xyons dot net
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17759


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]