vbcc optimizing C compiler now with Oric Atmos support

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
User avatar
Dbug
Site Admin
Posts: 4444
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by Dbug »

Regarding CC65 support of multiple architectures, yes it is definitely the way to go if you want to do multi-plateform projects.

The OSDK is only targeting the Oric, that's the only intent: I don't actively make it impossible to use it for other plateforms (that's why I added some switches to YM2MYM for example, because some MSX and Spectrum people asked for that), but supporting anything else is not part of my objective.

Regarding Tap2DSK requiring Old2MFM, yes, that's an old thing on my todo list, just never had the time to do it.
User avatar
xahmol
Flight Lieutenant
Posts: 437
Joined: Sun Jun 28, 2020 7:32 pm
Location: Utrecht, The Netherlands
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by xahmol »

Oh, and to clarify DBug, was not intended in any way as criticism as I understand fully where you are coming from. Just wanted to add my perspective in staying with CC65.
User avatar
xahmol
Flight Lieutenant
Posts: 437
Joined: Sun Jun 28, 2020 7:32 pm
Location: Utrecht, The Netherlands
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by xahmol »

iss wrote: Wed Feb 08, 2023 2:38 pm Yes, KickC is good but unfortunately I can't classify it as 100% standard C compiler. It has many language extensions which can make wonders but this means you need to devote yourself exclusively to its dialect.
Very true and exactly the main reason what still makes me not considering it yet. My present code apart from the assembly part and the graphics optimalisaties is also portable to non 6502 targets using completely different cross compilers. That is what made my TI-99/4a port of Ludo possible.

On the other hand of the spectrum, things like 8BitUnity and certainly Crosslib oversimplify graphics way to much to my taste, making the games look ugly, especially on the Oric. I respect their efforts quite a lot, but prefer myself to redo graphics and music for each target separately.

I am very charmed by TRSE as well, but that one also is a complete new language in its own (or actually not new as it is basically Pascal, but for me coming from C that is a BIG hurdle). TRSE also lacks an Oric Atmos target, and a proper implementation of the C128 80 column chip.
vbc
2nd Star Corporal
Posts: 29
Joined: Mon Feb 06, 2023 11:13 pm

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by vbc »

I have just uploaded version r3p3 with the following additions for testing:
  • new config +atmosb creates a raw binary without tape header
  • new config +atmosr creates a re-entrant tape file without autostart and a BASIC header
  • support for command line parameters like in cc65 implementation
  • source for the atmos-specific files in libsrc/6502-atmos
  • minor cleanups
vbc
2nd Star Corporal
Posts: 29
Joined: Mon Feb 06, 2023 11:13 pm

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by vbc »

Dbug wrote: Wed Feb 08, 2023 9:26 am The issues that need to be checked that I can see right now are:
- Program initialization and setup, like stack definition, etc...
I have uploaded an update that contains the source for the atmos startup-code in libsrc/6502-atmos.
- Calling conventions/parameter passing, to see if we can reuse our libraries/existing code
The vbcc.pdf contains an ABI description in "6502 Backend=>ABI". vbcc comes with a standard C library, but other functions would have to be adapted as lcc apparently uses a different ABI.
- Can VBCC generate a simple function without any setup code, like for example you want to make a complete program in assembler, but call some function written in C, without having to do anything crazy complicated to make that work.
vbcc functions will usually need its stack pointer set up (you can often get around without using the software stack, but it's hard to tell beforehand) and it needs its zero page registers. Furthermore, in some cases support functions from its library are needed (e.g. floating point or multiplication). Presumably pretty similar to the situation with lcc.

Btw. when having a short look at the osdk library functions to check the ABI, I stumbled upon the multi16 function. If I understand correctly that it does a 16x16=>16 multiplication, then it can probably be removed. In twos-complement arithmetic signed and unsigned multiplication are identical (unless the result is larger than the operands).
vbc
2nd Star Corporal
Posts: 29
Joined: Mon Feb 06, 2023 11:13 pm

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by vbc »

xahmol wrote: Wed Feb 08, 2023 2:09 pm But am not aware yet what Vbcc brings on the table to convince me. But that can very well be me not knowing enough of it. Again, open to be persuaded.
I am not on a mission to convince everybody to change their compiler. What sets vbcc apart from cc65 might be:
  • much better code quality
  • support for more language features like c99, floating-point, large stacks
  • more standard assembly syntax
  • support for more different object and output formats
  • support for more 6502 derivates like 45gs02
  • support for far-pointers
But if you are happy with cc65 and you do not need any of those features that is absolutely fine.
vbc
2nd Star Corporal
Posts: 29
Joined: Mon Feb 06, 2023 11:13 pm

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by vbc »

xahmol wrote: Wed Feb 08, 2023 2:29 pm but apart from that I would actually by far prefer if the basic header would be there as it enables exiting the program cleanly and starting it again with a simple RUN.
However that does not really work with cc65, because it does not preserve the data segment. Initialized variables do not have the correct values when running the program a second time.

I have now uploaded a vbcc update that contains a re-entrant config +atmosr similar to the ones I am using for C64 etc. It does create a BASIC header and can be started multiple times with RUN (with correctly initialized variables).
User avatar
iss
Wing Commander
Posts: 1641
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by iss »

XA-VBCC sub-topic: Very good news - it works! One point goes to the vbcc :)
What I forgot was that actually CC65's o65 object format is different and the idea of the above search/replace thing was to link CC65 object files (or libraries) with XA and VBCC. Anyway...

Attached is simple example test.c + testa.s compiled with XA and VBCC to binary and then added TAP header.
ZIP file contains a bash build script and all intermediate files.
Attachments
test-xa-vbcc.zip
(2.77 KiB) Downloaded 43 times
User avatar
iss
Wing Commander
Posts: 1641
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by iss »

I've just updated the benchmarks: 2023-02-07 vs 2023-02-08.
It's very handy to open both link in two browser tabs and switching between them you can see the differences ;).
You can find also the results in csv format - it would be cool to have kind of chart but when my free time allows...

First I've used the binary Release 3 (patch 2) of vbcc for 6502 - vbcc6502_r3p2.zip then I've updated the vbcc sources from Download compiler sources (29/04/2022) - vbcc.tar.gz and the results were the same. After the last announce about Release 3 (patch 3) of vbcc for 6502 - vbcc6502_r3p3.zip - I tested it and the results are the same again.

To build the examples I'm using:

Code: Select all

$ .../bin/vbcc6502 -O=3 -speed -size -maxoptpasses=8 -quiet -o=outfile.o infile.c
So, Very good improvement for vbcc compared to version 2022-03-xx! Congrats :)
vbc
2nd Star Corporal
Posts: 29
Joined: Mon Feb 06, 2023 11:13 pm

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by vbc »

