Advantages of z88dk compilers?

Other misc things
Post Reply
aoineko
New member
Posts: 7
Joined: Sun Dec 27, 2020 8:04 pm

Advantages of z88dk compilers?

Post by aoineko »

Hello,
I program in C and inline assembler for MSX computers using SDCC.
I don't use any standard C libraries; I have my own crt0s and features to handle I/O.
SDCC is a great tool, but I'm really not satisfied with the assembler code generated in a lot of situations:
- The lack of flexibility in passing function parameters via registers (the limit of a single parameter and the fix set of registers),
- The intesive use of IX/IY,
- The inconsistent code here and there (e.g., access a global variable is sometimes unnecessarily slow).

I've been looking for information about z88dk, but it's still not clear what are the differences between the provided 2 compilers (SCCZ80 and ZSDCC) and the SDCC one's. I saw the Benchmarks page, but the differences seem to come more from the libraries than from the compilers.

Do you have any information about those compilers and their features?
Do any of them offer more flexibility on the passing of function parameters via registers?
It has a very huge impact on performance (and on the ability to interface assembler libraries or access Bios routines).

I will look at the source of the compilers, but I am not used to this kind of program and I am afraid to get lost in it. ^^
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Advantages of z88dk compilers?

Post by stefano »

answering to your question is very difficult.
A lot of pople was disappointed by the code generation quality of the earlier z88dk versions (sccz80 only), so a lot of effort was put on it, which finally brought us to ..many possible paths you can choose, probably very confusing.
You now have 2 different compiler engines, 2 main library flavors (classic and new) and a lot of optimizer options.
The usual mistake (also the original one), is to undervalue the importance of the library.
Another aspect not taken in consideration is the compile time, if you get your executable in few seconds, you can sometimes proceed by trial and error, sccz80 is more comfortable in tha case.
SDCC on z88dk, in turn, squeezes out the best performances and size optimization, if used with the right options, but a big value of 'max-allocs-per-node' costs a long compile time.
SDCC can be invoked in 2 ways, by choosing the specific configuration (usually associated to "newlib") or by forcing zcc to choose it in place of SCCZ80 (-compiler=sdcc).
This latter option is useful to initially experiment a bit with z88dk, and speed-up your first project steps e.g. by switching to sdcc from time to time to get hints regarding unused variables, etc..
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Advantages of z88dk compilers?

Post by Timmy »

(Disclaimer: I am not part of the z88dk team but just a random person.)

C is a stack based language, the language is designed on the very core concept that parameters are passed through a stack. Also, local variables are created on the stack. Therefore, it has a lot of stack operations. On the z80, this means that it's a bit slow. If the parameters are not passed though the stack, that would make the language not a C language.

The fastcall directive is a hack. Because now it's not using a stack, and therefore it's not really C. Therefore, it's only useful for calling (inline) assembly code, where having a stack is not required. It's still a very useful hack, that is. :)

I wonder if using more parameters than hl for a fastcall defined function would make a game much faster. It would look faster on the outside, but now the compiler will have to do complicated register acrobatics (because there are only that many registers) while generating the code for the call. This isn't going to be trivial, and now the complexity (and the slowdowns) are hidden somewhere else instead.

callee() is already a good alternative, and uses stack. Or even faster, store the parameters in memory somewhere and call the desired function without any parameters, or just send the pointer to the parameters memory in hl. (That being said, I agree that function calls with many parameters is a heavy operation in any z80 based C code. I remember adding a function call (just the call) with 5 parameters will take about 40-100 bytes of extra code, but I doubt removing the stack passing would make it smaller or faster.)

As for the question whether it's useful to overload the z88dk_fastcall() function in sdcc that is used by z88dk. I don't know. But maybe someone from the z88dk team can answer that for you.

There is also a big misconception that the C generated code is anywhere near speed or quality as hand written optimised assembly. It's not (unfortunately). My quick and dirty assembly would be faster than any C code generated by the current compilers. But then again writing in C isn't really about speed, quality, or size. Then again, there are still good reasons to use C; it's still faster than BASIC, for one. And games written in C + (inline) assembly can still be fast. But for even more speed and better size, hand written (optimised) assembly is still king (or queen).



Some of your other points:

