vbcc optimizing C compiler for 6502 now supports bbc

handy tools that can assist in the development of new software
Post Reply
vbc
Posts: 4
Joined: Fri Oct 02, 2020 12:57 am
Contact:

vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

Hello,

I have uploaded a new version of my C compiler for 6502 with experimental support for BBC Micro/Master computers to: http://www.compilers.de/vbcc.html

A few of the good things:

- compiler is under active development
- supports C99 (variable-length arrays, designated initializers etc.)
- generates optimized code (see dhrystones in sample directory)
- supports banked memory and far-pointers
- (limited) floating point support based on Steve Wozniaks code
- (pretty good) 32/64bit IEEE floating point support based on SANE
- support for 65C02 extensions
- support for writing interrupt handlers
- attributes for putting variables into zero page
- supports stack-frames > 256 bytes

On the bad side, the C library is currently only partially optimized for the 6502 and may be too big for some applications. Not all functionality is supported at the moment. Especially file I/O is missing (stdin/stdout to keyboard/screen is supported).

I have never used a BBC Micro and the port is based on a bit of information I got from the internet. So, there are probably some things I did completely wrong. Feel free to tell me how to do it right.

So far I could only test with an emulator and do not know what works on real hardware. The samples directory contains a few examples (dhrystone benchmark and calculator) compiled for the BBC Micro. I would be interested to hear if they work on real hardware.
User avatar
Bobbi
Posts: 606
Joined: Thu Sep 24, 2020 12:32 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Bobbi »

Amazing work! Writing a C compiler is no small task.

How does your compiler compare to cc65? Not so much in terms of BBC Micro support, more the core compiler. How does code size and performance compare for example? I use cc65 a fair bit, but I could be 'in the market for' something better ;)
vbc
Posts: 4
Joined: Fri Oct 02, 2020 12:57 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

Bobbi wrote:
Fri Oct 02, 2020 9:18 pm
Amazing work! Writing a C compiler is no small task.

How does your compiler compare to cc65? Not so much in terms of BBC Micro support, more the core compiler. How does code size and performance compare for example? I use cc65 a fair bit, but I could be 'in the market for' something better ;)
Regarding features, my initial post lists probably the most important ones.

Speed of the generated code can be several times faster than cc65, depending on opportunities for optimizations. The dhrystones benchmark which is included in the samples directory of my distribution gets ~234 dhrystones/s on a C64 compared to ~75 compiled with cc65 -Oisr. Other people have reported similar improvements, e.g. in those threads:

http://forums.nesdev.com/viewtopic.php? ... 26#p251672
http://forums.nesdev.com/viewtopic.php? ... 20#p254354
http://forums.nesdev.com/viewtopic.php? ... 20#p254433
https://www.lemon64.com/forum/viewtopic ... 3&start=17

Code size is more of a mixed bag. The library of vbcc is only partially optimized for 6502 yet, so programs using large library functions will have some overhead compared to cc65. The actual generated code can be smaller or larger. vbcc comes with a (still somewhat experimental) code compressor that can save quite some space. On the other hand, when optimizing for speed, the code can get bigger. The links above also have some code size comparisons, but I have not yet done a more thorough comparison yet.
cmorley
Posts: 1431
Joined: Sat Jul 30, 2016 8:11 pm
Location: Oxford
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by cmorley »

Do you have the instructions to integrate it into a local copy of compiler explorer properly?

I managed to get it to run in CE but only by using bin/vbcc6502 not the driver bin/vc. With bin/vc I got a "no config file" error :| .
dominicbeesley
Posts: 1454
Joined: Tue Apr 30, 2013 12:16 pm
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by dominicbeesley »

Good work. I'm looking forward to trying this! The optimizations look promising
User avatar
Bobbi
Posts: 606
Joined: Thu Sep 24, 2020 12:32 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by Bobbi »

Yes I am looking forward to trying this out as well.

I have been secretly hoping for a better 6502 C compiler (secretly, because I was too lazy, and not smart enough, to do the hard work myself.)
vbc
Posts: 4
Joined: Fri Oct 02, 2020 12:57 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

cmorley wrote:
Fri Oct 02, 2020 10:55 pm
Do you have the instructions to integrate it into a local copy of compiler explorer properly?

I managed to get it to run in CE but only by using bin/vbcc6502 not the driver bin/vc. With bin/vc I got a "no config file" error :| .
I am not familiar with compiler explorer, but vc expects its config file in $VBCC/config. Maybe you did not set this environment variable?
vbc
Posts: 4
Joined: Fri Oct 02, 2020 12:57 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by vbc »

I have uploaded a new version: http://www.compilers.de/vbcc.html

Major changes since last update:

- new target: MEGA65 (native mode, some banking support)
- new target: Commander X16 (thanks András Péteri)
- new options -prefer-statics/-force-statics (allocate local variables in static memory rather than on the stack)
- new option -range-opt (first implementation of some range-based optimizations changing induction variables to smaller types)
- added support for o65 object file format
- added support for Oric target format
- better use of x register
- improved cross-module function-inlining
- IEEE math library works with 65c02
- several code generation improvements
- fixed several bugs
- slightly reworked examples
User avatar
tricky
Posts: 5186
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: vbcc optimizing C compiler for 6502 now supports bbc

Post by tricky »

https://godbolt.org/z/JN4AOA compiler explorer, supports many other compilers (x86 etc), but I think that this is cc65, it's a bit hard to tell on the phone!
Same genius who wrote jsbeeb :)
Post Reply

Return to “development tools”