public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* gcc's x86 "RET"-machine instruction optimization
@ 2005-08-01 13:56 Josef Angermeier
  2005-08-01 17:19 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Josef Angermeier @ 2005-08-01 13:56 UTC (permalink / raw)
  To: gcc-help


Hello

Im trying to write a script which patches gcc's assembler output (-S
option) in that way, that those functions which are exported (.gobl
asm-directive) return with a near-jump instead of a
near-return-instruction. (Im writing a BIOS for a virtual machine...)

So i fist that it would be an easy task to replace all
"retl"-instructions by "lretw" ones in gcc's asm code. But then now im
facing a problem:

C code like that:
kbd.c:

bios_16_xxxx(struct regs *regs)
{
	if (AH == 0x00) {
		bios_16_00xx(regs);
	} else {
		....
	}
}

kbd.s

bios_16_xxxx:
.LCFI71:
	...
	jmp	bios_16_00xx
.L105:
	...
	lretw		(PATCHED RETURN)


....


bios_16_00xx:
.LFB59:
	...
	ret


GCC uses a jmp-instruction instead of a call one, so 'speeds up' execution by
saving the execution of bios_16_xxxx's return instruction (lretw one). This of course
ruins my efforts. Therfore i'd like to know how this optimization is called, and if
there is any gcc option to disable this particular optimization.

Big thanks in advance
josef

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gcc's x86 "RET"-machine instruction optimization
  2005-08-01 13:56 gcc's x86 "RET"-machine instruction optimization Josef Angermeier
@ 2005-08-01 17:19 ` Ian Lance Taylor
  2005-08-01 19:01   ` Josef Angermeier
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2005-08-01 17:19 UTC (permalink / raw)
  To: Josef Angermeier; +Cc: gcc-help

Josef Angermeier <sijoange@cip.informatik.uni-erlangen.de> writes:

> GCC uses a jmp-instruction instead of a call one, so 'speeds up' execution by
> saving the execution of bios_16_xxxx's return instruction (lretw one). This of course
> ruins my efforts. Therfore i'd like to know how this optimization is called, and if
> there is any gcc option to disable this particular optimization.

These are called sibling calls, and you can turn the optimization off
using -fno-optimize-sibling-calls.

(I wouldn't be surprised if you run into other problems with your
approach, but that switch should take care of that particular
problem.)

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: gcc's x86 "RET"-machine instruction optimization
  2005-08-01 17:19 ` Ian Lance Taylor
@ 2005-08-01 19:01   ` Josef Angermeier
  0 siblings, 0 replies; 3+ messages in thread
From: Josef Angermeier @ 2005-08-01 19:01 UTC (permalink / raw)
  To: gcc-help


Hello

> > GCC uses a jmp-instruction instead of a call one, so 'speeds up' execution by
> > saving the execution of bios_16_xxxx's return instruction (lretw one). This of course
> > ruins my efforts. Therfore i'd like to know how this optimization is called, and if
> > there is any gcc option to disable this particular optimization.

> These are called sibling calls, and you can turn the optimization off
> using -fno-optimize-sibling-calls.

oh great!

> (I wouldn't be surprised if you run into other problems with your
> approach, but that switch should take care of that particular
> problem.)

Mmm, i'd appreciate all hints to what problems could happen when going
this approach. Doesn't matter how vague. 

> Ian
Thanks Ian, again !

josef
ciao

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-08-01 19:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-01 13:56 gcc's x86 "RET"-machine instruction optimization Josef Angermeier
2005-08-01 17:19 ` Ian Lance Taylor
2005-08-01 19:01   ` Josef Angermeier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).