As if supporting two compilers wasn't confusing enough, I've spent the past week adding support for another one.
As a bit of background, the TI84+ CE calculator is based on ez80 running in ADL mode and jacobly0 over on GitHub made a mammoth effort a few years ago and ported LLVM to target it and released it as ez80-clang. The TI84+ community then built a full dev kit around it. As a "hidden" feature, it also supported z80 and z180 processors however I've not been able to find a project that makes use of it.
Until now(!) I've added some of the required compiler support routines, tuned the core part of the classic library and now clang can be used as a compiler for classic targets.
It does of course come with some caveats, the generated code makes extensive use of both index registers (and index halves) and as such is not suitable for generating code that is intended to run on targets that reserve either or both of the index registers. For example the generated code would probably cause a ZX81 to crash very quickly.
Code generation using clang is very quick and the generated code sometimes bears little relation to the input - for example loops may be aggressively optimised away. This can result in larger code than that generated by the other two compilers.
Of course at the moment it's not going to work flawlessly, in particular:
- Not all compiler support routines have been written (in particular long long, floating point and some long routines are missing)
- Limited CPU support (no 808x, Rabbit, gbz80)
- Only the "standard" library has been updated to export to clang, so there's no/limited graphics, sound etc
- Source code debugging support is not available
- I'm unsure of the syntax for inline assembler, sfrs etc
- Support routines for other languages (C++ etc) has not been implemented
However, I think it's worth a play and would welcome some feedback. I'll be merging later on today so it should be available in the next nightly.
There's some more details here: https://github.com/z88dk/z88dk/wiki/Clang-support
ez80-clang supported as compiler
Re: ez80-clang supported as compiler
AY library and graphics has been exported- Only the "standard" library has been updated to export to clang, so there's no/limited graphics, sound etc
Use the function style asm("[assembler here, use \n to separate lines"); the same as the other compilers.- I'm unsure of the syntax for inline assembler,
-
- Member
- Posts: 124
- Joined: Mon Mar 26, 2018 1:49 pm
Re: ez80-clang supported as compiler
Do you have any feeling on the speed of the generated code relative to the other two compilers?
Re: ez80-clang supported as compiler
It depends, I put a summary of what I initially found on the wiki page:
Of course, I'm running fairly trivial programs, my suspicion is that when code is non-trivial, the llvm optimisations affecting the structure may well improve things.
A few years ago, Alvin was experimenting with clang+cbe and then feeding that into sdcc but seemed to run into some fairly serious issues. Given that cbe has been resurrected recently that might be worth re-exploring.
I've narrowed this down a bit more after some more tests, and can see that performance when using 8 bit values is usually better than the other compilers, 16 bit is a little worse than sdcc and 32 bit is appalling.The code generated for operations involving 32 bit integer values is not particularly optimal in either size or speed. For example the classic md5 algorithm used as part of the autotests is both significantly larger and over twice as slow as the other compilers.
On the other hand, running the enigma example (which uses int8 and int16 types) generates code of comparable size and executes in about 50% of the time of the other compiler.
Of course, I'm running fairly trivial programs, my suspicion is that when code is non-trivial, the llvm optimisations affecting the structure may well improve things.
A few years ago, Alvin was experimenting with clang+cbe and then feeding that into sdcc but seemed to run into some fairly serious issues. Given that cbe has been resurrected recently that might be worth re-exploring.
Re: ez80-clang supported as compiler
As a bit of analysis the use of iy as a general register. This works well on the ez80, but not so well on the z80. You tend to end up with code such as this:
[ld hl,(ixy +- val) is treated as a synthetic by z80asm]
On the ez80 there's the instruction ld iy,(ix+dd) which is 5 cycles, for reference ld r,(ix+dd) is 4 on the ez80 and ex (sp),hl is 5), so lets say the z80 equivalent of 19T, on the z80 the workaround code is 82T.
We can trim that in some circumstances in copt rules which removes the ex (sp),hl.
Code: Select all
push hl
ld hl, (ix - 14)
ex (sp), hl
pop iy
On the ez80 there's the instruction ld iy,(ix+dd) which is 5 cycles, for reference ld r,(ix+dd) is 4 on the ez80 and ex (sp),hl is 5), so lets say the z80 equivalent of 19T, on the z80 the workaround code is 82T.
We can trim that in some circumstances in copt rules which removes the ex (sp),hl.