On Wed, 25 Jul 2007, Trent Piepho wrote: > > Specifically, check test6_memasm.s. The C code looks like this: > > extern int a; /* keep asm from being elided for having no used output */ > static inline void bar(void) { asm("call bar" : "=m"(a) : : "memory"); } > /* float x can't alias asm's output int a */ > void foo(float *x) { x[20] = 1; bar(); x[20] = 2; } > > The asm code ends up like this: > foo: > call bar > movl 4(%esp), %eax # x, x > movl $0x40000000, 80(%eax) #, > ret
Hmm. I really think you should take this up with the gcc people. That looks like a gcc bug - because there really is nothing that guarantees that the asm doesn't change the array that "x" points to, and the asm clearly talks about clobbering memory. > Notice that the first write to x[20] was NOT done. It's also not done for a > volatile asm without a memory clobber. But if you combine both volatile and a > memory clobber, then it is! How to explain that? I can't explain it. I do think you've found a gcc bug. That said, the kernel mostly uses "asm volatile()" _together_ with a memory clobber for these kinds of things, so it sounds like the kernel wouldn't be impacted. But you're definitely right - the above report makes me worry. > The difference between test2_volasm.s and test2_normasm.s is hard to explain > too. It seems like some times gcc forgets that imull is commutative. It will > emit "imull %edx, %eax" in some cases, but change an asm slightly and it will > decide it must do "imull %eax, %edx ; movl %edx, %eax" for no apparent reason. Well, that's likely just a subtle register allocation issue, and understandable. Generating perfect code is impossible, you want to generate good code on average. Linus - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/