* The reason why ix/iy handling is different between the 2 compilers is probably (note: from here on it's all hunch and guesses) because z88dk is a sinclair based compiler. The Spectrum computer uses iy internally, so (my guess) the compiler tries to not use iy for their code. sdcc is a generic compiler, so (my guess here) is that there is no preference for ix or iy. Now you might wonder why the index registers are used even if they are considered slow by some people. The use case here (also guess) is that index registers have random access to memory while the alternative involves lots of pushing and popping. So in this case it's really faster.

* Oh, and did I already mentioned that the sdcc compiler in z88dk is currently not available for the MSX? At least, I don't think it is (yet).
aoineko
New member
Posts: 7
Joined: Sun Dec 27, 2020 8:04 pm

Re: Advantages of z88dk compilers?

Post by aoineko »

Thank you for all this information.
However, I don't completely agree with the fatality on the slowness of the C language :)
Ok, C will never reach the assembler performances, but in my point of view, this language is made to allow writing code that can be very efficient. But above all, the speed of a program is often a question of algorithmic and having a high level language helps a lot to write efficient algorithms (at least for the common people like me ^^).
And just because C will never be as fast as assembler, doesn't mean that it doesn't make sense to try to make C programs more efficient.
As for whether C is defined by its language or by the way compilers generate assembler code, personally, I think the important thing is the language. I consider all compiler hacks to be legit as long as they apply to standard source code that is supposed to ensure compatibility between systems and compilers.
So, if I had to find a flaw in z88dk_fastcall, I would say that the only problem is to go through a non-standard directive. Ideally, the compiler itself should decide when it is more optimal to go through the stack or the registers. I imagine it's a very complex task and I really appreciate that the z88dk team has developed this alternative!
The Z80 C compilers are designed for machines with very limited performance, and I think that this should push us to be pragmatic.
Passing parameters through registers is a huge performance gain for a lot of functions. Not all of them, of course, but that's the whole point of having a manual directive.
I have a game engine for MSX written in C (and a bit of inline assembler) that seems pretty standard, with hundreds of functions to manage joystick, keyboard, graphics card, interactions with the Bios, etc.
In my case, even keeping the 4-bytes limit of z88dk_fastcall (H, L, D and E) and allowing to use it with more than one parameter, I estimate that 75% of my functions that can't use z88dk_fastcall at the moment would benefit from a huge performance gain (I have a lot of functions that take 2~3 parameters of 1-byte).
However, I suppose on the compiler side, it wouldn't change much since it is already able to generate the body of a function with an initial reservation of HL and DE.
I feel like it's a small change that could have a big impact.

Timmy wrote: Mon Jan 04, 2021 2:08 am* Oh, and did I already mentioned that the sdcc compiler in z88dk is currently not available for the MSX? At least, I don't think it is (yet).
What do you mean by "not available for MSX"? MSX use a standard Z80 and I never had any hardware specific problem with SDCC. As I mentioned, I use my own library and my own crt0. I only use the compiler/linker to generate intermediate assembler and final binary.
Last edited by aoineko on Mon Jan 04, 2021 9:48 am, edited 1 time in total.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Advantages of z88dk compilers?

Post by dom »

I found this one difficult to answer as well, I kept starting writing something and then changing my mind.

The bulk of z88dk is the libraries, it's a huge collection of (mostly) assembler code and really is a repository of information on how to write software to run on over 100+ machines. As Stefano said, there's nominally two libraries, but they've really converged so that we're left with the following differences:

- Classic supports many more targets and has different way of implementing the crt0 startup file
- <stdio.h> is a different implementation that supports file io in classic
- Classic supports multiple floating point libraries for pure sccz80 compilations
- Classic provides the cross platform libraries detailed below
- Classic tends to be tuned at link time, newlib at library build time

I think to combine both your and Timmy's points, it's using the library routines that can allow C compiled code to become performant: I'd probably not recommend using sdcc's standard library since that is all compiled C.

Another key part of z88dk is appmake, this is the tool that turns the binary produced by the linker into a file that can be loaded into an emulator or transferred to a real machine. All the complexity is hidden behind the simple -create-app flag.

z80asm is next part, despite some idiosyncrasies, I think it's still the most capable z80 family assembler out there. Some of the object file relocation functionality is something that I've not found in other assemblers whenever I've periodically tried to figure out how to replace it.

All of this is driven by the two compilers, sdcc I presume you know about so I'm not going to talk about beyond saying that are extensions are mostly optimisation rules that fix up some code generation issues and streamline the code generation (particularly for long long), but sccz80 is the compiler maintained as part of the project.

sccz80 is yet another Small C derivative, but it's been extended beyond recognition (I think cc65 has roughly lineage), because it's in-house and simple in design it's ideal for experimenting with new features such as playing around with calling conventions (there's a few of them: https://github.com/z88dk/z88dk/wiki/CallingConventions) and new types, eg _Float16 support.

There's a been a lot of work done to the code generator over the past few years, it used to delegate a lot to support routines, but now it'll inline a fair bit of code, especially when there's constants involved. The main issue I have really is that the loop constructs are not great, but I've got a plan and some code written to help with that when I get some time to focus on it.

In hindsight, one of the big mistakes of the z80 ABI used is that hl is used for passing arguments, a much better ABI would be to have used bcde, which would lend itself to being able to pass more multiple parameters - I think BDS C always used bc de and then only spilled onto the stack when there were more than 4 bytes of parameters.

An "interesting" secret about __z88dk_fastcall, is that the two compilers behave differently - for sccz80 any function can be marked as fastcall and the last parameter will always be passed in registers, for sdcc fastcall can only be applied to functions with a single parameter.

I think there's probably a couple of calling conventions worth investigating:

- Zero page style calling, it kills re-entrancy but having variables at fixed addresses means callees can use static memory access
- Register calling, eg to pass two integers in registers

The latter is what you're asking for, packing chars into 16 bit registers may require a lot of code shuffling and it is a trade-off between doing it each time at the call site vs dealing with stack access at the callee.

I'm guessing you could achieve this "cheekily" at the moment by using 4 static chars and then a (*(long *)&char1) which would pass the chars in: l = char 1, d = char4

So the ix/framepointer discussion. sccz80 by choice doesn't use a framepointer, sometimes this works advantageously, sometimes it doesn't. I've debated adding one several times - I'm probably going to add an inert one for debugging purposes. This has worked out well on machines that tend to reserve one of them for firmware purposes (though I'm sure there's a supported machine that reserves both of them), the trade off being a constant desire that ld hl,(sp+nn) was a standard z80 instruction or even added to the Z80N.

As far as I know, the +msx support target supports using both compilers, I think most targets are good with both compilers - I think that the zx81 is an exception and there's bound to be a few more.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Advantages of z88dk compilers?

Post by Timmy »

For some context about the discussion, 2 external links:

https://www.msx.org/forum/msx-talk/deve ... cc?page=17
https://sourceforge.net/p/sdcc/feature- ... 53/?page=1

(I'll continue the discussion on another day, I'm a bit busy right now. But in the meantime you could read some info. :) )
As far as I know, the +msx support target supports using both compilers, I think most targets are good with both compilers - I think that the zx81 is an exception and there's bound to be a few more.
Oh that sounds great! (Even if I haven't switched over to sdcc yet.) I personally didn't read anything about it so I just assumed the z88dk sdcc didn't support the +msx target.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Advantages of z88dk compilers?

Post by dom »

Timmy wrote: Mon Jan 04, 2021 4:24 pmOh that sounds great! (Even if I haven't switched over to sdcc yet.) I personally didn't read anything about it so I just assumed the z88dk sdcc didn't support the +msx target.
The great thing about using sdcc is that you end up with lots of time to read about other things...

For me it's pretty much unusable for anything beyond a trivial program, I know I have old hardware, and I may not be the patient person in the world, but do people seriously develop large project using just a batch file and sdcc?

OTOH, it does encourage me to make sccz80 better as a development/prototyping compiler - fast feedback/testing is really important to me.
aoineko
New member
Posts: 7
Joined: Sun Dec 27, 2020 8:04 pm

Re: Advantages of z88dk compilers?

Post by aoineko »

Timmy wrote: Mon Jan 04, 2021 4:24 pmFor some context about the discussion, 2 external links:
I've already read both threads entirely (I even posted there ^^).
aoineko
New member
Posts: 7
Joined: Sun Dec 27, 2020 8:04 pm

Re: Advantages of z88dk compilers?

Post by aoineko »

Hi again,

Sorry to insist, but I still don't understand the precise link between the z80 compiler used by SDCC and your ZSDCC compiler.
According to the descirption page on GitHub, I understand that ZSDCC is a patch of the SDCC z80 compiler and that these changes are then partially reintegrated into SDCC compiler.
Is that correct?
Is there a detailed list of the differences between the two compilers?

Since I don't use any default libraries, I'm only interested in compiler performance on basic tasks (especially function calls) and C code optimizations. Are there any known notable differences in this area between SCCZ80, ZSDCC and the SDCC z80 compiler?
Are there any benchmark in the list that highlight this point better?

Another point I have a problem with the SDCC compiler is the fact that the const data is mixed with the code in the _CODE segment while you wish that you could put it in a separate segment that could be placed anywhere. Is this a feature available in SCCZ80 or ZSDCC?

EDIT : I found that ZSDCC have this feature (using rodata segment)! Very good point :)
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Advantages of z88dk compilers?

Post by Timmy »

Same old Disclaimer again. (Not part of z88dk or sdcc. etc.)
aoineko wrote: Sun Jan 10, 2021 6:35 pm Sorry to insist, but I still don't understand the precise link between the z80 compiler used by SDCC and your ZSDCC compiler.
If you ask me, there's aren't any. They are Two different compilers for a similar language. Like MSX BASIC is not the same as ZX BASIC.
According to the descirption page on GitHub, I understand that ZSDCC is a patch of the SDCC z80 compiler and that these changes are then partially reintegrated into SDCC compiler.
I doubt anyone here can answer any SDCC related questions. But I like that you're trying. :P

You really need to direct these questions to SDCC.

I personally don't care if SDCC is reintegrating any changes, but then again I am not part of z88dk or sdcc.
Since I don't use any default libraries, I'm only interested in compiler performance on basic tasks (especially function calls) and C code optimizations. Are there any known notable differences in this area between SCCZ80, ZSDCC and the SDCC z80 compiler?
Are there any benchmark in the list that highlight this point better?
There are lots of benchmarks already on the internet. But from hearsay I understand that SDCC is "better", but I never used it.

Also, I doubt there are any relevant benchmark for your very specific use case, especially if you're not really using C but assembly.

For me it doesn't matter, both of the compilers are faster than me writing Basic. There was a time that I considered switching to (Z)SDCC, but it's so easy to port my games from the Spectrum to MSX with the z88dk compiler, that I don't bother with sdcc any more.

---

PS. What is interesting is that there are already several game engines using z88dk (not for the MSX).

PS2. MSX support is available but most people write their own libraries (I use my own library too but it's not ready for publishing yet).
32K Roms can be done out-of-the-box, 48K is possible, and megaroms are kind of possible but it's tricky.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Advantages of z88dk compilers?

Post by Timmy »

dom wrote: Mon Jan 04, 2021 5:23 pm
Timmy wrote: Mon Jan 04, 2021 4:24 pmOh that sounds great! (Even if I haven't switched over to sdcc yet.) I personally didn't read anything about it so I just assumed the z88dk sdcc didn't support the +msx target.
The great thing about using sdcc is that you end up with lots of time to read about other things...
So how do I use the zsdcc for the +msx target then? (I'll probably still using sccz80 but it's good to know.)
For me it's pretty much unusable for anything beyond a trivial program, I know I have old hardware, and I may not be the patient person in the world, but do people seriously develop large project using just a batch file and sdcc?
All of my Spectrum programs are "using just a batch file and" z88dk... :D
OTOH, it does encourage me to make sccz80 better as a development/prototyping compiler - fast feedback/testing is really important to me.
I really like the fast compile times of sccz80. Saves so much time during development. I test a lot while developing, so for me it's almost essential.

EDIT: Somehow, SDCC is very popular on the MSX platform. Perhaps it's because it's just more popular, or perhaps all those online benchmark really say that SDCC is "better". Or perhaps they just don't know that z88dk exist. I don't know.
Last edited by Timmy on Tue Jan 12, 2021 12:28 pm, edited 1 time in total.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Advantages of z88dk compilers?

Post by dom »

aoineko wrote: Sun Jan 10, 2021 6:35 pm Hi again,

Sorry to insist, but I still don't understand the precise link between the z80 compiler used by SDCC and your ZSDCC compiler.
According to the descirption page on GitHub, I understand that ZSDCC is a patch of the SDCC z80 compiler and that these changes are then partially reintegrated into SDCC compiler.
Is that correct?
Yes, a chunk of our changes for the core compiler have been integrated upstream, what's left probably won't be. What's left is in the patch (https://github.com/z88dk/z88dk/blob/mas ... 88dk.patch) is mainly regarding replacing chunks of sdcc generated code with function call stubs.

Some of these are then replaced by the optimiser with either inline code. To be honest if all you're doing is shuffling around chars and ints it's not going to make any difference, those changes really kick in when applied to the longer datatypes.
Since I don't use any default libraries, I'm only interested in compiler performance on basic tasks (especially function calls) and C code optimizations. Are there any known notable differences in this area between SCCZ80, ZSDCC and the SDCC z80 compiler?
"Userland" function calls will be identical, intrinsic operations (eg arithmetic) will probably be faster with zsdcc as a result of:

a) Our added optimisation rules
b) The tuned assembler libraries offering performance/space tradeoffs

I suspect that if you're not using any of the C stdlib then performance will be roughly equal, but as soon as you start to use string.h, ctype.h, stdio.h, stdlib.h, floats then with z88dk your code will be smaller and faster. Given that sdcc is a multi-target project, the stdlib there is mostly written in C.

It then comes down to personal preference and whether you've got your own selection of supporting tools to make development easy.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Advantages of z88dk compilers?

Post by dom »

Timmy wrote: Tue Jan 12, 2021 12:19 pmSo how do I use the zsdcc for the +msx target then? (I'll probably still using sccz80 but it's good to know.)
We keep it really simple in classic! Just add -compiler=sdcc to your options. In theory you can build a project in classic mixing and matching object files from the different compilers though there are edgecases that need function decorators to resolve (char passing convention, floats).
All of my Spectrum programs are "using just a batch file and" z88dk... :D
Let me introduce you to the z88dk multi-project, multi-target makefile! https://github.com/z88dk/z88dk/wiki/Com ... ts-classic :)
EDIT: Somehow, SDCC is very popular on the MSX platform. Perhaps it's because it's just more popular, or perhaps all those online benchmark really say that SDCC is "better". Or perhaps they just don't know that z88dk exist. I don't know.
I did think +msx was a later target, but Stef added it back in 2000 so it's not that. I'm not sure, I guess we (and your contributions are included here) have made things a bit too easy to get started and there might be a handful of bytes "wasted".
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Advantages of z88dk compilers?

Post by stefano »

As I tried to say at the very beginning of this talk, a lot of people focuses on the "resulting compiled code". Please remember that even many historical compilers had their strength somewhere else. BDS C was mostly famous for his speed while compiling, and part of the optimization was done by tuning the linker.
Thus, considering the relatively recent success consequent to the long lasting Alvin's effort on the optimizing techniques which ended up in a total rework of the libraries, it took time for the people to understand why z88dk (bigger, and more articulated) should compete with the 'pure' sdcc compile engine.
.. a lot of articles (some not positive) were written in the meanwhile but now also sccz80 became a powerful beast ;)
aoineko
New member
Posts: 7
Joined: Sun Dec 27, 2020 8:04 pm

