fastcalls and multiple parameters

Other misc things
Post Reply
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

fastcalls and multiple parameters

Post by Timmy »

Note: this isn't a feature request. In fact, while I do like it I don't think it's feasible.

I'm just wondering how it would work.

For example (untested code)

Code: Select all

uchar __FASTCALL__ read_hl (uchar *hl)
{
	#asm
	ld a, (hl)
	#endasm
}

uchar __FASTCALL__ inc_a (uchar a)
{
	#asm
	ld h,a
	inc h
	ld a,h
	#endasm
}

uchar __FASTCALL__ read_hl (uchar h, uchar l)
{
	#asm
	ld a, (hl)
	#endasm
}

void main()
{
	uchar x;
	x = read_hl(read(23672), inc_a(read(23672)));
}
What do you think what the results of this should be?
To be honest I just don't see this working, especially if I'm going to use recursion on the second parameter.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: fastcalls and multiple parameters

Post by dom »

See: https://github.com/z88dk/z88dk/issues/1827

However, there is, to be honest, precisely 0 interest in rewriting all of our library routines to take advantage of the marginal gains that might be achieved.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: fastcalls and multiple parameters

Post by Timmy »

Well, I don't really have a github account and I certainly am not going to post any z80 related code there, since the Copilot debacle. Therefore I'm just writing it here instead.

But I'm not really worried about breaktheworld, I'm more worried about: https://github.com/z88dk/z88dk/issues/28

Obviously you have 0 interest to rewrite all of the library routines, but I can say I won't be doing it to my own routines either.

My reason for me is that it is impossible for me to write any fastcall routines with more than one parameters, because neither the compiler nor me can guarantee those parameters won't overwrite each other. The obvious solution is to use callee instead, but that's what I've mostly been doing for functions with multiple parameters already.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: fastcalls and multiple parameters

Post by dom »

Timmy wrote: Fri Sep 10, 2021 5:45 amMy reason for me is that it is impossible for me to write any fastcall routines with more than one parameters, because neither the compiler nor me can guarantee those parameters won't overwrite each other.
I don’t understand this bit. There’s no way that arguments should override each other. For sccz80 it’s always the rightmost argument that is passed in registers. The remainder are on the stack.

Unfortunately when sdcc implemented the idea they enforced only a single argument which breaks interop and is why the rightmost argument qualifier has been interpreted as “only parameter”

If I were to implement #28 it would be through a different decorator so that everything doesn’t break by default. However it’s highly unlikely that I will implement it since it would break interop.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: fastcalls and multiple parameters

Post by Timmy »

dom wrote: Fri Sep 10, 2021 6:23 am There’s no way that arguments should override each other. For sccz80 it’s always the rightmost argument that is passed in registers. The remainder are on the stack.
Ah, good to know. I never realised you already did this. :)
If I were to implement #28 it would be through a different decorator so that everything doesn’t break by default. However it’s highly unlikely that I will implement it since it would break interop.
Thank you very much for not implementing it. (As I said, I don't like it either.)
Post Reply