I read about the Fast and Callee calling conventions in a C-to-assembly context (temp:front wiki) and wonder if I can use these to optimize normal C function too?
I have tried to do this but it crashes my app at some point...
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
[Z88dk-users] Fast and Callee calling conventions in C
-
- Member
- Posts: 67
- Joined: Tue Dec 22, 2015 7:39 am
sccz80 cannot generate fastcall or callee functions.I read about the Fast and Callee calling conventions in a C-to-assembly context (temp:front wiki) and wonder if I can use these to optimize normal C function too?
sdcc can generate fastcall functions only. You can try that by adding the "__z88dk_fastcall" attribute to the end of the function:
int my_abs(int a) __z88dk_fastcall
{
return (a<0) ? -a : a;
}
There are some complications with generating function pointer calls for C fastcall functions. One is that "fastcall" becomes part of the type so that, eg:
int (*f)(int a); f = my_abs; // error!
int (*g)(int a) __z88dk_fastcall; g= my_abs; // (if I have that right)
Are not the same types so that "f=g" is not legal. It can't be legal because the function invocation is different for the two different function pointers.
The other complication is that sdcc cannot generate function pointer calls to fastcall functions without using the IY register. Best code generation comes using "clib=sdcc_iy" which forbids the use of IY by sdcc so using this compile method will generate errors. You can compile with "clib=sdcc_ix" however.
All of these problems are hidden by the C library because it uses a different method to resolve callee and fastcall functions through functions pointers. If you don't need to call your fastcall function through a function pointer then you can ignore these issues.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
-
- Member
- Posts: 67
- Joined: Tue Dec 22, 2015 7:39 am
Right, I keep forgetting to mention I use sdcc (iy)...sdcc can generate fastcall functions only.
I was also using the callee type so that would explain it.
Is there any particular reason why it is not supported?
I mean after compilation it is as if an asm routine is called, isn't it?
Anyway, I will try this. Thanx.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
-
- Member
- Posts: 67
- Joined: Tue Dec 22, 2015 7:39 am
Confirmed. Works fine for sdcc (iy) using only fast calls.
For those who are interested, I used these macros.
Where FastCall is for C calls and API is for asm calls... (good names are hard!)
You can use them like so (.h) the '__fast' postfix is just a naming convention - can be anything.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
For those who are interested, I used these macros.
Code: Select all
#ifdef __SDCC
#define FastCall(fn) fn __z88dk_fastcall
#define FastAPI(fn) fn __z88dk_fastcall
#define API(fn) fn __z88dk_callee
#endif
#ifdef __SCCZ80
#define FastCall(fn) fn
#define FastAPI(fn) __FASTCALL__ fn
#define API(fn) __CALLEE__ fn
#endif
You can use them like so (.h) the '__fast' postfix is just a naming convention - can be anything.
Code: Select all
uint8_t FastCall(my_function__fast(void* first_param));
#define my_function(p) my_function__fast(p)
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
This is something that has to be an integral part of the compiler's code generator. For sdcc, these calling conventions were only added a year ago to help us get the z88dk libraries working well with sdcc. Bolting something on that the compiler itself doesn't have to know about is much easier than re-writing the code generator.Is there any particular reason why it is not supported?
I mean after compilation it is as if an asm routine is called, isn't it?
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot