Go Down

Topic: Function() vs Speed (Read 3 times) previous topic - next topic

westfw

Quote
assumption was that debug information has to be stored into the final executable, thus making it bigger.

The .elf files becomes significantly swollen with debugging information, but it is all is separate linker sections that are easily stripped out when making the .hex files that actually load on the Arduino HW.

Runaway Pancake


call --> 4 cycles
ret ---> 4 cycles
(4 + 4) * 5 / 16 = 2.5 microseconds.



[Copious data redacted.]
My suggestion still is: don't try to outsmart the compiler. Write simple, readable code.


There's some elucidation.
I was figuring to snap things up a bit, but it looks like the returns for the effort would be negligible.
Thanks.
"Don't Try to Outsmart The Compiler" - that's long for a bumper sticker, but it has potential.
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

JimEli


Registers are only used when available which depends entirely on what else the CPU is doing at the time, at all other times the stack is used, so you should not rely on the use of registers, but you should factor the stack into your operation as this is the worst case senario.


Quote from: avr-libc FAQ

Function call conventions:

Arguments - allocated left to right, r25 to r8. All arguments are aligned to start in even-numbered registers (odd-sized arguments, including char, have one free register above them). This allows making better use of the movw instruction on the enhanced core.

If too many, those that don't fit are passed on the stack.


My experience and the FAQ states the opposite of what you state. Can you provide evidence to support your statement?

SPlatten

#38
Mar 11, 2012, 06:44 pm Last Edit: Mar 11, 2012, 06:50 pm by SPlatten Reason: 1
The evidence is in numerous books.  My experience working with assembler dates back to the early 80's with 6502 and Z80.  

You only have a limited number of registers, when you run out of registers, this doesn't mean you can't call any functions, it simply switches to the stack.  Go read some books or search online.

Like-wise, if you nest to many function calls you will run out of stack space and encounter a stack overflow.

Quote

If too many, those that don't fit are passed on the stack.


This might be useful: http://en.wikipedia.org/wiki/Calling_convention
Kind Regards,
Sy

JimEli


The evidence is in numerous books.  My experience working with assembler dates back to the early 80's with 6502 and Z80.  

You only have a limited number of registers, when you run out of registers, this doesn't mean you can't call any functions, it simply switches to the stack.  Go read some books or search online.

Like-wise, if you nest to many function calls you will run out of stack space and encounter a stack overflow.

Quote

If too many, those that don't fit are passed on the stack.



As suspected, your statements are generalized comments about compiler functionality and not specific to gcc, avr and arduino. I would suggest using the disassembler in AVRStudio to evaluate the specifics of a particular function call.

My experience also dates back to the 1980's and the 6502. A copy of Principles of Compiler Design is in my library.

Go Up