Re: i386 flags register clober in inline assembly

Linus Torvalds (torvalds@transmeta.com)
Tue, 20 Nov 2001 17:12:16 +0000 (UTC)


In article <20011120003338.A24717@twiddle.net>,
Richard Henderson <rth@twiddle.net> wrote:
>
>Hmm. It appears to be easy to do with machine-dependent builtins. E.g.
>
> int x;
> __asm__ __volatile__(LOCK "subl %1,%0"
> : "=m"(v->counter) : "ir"(i) : "memory");
> x = __builtin_ia32_sete();
> if (x) {

This would obviously be more than useful.

However, at the same time I worry that the syntax of having things
as separate expressions would be a total nightmare to support in the
long run for gcc - making sure that they never split up by mistake
during parsing/tree-forming/CSE/whatever. That makes for a nasty special
case that just sounds like a maintainance headache.

It _sounds_ like you prototyped something like the above to test it
out? If so, how hard would it be to just change the syntax slightly, and
move the "builting_ia32_sete()" syntactically into the __asm__, even if
it as an implementation then gets split out again for now.

That would make it less of a special case - or at least it would be an
_internal_ special case rather than one exported to the user.

The simplest syntactic extension would obviously be to add a fourth set
of flags, and make the above look somehting like

char flag;
__asm__ __volatile__(LOCK "subl %1,%0"
:"=m" (v->counter) /* Inputs */
:"ir" (i) /* Outputs */
:"memory" /* Clobbers */
:"=Z" (x) /* Flags (Z/E=equal, A=above, C=carry etc etc*/
);
if (x) {
...

which looks like a reasonable syntax to me. It has the advantage that it
should be _very_ easy and natural to use this syntax on predicate-based
machines like ia64, where the "flags" are trivially predicates. On such
machines I bet that the need to export the predicates is even bigger
than the need to export eflags on x86.

In fact, for predicate architectures it might be reasonable to have both
input and output predicates, which is why I did the "=Z" syntax (so that
if you find it useful to do _input_ predicates, you might have fields 4
and 5 look something like

:"=p" (is_zero)
:"p" (a == 7))

and have support for using something like "%p0" and "%!p1" etc for
specifying predicates in the assembly string. I don't know if you
already do something like this on ia64, or if gcc/ia64 even considers
the predicate bits to be independent registers.

I don't know how much inline-asm has been written for ia64, but I
suspect that it could come in handy to let gcc select predicates too,
and not have to hardcode and clobber them (or whatever it is ia64 asms
do).

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/