iss wrote: Wed Feb 08, 2023 5:58 pm To build the examples I'm using:

Code: Select all

$ .../bin/vbcc6502 -O=3 -speed -size -maxoptpasses=8 -quiet -o=outfile.o infile.c
Unfortunately that is not a good command line. When calling vbcc directly (instead of using the frontend vc), the -O option specifies a bit mask of optimizations (see the vbcc.pdf for details). -O=3 is not the same as using -O3 with the frontend. Please use either -O=991 (= -O1), -O=1023 (= -O2) or -O=-1 (= -O3). Only then will you get decent results. Also, consider that there is still more functionality in the frontend, e.g. calling the code compressor or doing cross-module optimizations.

-maxoptpasses=8 seems a bit low.

Furthermore, -speed and -size tell the compiler whether you want to optimize for speed or for size. So using both does not really make sense. Use -speed for fast code and -size for small code. Not specifying either will use a reasonable compromise.

Optimizing for size is still a bit neglected in vbcc, so you might try either -O=991 -size or -O=-1 -size. It is a bit hit and miss which option yields better results. Also you can try to run the code compressor (vcpr6502) when you only care about size and do not mind slower code.
User avatar
Dbug
Site Admin
Posts: 4444
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by Dbug »

iss wrote: Wed Feb 08, 2023 5:58 pm I've just updated the benchmarks: 2023-02-07 vs 2023-02-08.
It's very handy to open both link in two browser tabs and switching between them you can see the differences ;).
Maybe it would make sense to have some tooltips on each of the column headers to show the command line parameters used to build each version.
User avatar
iss
Wing Commander
Posts: 1641
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by iss »

vbc wrote: Wed Feb 08, 2023 6:16 pm ... the -O option specifies a bit mask of optimizations ...
Indeed, I have this in my build script

Code: Select all

#                                    111110000000000
#                                    432109876543210
# CFLAGS="${CFLAGS} -O=$(echo "ibase=2;000000100010011"| bc)"
I've tried to experiment with different bits set but didn't managed to achieve something remarkable. Thanks for the extra clarifications I will try the magic numbers 991,1023,-1 asap. I totally agree that using both flags 'size' and 'speed' together makes no big sense will see how to deal with them (obviously the tests should be run twice).
Dbug wrote: Wed Feb 08, 2023 6:25 pm Maybe it would make sense to have some tooltips on each of the column headers to show the command line parameters used to build each version.
Tooltips... nice idea!
User avatar
Dbug
Site Admin
Posts: 4444
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by Dbug »

Maybe also indicate somewhere on the page what C and R actually mean :)
User avatar
iss
Wing Commander
Posts: 1641
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by iss »

Dbug wrote: Wed Feb 08, 2023 6:42 pm Maybe also indicate somewhere on the page what C and R actually mean :)
C -> failed during compilation
R -> failed to run or runs longer than 5 mins.
I'll add a note.
User avatar
xahmol
Flight Lieutenant
Posts: 437
Joined: Sun Jun 28, 2020 7:32 pm
Location: Utrecht, The Netherlands
Contact:

Re: vbcc optimizing C compiler now with Oric Atmos support

Post by xahmol »

vbc wrote: Wed Feb 08, 2023 5:29 pm However that does not really work with cc65, because it does not preserve the data segment. Initialized variables do not have the correct values when running the program a second time
Recognise that, but always took that as a given 😉 therefore never use variables where that is an issue as pre-initialised. Good to know though that this can be different in your compiler.

Of the other features, for me it is a little bit hard to appreciate things that I never learned to use. Proper float support might be handy. For the rest: I learned C to code in CC65, so never learned proper C 😉 So that also causes that I do not miss what CC65 does not have.
Understand floats. The rest I have to study if that would be beneficial for what I do.
Post Reply