C in a uC... what were they thinking??

Let's talk about anything related to the 6502 microprocessor.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: C in a uC... what were they thinking??

Post by BigEd »

barrym95838 wrote:
https://github.com/dschmenk/PLASMA/

I haven't tried it yet, but it looks like the talented Mr. Schmenk is on to something nice here.

Mike B.
Also worth noting, the very recent COWGOL from David Given:
Quote:
I am very pleased, gleeful even, to announce the first proper release of Cowgol, my almost self hosted fully compiled, properly strongly typed, Ada-inspired programming language for the 6502! Which is written in Cowgol itself!

https://github.com/davidgiven/cowgol
- http://stardot.org.uk/forums/viewtopic.php?f=53&t=13871
whartung
Posts: 1004
Joined: 13 Dec 2003

Re: C in a uC... what were they thinking??

Post by whartung »

Wow -- that's really exciting.
resman
Posts: 154
Joined: 12 Dec 2015
Location: Lake Tahoe
Contact:

Re: C in a uC... what were they thinking??

Post by resman »

White Flame wrote:
PLASMA is a VM, so if the point is to get high speed, which is usually why C is chosen over other HLLs, I don't think that's the direction to take. VMs are great for code density, though.
PLASMA currently targets the VM, but it didn't always. The first version:
(http://vm02.cvs.sourceforge.net/viewvc/ ... 02/plasma/)
could generate three different outputs: byte code, threaded code, and in-line native. The in-line code was quite fast, but as noted earlier, the 6502 isn't the most efficient compiler target, so it was a great deal larger. So later versions targeted just the byte code with an eye towards an efficient interpreter and the ability to execute byte code out of auxiliary/extended memory.

As for high speed, that can be subjective. PLASMA is certainly faster than BASIC, and is roughly equivalent to Forth (I used many concepts from Forth's interpreter when designing PLASMA's VM). The cc65 C compiler implements much of its functionality through library calls to keep the code size reasonable. Each call takes 12 cycles just for JSR/RTS and I have the inner loop for the VM down to 16 cycles. Not insignificant, but the code density and ability to have byte code in auxiliary memory was a good tradeoff, IMHO.

My eventual goal is to create a JIT to target 6502/65C02 which may or may not happen in my lifetime. However, whichever HLL compiler to implement on a 6502, it seems to me that an intermediate representation that satisfies the requirements of implementing the HLL constructs while still fitting into the constraints of the 6502 is crucial. I just went through a re-write of the compiler to extract out the optimizer into an optional back-end operation. This greatly simplified the main code generator and allowed for much better optimizations to occur (with great help from SteveF: http://stardot.org.uk/forums/viewtopic. ... 88#p163288)

Although I've programmed professionally in C for 33 years, I find PLASMA to be much more productive on the 6502 than any other language (Ok, so I'm a little biased). I will still write a number of performance critical routines in 6502 assembly (easy to write assembly routines inside PLASMA) but quite honestly, 100% of the code I write doesn't have to be the fastest possible.


Dave...
Last edited by resman on Sun Oct 15, 2017 9:01 pm, edited 1 time in total.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: C in a uC... what were they thinking??

Post by BigEd »

One thing strikes me: the most efficient data type on 6502 is the byte - especially for counters. So a language which defaults to byte-size data, or at least makes it easy (and tidy) to declare data to be byte size, would be a win. Perhaps the best possible situation is where the compiler can infer that a byte-size operation is sufficient, without annotations.

(I say this without checking how PLASMA or any other language tackles the problem...)
resman
Posts: 154
Joined: 12 Dec 2015
Location: Lake Tahoe
Contact:

Re: C in a uC... what were they thinking??

Post by resman »

BigEd wrote:
One thing strikes me: the most efficient data type on 6502 is the byte - especially for counters. So a language which defaults to byte-size data, or at least makes it easy (and tidy) to declare data to be byte size, would be a win. Perhaps the best possible situation is where the compiler can infer that a byte-size operation is sufficient, without annotations.

(I say this without checking how PLASMA or any other language tackles the problem...)
PLASMA has two basic data types: byte (unsigned 8 bits) and word (signed 16 bits). That's all you could ever need!
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: C in a uC... what were they thinking??

Post by BigEd »

Sounds good!
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: C in a uC... what were they thinking??

Post by GARTHWILSON »

GARTHWILSON wrote:
I would really like for someone to improve upon cc65. As it is, it generates horribly inefficient code. Anyone with any experience at all can do much better in assembly.
I just came across this page about benchmarking the various C compilers for the 6502. CC65 produced much slower, more bloated code than the other C options, although it was more solid.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: C in a uC... what were they thinking??

Post by BigDumbDinosaur »

GARTHWILSON wrote:
GARTHWILSON wrote:
I would really like for someone to improve upon cc65. As it is, it generates horribly inefficient code. Anyone with any experience at all can do much better in assembly.
I just came across this page about benchmarking the various C compilers for the 6502. CC65 produced much slower, more bloated code than the other C options, although it was more solid.
I saw that page as well. It succeeds in pointing out the gorilla in the room, which is the 65(c)02 is not a compiler-friendly MPU. The 65C816 is much better suited to C, although still hampered by its paucity of general purpose registers.

EDIT: Fixed some phrasing that evidently was misunderstood by several readers.
Last edited by BigDumbDinosaur on Mon Aug 16, 2021 1:40 am, edited 1 time in total.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: C in a uC... what were they thinking??

Post by BigEd »

Complete nonsense, BDD. I hope you never behave like this in person.

It's a comparison of various aspects of various compilers, shows a lot of care and attention, and is worth a read: title is "Technical highlight: C compilers for 6502 benchmark: A new hope!"

Some images from within:

Image

Image

Image

Image
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: C in a uC... what were they thinking??

Post by BigDumbDinosaur »

What is complete nonsense?
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
Dr Jefyll
Posts: 3526
Joined: 11 Dec 2009
Location: Ontario, Canada
Contact:

Re: C in a uC... what were they thinking??

Post by Dr Jefyll »

BigDumbDinosaur wrote:
What is complete nonsense?
Accidentally or otherwise, BDD, in your post you imply the article has little or no value. I'm guessing that's what Ed considers nonsense.

(Just sayin'. I don't have an opinion, myself -- about the article, I mean. But the excerpts posted do seem comprehensive.)

-- Jeff
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html
User avatar
BigDumbDinosaur
Posts: 9428
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: C in a uC... what were they thinking??

Post by BigDumbDinosaur »

Dr Jefyll wrote:
BigDumbDinosaur wrote:
What is complete nonsense?
Accidentally or otherwise, BDD, in your post you imply the article has little or no value. I'm guessing that's what Ed considers nonsense.

(Just sayin'. I don't have an opinion, myself -- about the article, I mean. But the excerpts posted do seem comprehensive.)

-- Jeff
That wasn't at all what I intended. The article was interesting. I was referring to the 6502 not being a good compiler target.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: C in a uC... what were they thinking??

Post by GARTHWILSON »

I came across this on another forum, another C compiler for the '02:
https://drive.google.com/file/d/1Eai87N ... DAyx0/view
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: C in a uC... what were they thinking??

Post by BillG »

GARTHWILSON wrote:
I came across this on another forum, another C compiler for the '02:
https://drive.google.com/file/d/1Eai87N ... DAyx0/view
Thanks for that.

Though I have no interest in programming the 6502 family in C or writing a C compiler, the manual is interesting reading as to ideas for generating good code for the 6502.
Post Reply