[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[f-cpu] calling conventions
this is a (bad) translation of a mail I have posted on the french mailing list.
I have just finished reading the new handbook, and overall I have found what I
think, no big news but a versiopn stable (I hope) of the ISA. There remain
some shells but it is inevitable and will be to correct with the wire of time.
On the other hand when I am at the chapter on the recomandations of
programation for the calling convention I have questions about the intentions
of the people who have choose it.
15 registers on the whole right for the passages of the parameters? 13 for the
donnee 1 for the stack of parameters and 1 for the number of parameters.
After read this section I have made a small script for scann all my source file
and see the average number of parameter used and I obtained approximately 3
parameters (a little more or a little less according to the languages) what I
want to say that there is ten unused register in each functions.
Moreover there is a stack of register for each calls, which want to say that
for calling a function we need 3 stages:
1/ put the 13 parameters in the registers r1-r13
2/ push all the registers in r14 and put their number in r15
3/ make a jmp on the function (address of return in r60)
At my opinion the 2nd stages is very ugly, need to store all the parameters in
memory will impose many accesses in memory which are penalisant, or which will
be found to cache memory and replace more useful donnee in it.
What I propose has the place : first an observation, as well the caller
function as the function to call know at the compile time the number of
That is to say N the number of parameters:
* if n inferior to 13
r1 : number of parameters
r2-r(n+1) : parameters
r(n+2)-r31 : temporari registers
* Si n est superieur a 13
r1 : number of parameters
r2-r14 : parameters
r15 : pointer over the parameters list
r16-r31 : temporari registers
This has the advantage of optimizing the number of register to use according to
the number of parameters, a function which uses 3 parameters will mobilize 4
register for the parameters and will have 27 temporary registers. In the best
cases, a function which does not have parameters, only one register is to
mobilize and 30 others are available. In the worst cases, it is has to say
more than 13 parameters, this calling convention is similar to the proposal of
the handbook with only an inversion of register.
In all the cases the register r1 is used (by the number of parameters), it is
thus available to store the value of return of the function. The number of
parameters was present, same if it is known of the two functions, in order to
be able to possibly make checks.
In the case of more than 13 parameters I don't know if it is useful to put all
the parameters in the list pointed by r15. Indeed to have all the parameters
lists some in very practical, for the function such as [printf] in C or
[format] in Pascal, but I am not sure time to gain in these function is a
superior than time wasted to put in memory parameters which are already in the
Otherwise, the registers r32 with r59 are register has to preserve and it is to
the called to save them. It is a good thing because it save only those which
it use. But how save does ? With my opinion there are 2 methods : use the SRB
or a store, for the SRB I don't know if it is possible of chain about thirty
call of function with as much [srb_save] ? For the second solution I think that
it was interresting to have a register pointing on a memory area reserved for
This some personal reflexion, I think that is not because we have 64 register
we can waste them.
Thomas Lavergne "Le vrai rÍveur est celui qui rÍve
de l'impossible." (Elsa Triolet)
email@example.com ICQ:#137121910 http://assoc.wanadoo.fr/thallium/
To unsubscribe, send an e-mail to firstname.lastname@example.org with
unsubscribe f-cpu in the body. http://f-cpu.seul.org/