This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH: pseudo conditional traps for ix86


Greg McGary <greg@mcgary.org> writes:

> Linus Torvalds <torvalds@transmeta.com> writes:
> 
> > Why not use "into"?
> > 
> > The x86 _does_ have a conditional trap instruction, it's just not very
> > commonly used and thus easily overlooked.
> > 
> > Sure, it has strange behaviour - it looks at the overflow flag and
> > nothing else - but it's still saner than doing an "int $5" and having
> > jumps around it etc.  And quite often you probably _can_ use the
> > overflow flag directly. 
> > 
> > You could make it do an "into" when it can use the overflow flag, and
> > use a conditional "int $4" when it cannot.
> 
> That's an excellent idea.  We can easily mutate an arbitrary condition
> into overflow like so:
> 
> 	setCC REG		; REG = 1 if CC holds, 0 otherwise
> 	addl $0x7fffffff, REG	; OF now set if CC holds
> 	into			; boom

It may just be slower on modern x86, because into will very likely drop into
slow microcode. A predicted forward jump may actually be faster.

[it is a less icache use vs potential slowness of microcode tradeoff]

Forward jumps are usually predicted as not taken, so to make it predicted you
may need to use a different ELF section to move it out of line (at the cost
of more bloat, because you need a 6 byte back jump and a relocation in the object
file) 

It is not clear which one will win. 

-Andi

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]