[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [f-cpu] calling conventions
just a quick answer.
i didn't follow this thread (i consider this to be too much
software-related and i have big HW worries) but here's just
Rob Finch wrote:
> My two cents:
> Defining a standard calling convention seems like a good idea to me. One of
> the reasons why languages use different conventions may be that no one put
> their foot down at the beginning and said you must use these conventions to
> be compatible. Heterogenous calling conventions are a big pain.
that's looking obvious.
However, we have 64 registers and it's another story...
> I think regs should be assigned in the following order
> r63: return address - most RISC machines use last reg for return address
> and you are guarenteed to always need a return address, hence this reg
> should be fixed like r0. It is probably better to put it at the end since
> the remaining pointers are not always needed
why 63 ? because other RISC do it ? that's not a good enough reason.
1) i remember a post from some days ago which speaks about the
"special case" of using pairs of registers, it asks what would
be the point of using Reg1 xor 1... if you need a return address,
then it's a good idea to put it at register #1 because it's not
going to be needed in a loop (the idea behind the xor with the
register LSB is that it is easier to decode the numbers, check
the dependencies and also helps with naming the registers
when unrolling loops).
2) the F-CPU ISA says that the return address can be saved
by the callee to any register (reg 0 if you don't want to save it).
If you are going to nest function calls (in a non-recursive way)
then you'd better use a stack in the register set (at least).
This is because when you call the inside function, the return address
will be moved (either to memory or another register) and the original
register will loose the "flags" that associate it to the memory location.
So the return will have some cycles of penalty.
One good idea (and it doesn't cost that much) is that a few registers
(let's say : 4) are reserved for the "leaf" functions. If a function
is "leaf" (doesn't call other functions) then the return address will
be stored in register #2, a function calling a leaf function will
have its own return address in register #3 and so on...
If you are going to make a "real men's compiler", however, everything
will be flattened and the calling convention will be used to call
generic library functions.
for what it is worth...
To unsubscribe, send an e-mail to firstname.lastname@example.org with
unsubscribe f-cpu in the body. http://f-cpu.seul.org/