Re: Advantages of z88dk compilers?

Post by aoineko »

Thank you for all these clarifications, it's clearer now.

I have been programming in C for MSX for almost 10 years and have only recently heard about z88dk.

In fact, it was while trying to learn more about the wonderful z88dk_fastcall option (which has been a performance game changer) that I finally discovered your tool kit.

All the tutorials and discussions I'd had so far were about SDCC. I don't know why z88dk is so little known in the MSX scene. Maybe people aren't curious and settle for the first tool that crosses their path. ^^
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Advantages of z88dk compilers?

Post by Timmy »

aoineko wrote: Wed Jan 13, 2021 10:49 pm I have been programming in C for MSX for almost 10 years and have only recently heard about z88dk.
Yes, that's very possible but I'm glad you've found it now. :)
In fact, it was while trying to learn more about the wonderful z88dk_fastcall option (which has been a performance game changer) that I finally discovered your tool kit.
Yes, I think fastcall is a game changer.

For example, here's an AY library I wrote that only uses fastcalls: viewtopic.php?f=2&t=5088

(The thread is in the Spectrum section but there's also an MSX version available in that thread, which only needed change in only one function.)

Note that there is nowadays also a wyzplayer library available for the MSX (in z88dk), so you might not even need the AY library on its own.
All the tutorials and discussions I'd had so far were about SDCC. I don't know why z88dk is so little known in the MSX scene. Maybe people aren't curious and settle for the first tool that crosses their path. ^^
It might be surprising for you to know that there are many things have already been made with z88dk.

I've already entered MSXDev with it twice already, for example (not in 2020 though, there were way too many entries).
These are slow thinking games but that's not because I can't write fast action games, and I hope to release an action game this year (not sure if it's going to be an entry tough.)

Other examples:

I think one of those games on msx.org on the frontpage right now, Fall of Prometheus, was written in z88dk, but I don't know if it still is.

And Fabrizio's multi platform thing is too.
aoineko
New member
Posts: 7
Joined: Sun Dec 27, 2020 8:04 pm

Re: Advantages of z88dk compilers?

Post by aoineko »

If z88dk had a more powerful "function parameters via registers" feature (like more than 1 parameter and/or the ability to choose the registers), I would not hesitate for a second to switch to z88dk toolchain.
But for now, it's hard to see what z88dk could give me more than SDCC and if it's really worth changing.
I will continue to look closelly to the available alternatives. For example, I have a problem placing my constant data in a separate segment with SDCC. If I don't find a solution, that would be another argument for z88dk.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Advantages of z88dk compilers?

Post by stefano »

I don't fully understand why this single reason should be convincing you to move.
In short, SDCC does not change very much when incorporated in z88dk.

What could be the benefit of choosing a register to pass the fn argument?
aoineko
New member
Posts: 7
Joined: Sun Dec 27, 2020 8:04 pm

Re: Advantages of z88dk compilers?

Post by aoineko »

8-bits computers like MSX often have a lot of assembler routines available into the OS (Bios/Basic/Disc ROMs, DOS routines in RAM, etc.), and a lot of z80 routines are also available all over the web (fast math, compression algorithm, music replayers, etc.).
Be able to create a C function prototype that tell the compiler to setup properly the registers before calling a such routine would be incredibly useful. It's what __z88dk_fastcall do with registers HL and DE. Be able to do the same thing but with other registers would make a big difference.

This is not directly a performance issue, but being able to more easily interface C and assembler is essential to take full advantage of the capabilities of 8-bit computers.

In an other hand, be able to use __z88dk_fastcall for more than 1 function parameter (even with the current 32-bits limit on registers usage) may be a real performance game changer.
I can't say it's representative of all uses, but my library is quite standard and currently only ~30% of my hundreds of functions can take advantage of __z88dk_fastcall because having only one parameter. If the feature would work with all combinations of parameters whose total is less than or equal to 32-bits (e.g. 3 x uint8), the rate of supported function would increase to ~80%.

That would be a big change. Significant enough for me to invest time to switch to a new toolchain.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Advantages of z88dk compilers?

Post by Timmy »

stefano wrote: Sun Jan 17, 2021 8:54 pm I don't fully understand why this single reason should be convincing you to move.
In short, SDCC does not change very much when incorporated in z88dk.
I think the reason is very clear. It's the same reason why I am still using sccz80 and not zsdcc.
After 10 years doing the same language there really is never a reason to change.
It's fine and I don't blame him.
What could be the benefit of choosing a register to pass the fn argument?
Less use of stack (in theory of course), and therefore smaller size and faster code. If you have many functions and routines, then calling them all will use a lot of stack space and processor time. Every one of my games use at least hundreds of functions. (That being said, for my games it has never been a great problem, but I need to be very selective with my function calls.)
In practice, the request is likely to be technically impossible, at least on a z80. (I believe I can mathematically prove this, too.)
Also, the fact that this isn't done in C on PC architectures with many registers and stacks, tells me that it doesn't make sense even within smaller architectures.
Anyway, good luck. :)
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Advantages of z88dk compilers?

Post by stefano »

I suppose you all know the "callee" method, right? It is not as much effective as fastcall but it gives the program size a bit of relief. I'm currently adapting bit_synth and microman.c will save a hundred of bytes just with it.
Post Reply