The code below is an attempt at having the macro add_ssaaaa from GNU MP accepted by G++. I am casting the outputs of the asm statement to unsigned int& (in GMP, USItype is unsigned int + attrib SI, which are the same on i386).
First, I'd like to be told if this is not a reasonable thing to do. I think it is, but I'm not too sure. The problem is that g++ 3.4.x produces wrong code at -O2 level for this. The asm produced has no trace of the two tests at the end (it must, really). No warning is issued. The problem vanishes if I cast to unsigned long& instead, or if I remove the cast. 4.0 does not have the problem. See also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=2803 --------------------------------------------------------------------------- const unsigned long f_p = 4194301; extern unsigned long mpinv_mod_r; unsigned long redc(unsigned long zhi, unsigned long zlo) { unsigned long t, u, m, __w1, __xm0, __xm1; m = zlo * mpinv_mod_r; __xm0 = m; __xm1 = f_p; __asm__("mull %3": "=a"(u), "=d"(__w1):"%0"(__xm0), "rm"(__xm1)); t = __w1 - (-(__xm0 >> 31) & __xm1) - (-(__xm1 >> 31) & __xm0); __asm__("addl %5,%1\n\tadcl %3,%0" : "=r" ((unsigned int&) t), "=&r" ((unsigned int&) u) :"0"(t), "g"(zhi), "%1"(u), "g"(zlo)); if ((int) t < 0) t += f_p; if (t >= f_p) t -= f_p; return t; } --------------------------------------------------------------------------- E. -- Summary: asm and cast-to-reference -> bad code Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: thome at lix dot polytechnique dot fr CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i386-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21699