Making gcc code jump to a subroutine

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A few days ago, someone asked about the code 'gcc' generates when a function ends with a function call. Specifically, why does it call the function and then return, for example

	ldi r24,lo8(0)
	rcall wr_out_all
	.stabn 68,0,23,.LM3-kill_outputs
.LM3:
/* epilogue: frame size=0 */
        ret

rather than just jump to the function to save flash and cycles

	ldi r24,lo8(0)
	rjmp wr_out_all
	.stabn 68,0,23,.LM3-kill_outputs
.LM3:
/* epilogue: frame size=0 */

Out of curiousity, I wrote an 'awk' script to see how hard this would be to fix. After spending three hours to save 8 bytes out of 2000 (0.4%), I have confirmed what I had expected: that the hack wasn't worth doing. :)

Now that it is written, however, would there be any interest in my uploading the script to the AVR Freaks site? If so, where should I put it? It is not really a user project or a design note.

- John

Last Edited: Tue. Nov 30, 2004 - 08:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
why does it call the function and then return

That's rather curious, since historically GCC was capable of doing this --
I've seen it in other ports. In fact, I recall an option to turn this Off
("-fno-tail-calls" or some such).

"avr-gcc -v --help" lists "-foptimize-sibling-calls" which sounds mostly
right but didn't seem make any difference when I tried it just now.

I wonder where this feature went?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can't find this option either in the latest gcc manual.

But I wonder if -finline-functions would help?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"-finline-functions" doesn't do anything for me.

It appears "-foptimize-sibling-calls" was lost before 3.0.2. I just tried it there and it made no difference.

On the other hand, it does generate code to jump from the function tail to the called function in the PowerPC port of 3.3.

-John

- John