[lkml]   [2001]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: i386 flags register clober in inline assembly
> 	unsigned long result;
> asm volatile(
> LOCK "decl %m"
> :"+m" (v->counter),
> "=cc" (result)
> : :"memory");
> if (result > 0) /* "jnb" */
> ...
> which would be wonderful, and would expand to
> (set (cc0) ..asm..)
> (set (pc)
> (if_then_else (gtu (cc0) (const_int 0))
> (label_ref (match_operand ..
> (pc))
> Which _should_ just automatically give us
> lock ; decl ..
> ja ..
> which is exactly what we want.
> I know this used to be impossible in gcc, because the x86 didn't
> actually track the flags values, and conditional jumps were really a
> _combination_ of the conditional and the jump, and splitting it up so
> that the conditional would be in an asm was thus not possible.
> But I think gcc makes cc0 explicit on x86 these days, and that the above
> kind of setup might be possible today, no?
Actually the main dificulty I see is storing cc0 to variable. CC0 is hard
register and pretty strange one - you can't move it, you can't spill. Using
the syntax above you can easilly make cc0 from asm statement to span another
cc0 set resulting in incorrect code or compiler crash.
(the code generator may insert any code in between statements as it don't
know he can't clobber cc0. In fact this is happening in from of if
construct as deffered stack deallocators are flushed).

If i386 were IA-64 this would be possible as their flags behave more regularry,
but in i386 way I don't see easy trick how to get this (or something
equivalent) working. Maybe someone do have idea how to get around, but I was
thinking about this some time ago too and failed to find feasible sollution.

> Linus
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:13    [W:0.139 / U:0.708 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site