Re: constraints and precious operand wastage

Michael L. Galbraith (mikeg@weiden.de)
Mon, 1 Jun 1998 09:37:30 +0200 (MET DST)


On Sun, 31 May 1998, Colin Plumb wrote:

> Um, unfortunately that won't work. let me give a simple example:
>
> asm volatile("... trashing %ecx ..." : "=r" (*out) : "r" (in));
> asm volatile("" : : : "cx");
>
> The problem is that GCC might decide to store "out" in ecx and, between the
> two asm statements, "movl %eax,(%ecx)". Which, of course, won't work.
>

Drat. I searched long and hard for a case where gcc inserted something
in an inline before trying this, and found none. It's my understanding
that gcc optimizes blockwise (?), the thinking being that as long as the
two halves are alone in a block or alone in a statement, nothing should
end up landing between the two halves. Doesn't mean gcc won't do such
in future tho :-/

> You can have more than 12 operands to an inline asm; you just can't refer
> to them in the string. But if all of the end ones have either matching
> constraints like "0" then you can write them as %0, while if they have
> specific constraints like "c", you can just reference "%%ecx" and likewise
> not worry about it.
>

I must be doing something wrong then, as with the following constraints
the compiler gripes even though %8 is the largest %referenced operand.

: "=a" (sum), "=c" (dead1), "=S" (dead2), "=D" (dead3)
: "m" (src_err_ptr), "m" (dst_err_ptr),
"0" (sum), "i" (-EFAULT), "m"(tmp_var),
"1" (len), "2" (src), "3" (dst)
: "bx", "dx" );

[root]:# make arch/i386/lib/checksum.s
gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -DCPU=586 -S arch/i386/lib/checksum.c -o arch/i386/lib/checksum.s
arch/i386/lib/checksum.c: In function `csum_partial_copy_generic':
arch/i386/lib/checksum.c:331: more than 10 operands in `asm'
make: *** [arch/i386/lib/checksum.s] Error 1

>
> (Certainly csum_partial is going just a bit beyond what the GCC developers
> had in mind for inline asm, so it's going to be somewhat ugly.)
> --
> -Colin

:) well, Ingo is an above and beyond kinda guy. If he writes it, it's
FAST and likely very SNEAKY too.. why I don't want to try a rewrite.

>
> "If you lie to the compiler, it will get its revenge." - Henry Spencer
>

very appropriate quote that :)

BTTODB,

-Mike

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu